DIR : /home/kozerus/public_html/pn/uize/site-source/js/Uize/Test/Uize/Templates/Text/Table.js

/home/kozerus/public_html/pn/uize/site-source/js/Uize/Test/Uize/Templates/Text

/*______________
|       ______  |   U I Z E    J A V A S C R I P T    F R A M E W O R K
|     /      /  |   ---------------------------------------------------
|    /    O /   |    MODULE : Uize.Test.Uize.Templates.Text.Table Class
|   /    / /    |
|  /    / /  /| |    ONLINE : http://www.uize.com
| /____/ /__/_| | COPYRIGHT : (c)2014-2016 UIZE
|          /___ |   LICENSE : Available under MIT License or GNU General Public License
|_______________|             http://www.uize.com/license.html
*/

/* Module Meta Data
	type: Test
	importance: 1
	codeCompleteness: 100
	docCompleteness: 100
*/

/*?
	Introduction
		The =Uize.Test.Uize.Templates.Text.Table= module defines basic unit tests for the =Uize.Templates.Text.Table= JavaScript template module.

		*DEVELOPERS:* `Chris van Rensburg`
*/

Uize.module ({
	name:'Uize.Test.Uize.Templates.Text.Table',
	builder:function () {
		'use strict';

		return Uize.Test.resolve ({
			title:'Test for Uize.Templates.Text.Table JavaScript Template',
			test:[
				Uize.Test.requiredModulesTest ('Uize.Templates.Text.Table'),
				Uize.Test.staticMethodsTest ([
					['Uize.Templates.Text.Table.process',[
						/*** tests for title ***/
							/*** test support for no title ***/
								['A table without a title can be generated by not specifying a title property in the input object',
									{
										columns:[{title:'Foo'}],
										rows:[]
									},
									'+-----+\n' +
									'| Foo |\n' +
									'|-----|\n' +
									'+-----+\n'
								],
								['A table without a title can be generated by specifying an empty string for the title property in the input object',
									{
										title:'',
										columns:[{title:'Foo'}],
										rows:[]
									},
									'+-----+\n' +
									'| Foo |\n' +
									'|-----|\n' +
									'+-----+\n'
								],
								['A table without a title can be generated by specifying the value null for the title property in the input object',
									{
										title:null,
										columns:[{title:'Foo'}],
										rows:[]
									},
									'+-----+\n' +
									'| Foo |\n' +
									'|-----|\n' +
									'+-----+\n'
								],
								['A table without a title can be generated by specifying the value undefined for the title property in the input object',
									{
										title:undefined,
										columns:[{title:'Foo'}],
										rows:[]
									},
									'+-----+\n' +
									'| Foo |\n' +
									'|-----|\n' +
									'+-----+\n'
								],
								['If the table is wider than the title, then the title text is center-aligned',
									{
										title:'The Table Title',
										columns:[{title:'The Title of a Column'}],
										rows:[]
									},
									'+-----------------------+\n' +
									'|    The Table Title    |\n' +
									'+-----------------------+\n' +
									'| The Title of a Column |\n' +
									'|-----------------------|\n' +
									'+-----------------------+\n'
								],

							/*** test support for no title ***/
								['A table with a title can be generated by specifying the title as a string for the title property in the input object',
									{
										title:'Foo',
										columns:[{title:'Bar'}],
										rows:[]
									},
									'+-----+\n' +
									'| Foo |\n' +
									'+-----+\n' +
									'| Bar |\n' +
									'|-----|\n' +
									'+-----+\n'
								],

						/*** tests for different numbers of rows ***/
							['A table may contain no rows of data',
								{
									title:'Foo',
									columns:[{title:'Col'}],
									rows:[]
								},
								'+-----+\n' +
								'| Foo |\n' +
								'+-----+\n' +
								'| Col |\n' +
								'|-----|\n' +
								'+-----+\n'
							],
							['A table may contain a single row of data',
								{
									title:'Foo',
									columns:[{title:'Col'}],
									rows:[
										['Foo']
									]
								},
								'+-----+\n' +
								'| Foo |\n' +
								'+-----+\n' +
								'| Col |\n' +
								'|-----|\n' +
								'| Foo |\n' +
								'+-----+\n'
							],
							['A table may contain multiple rows of data',
								{
									title:'Foo',
									columns:[{title:'Col'}],
									rows:[
										['Foo'],
										['Bar'],
										['Baz'],
										['Qux']
									]
								},
								'+-----+\n' +
								'| Foo |\n' +
								'+-----+\n' +
								'| Col |\n' +
								'|-----|\n' +
								'| Foo |\n' +
								'|-----|\n' +
								'| Bar |\n' +
								'|-----|\n' +
								'| Baz |\n' +
								'|-----|\n' +
								'| Qux |\n' +
								'+-----+\n'
							],

						/*** tests for columns ***/
							/*** tests for different numbers of columns ***/
								['A table may contain just a single column',
									{
										title:'Foo',
										columns:[{title:'Col'}],
										rows:[
											['Foo'],
											['Bar'],
											['Baz'],
											['Qux']
										]
									},
									'+-----+\n' +
									'| Foo |\n' +
									'+-----+\n' +
									'| Col |\n' +
									'|-----|\n' +
									'| Foo |\n' +
									'|-----|\n' +
									'| Bar |\n' +
									'|-----|\n' +
									'| Baz |\n' +
									'|-----|\n' +
									'| Qux |\n' +
									'+-----+\n'
								],
								['A table may contain just a single column',
									{
										title:'Foo',
										columns:[{title:'Col 1'},{title:'Col 2'},{title:'Col 3'}],
										rows:[
											['Foo 1','Foo 2','Foo 3'],
											['Bar 1','Bar 2','Bar 3'],
											['Baz 1','Baz 2','Baz 3'],
											['Qux 1','Qux 2','Qux 3']
										]
									},
									'+-----------------------+\n' +
									'|          Foo          |\n' +
									'+-----------------------+\n' +
									'| Col 1 | Col 2 | Col 3 |\n' +
									'|-------+-------+-------|\n' +
									'| Foo 1 | Foo 2 | Foo 3 |\n' +
									'|-------+-------+-------|\n' +
									'| Bar 1 | Bar 2 | Bar 3 |\n' +
									'|-------+-------+-------|\n' +
									'| Baz 1 | Baz 2 | Baz 3 |\n' +
									'|-------+-------+-------|\n' +
									'| Qux 1 | Qux 2 | Qux 3 |\n' +
									'+-----------------------+\n'
								],

							/*** tests for column titles ***/
								['Column titles are center-aligned',
									{
										title:'Foo',
										columns:[{title:'Col 1'},{title:'Col 2'},{title:'Col 3'}],
										rows:[
											['Wide Column Value 1','Wide Column Value 2','Wide Column Value 3']
										]
									},
									'+-----------------------------------------------------------------+\n' +
									'|                               Foo                               |\n' +
									'+-----------------------------------------------------------------+\n' +
									'|        Col 1        |        Col 2        |        Col 3        |\n' +
									'|---------------------+---------------------+---------------------|\n' +
									'| Wide Column Value 1 | Wide Column Value 2 | Wide Column Value 3 |\n' +
									'+-----------------------------------------------------------------+\n'
								],

							/*** tests for column width calculation ***/
								['When a column title is wider than all the column values, then the column is as wide as the title',
									{
										title:'Table',
										columns:[{title:'A Wide Column Title'}],
										rows:[
											['foo'],
											['bar bar bar'],
											['baz baz'],
											['qux qux qux qux']
										]
									},
									'+---------------------+\n' +
									'|        Table        |\n' +
									'+---------------------+\n' +
									'| A Wide Column Title |\n' +
									'|---------------------|\n' +
									'| foo                 |\n' +
									'|---------------------|\n' +
									'| bar bar bar         |\n' +
									'|---------------------|\n' +
									'| baz baz             |\n' +
									'|---------------------|\n' +
									'| qux qux qux qux     |\n' +
									'+---------------------+\n'
								],
								['When a column title is narrower than all of the column values, then the column is as wide as the widest column value',
									{
										title:'Table',
										columns:[{title:'Column'}],
										rows:[
											['foo'],
											['bar bar bar'],
											['baz baz'],
											['qux qux qux qux']
										]
									},
									'+-----------------+\n' +
									'|      Table      |\n' +
									'+-----------------+\n' +
									'|     Column      |\n' +
									'|-----------------|\n' +
									'| foo             |\n' +
									'|-----------------|\n' +
									'| bar bar bar     |\n' +
									'|-----------------|\n' +
									'| baz baz         |\n' +
									'|-----------------|\n' +
									'| qux qux qux qux |\n' +
									'+-----------------+\n'
								],
								['When a table\'s title is wider than the maximum width of all the columns, then the table is expanded to fit the title and the difference is distributed evenly across the columns',
									{
										title:'This is an extremely long title for this table',
										columns:[{title:'Col 1'},{title:'Col 2'},{title:'Col 3'}],
										rows:[
											['Foo 1','Foo 2','Foo 3'],
											['Bar 1','Bar 2','Bar 3'],
											['Baz 1','Baz 2','Baz 3'],
											['Qux 1','Qux 2','Qux 3']
										]
									},
									'+------------------------------------------------+\n' +
									'| This is an extremely long title for this table |\n' +
									'+------------------------------------------------+\n' +
									'|     Col 1     |     Col 2      |     Col 3     |\n' +
									'|---------------+----------------+---------------|\n' +
									'| Foo 1         | Foo 2          | Foo 3         |\n' +
									'|---------------+----------------+---------------|\n' +
									'| Bar 1         | Bar 2          | Bar 3         |\n' +
									'|---------------+----------------+---------------|\n' +
									'| Baz 1         | Baz 2          | Baz 3         |\n' +
									'|---------------+----------------+---------------|\n' +
									'| Qux 1         | Qux 2          | Qux 3         |\n' +
									'+------------------------------------------------+\n'
								],

							/*** tests for column alignment ***/
								['Column data is left-aligned, by default, when alignment is not explicitly specified',
									{
										title:'Table',
										columns:[{title:'Column 1'},{title:'Column 2'},{title:'Column 3'}],
										rows:[
											['foo','bar bar bar','baz baz'],
											['bar bar bar','baz baz','qux qux qux qux'],
											['baz baz','qux qux qux qux','foo'],
											['qux qux qux qux','foo','bar bar bar']
										]
									},
									'+-----------------------------------------------------+\n' +
									'|                        Table                        |\n' +
									'+-----------------------------------------------------+\n' +
									'|    Column 1     |    Column 2     |    Column 3     |\n' +
									'|-----------------+-----------------+-----------------|\n' +
									'| foo             | bar bar bar     | baz baz         |\n' +
									'|-----------------+-----------------+-----------------|\n' +
									'| bar bar bar     | baz baz         | qux qux qux qux |\n' +
									'|-----------------+-----------------+-----------------|\n' +
									'| baz baz         | qux qux qux qux | foo             |\n' +
									'|-----------------+-----------------+-----------------|\n' +
									'| qux qux qux qux | foo             | bar bar bar     |\n' +
									'+-----------------------------------------------------+\n'
								],
								['Column data can be left-aligned, by specifying the value "left" for the align property of the column description',
									{
										title:'Table',
										columns:[{title:'Column',align:'left'}],
										rows:[
											['foo'],
											['bar bar bar'],
											['baz baz'],
											['qux qux qux qux']
										]
									},
									'+-----------------+\n' +
									'|      Table      |\n' +
									'+-----------------+\n' +
									'|     Column      |\n' +
									'|-----------------|\n' +
									'| foo             |\n' +
									'|-----------------|\n' +
									'| bar bar bar     |\n' +
									'|-----------------|\n' +
									'| baz baz         |\n' +
									'|-----------------|\n' +
									'| qux qux qux qux |\n' +
									'+-----------------+\n'
								],
								['Column data can be left-aligned, by specifying the value 0 for the align property of the column description',
									{
										title:'Table',
										columns:[{title:'Column',align:0}],
										rows:[
											['foo'],
											['bar bar bar'],
											['baz baz'],
											['qux qux qux qux']
										]
									},
									'+-----------------+\n' +
									'|      Table      |\n' +
									'+-----------------+\n' +
									'|     Column      |\n' +
									'|-----------------|\n' +
									'| foo             |\n' +
									'|-----------------|\n' +
									'| bar bar bar     |\n' +
									'|-----------------|\n' +
									'| baz baz         |\n' +
									'|-----------------|\n' +
									'| qux qux qux qux |\n' +
									'+-----------------+\n'
								],
								['Column data can be center-aligned, by specifying the value "center" for the align property of the column description',
									{
										title:'Table',
										columns:[{title:'Column',align:'center'}],
										rows:[
											['foo'],
											['bar bar bar'],
											['baz baz'],
											['qux qux qux qux']
										]
									},
									'+-----------------+\n' +
									'|      Table      |\n' +
									'+-----------------+\n' +
									'|     Column      |\n' +
									'|-----------------|\n' +
									'|       foo       |\n' +
									'|-----------------|\n' +
									'|   bar bar bar   |\n' +
									'|-----------------|\n' +
									'|     baz baz     |\n' +
									'|-----------------|\n' +
									'| qux qux qux qux |\n' +
									'+-----------------+\n'
								],
								['Column data can be center-aligned, by specifying the value .5 for the align property of the column description',
									{
										title:'Table',
										columns:[{title:'Column',align:.5}],
										rows:[
											['foo'],
											['bar bar bar'],
											['baz baz'],
											['qux qux qux qux']
										]
									},
									'+-----------------+\n' +
									'|      Table      |\n' +
									'+-----------------+\n' +
									'|     Column      |\n' +
									'|-----------------|\n' +
									'|       foo       |\n' +
									'|-----------------|\n' +
									'|   bar bar bar   |\n' +
									'|-----------------|\n' +
									'|     baz baz     |\n' +
									'|-----------------|\n' +
									'| qux qux qux qux |\n' +
									'+-----------------+\n'
								],
								['Column data can be right-aligned, by specifying the value "right" for the align property of the column description',
									{
										title:'Table',
										columns:[{title:'Column',align:'right'}],
										rows:[
											['foo'],
											['bar bar bar'],
											['baz baz'],
											['qux qux qux qux']
										]
									},
									'+-----------------+\n' +
									'|      Table      |\n' +
									'+-----------------+\n' +
									'|     Column      |\n' +
									'|-----------------|\n' +
									'|             foo |\n' +
									'|-----------------|\n' +
									'|     bar bar bar |\n' +
									'|-----------------|\n' +
									'|         baz baz |\n' +
									'|-----------------|\n' +
									'| qux qux qux qux |\n' +
									'+-----------------+\n'
								],
								['Column data can be right-aligned, by specifying the value 1 for the align property of the column description',
									{
										title:'Table',
										columns:[{title:'Column',align:1}],
										rows:[
											['foo'],
											['bar bar bar'],
											['baz baz'],
											['qux qux qux qux']
										]
									},
									'+-----------------+\n' +
									'|      Table      |\n' +
									'+-----------------+\n' +
									'|     Column      |\n' +
									'|-----------------|\n' +
									'|             foo |\n' +
									'|-----------------|\n' +
									'|     bar bar bar |\n' +
									'|-----------------|\n' +
									'|         baz baz |\n' +
									'|-----------------|\n' +
									'| qux qux qux qux |\n' +
									'+-----------------+\n'
								],
								['Column data can be quarter-aligned, by specifying the value .25 for the align property of the column description',
									{
										title:'Table',
										columns:[{title:'Column',align:.25}],
										rows:[
											['foo'],
											['bar bar bar'],
											['baz baz'],
											['qux qux qux qux']
										]
									},
									'+-----------------+\n' +
									'|      Table      |\n' +
									'+-----------------+\n' +
									'|     Column      |\n' +
									'|-----------------|\n' +
									'|    foo          |\n' +
									'|-----------------|\n' +
									'|  bar bar bar    |\n' +
									'|-----------------|\n' +
									'|   baz baz       |\n' +
									'|-----------------|\n' +
									'| qux qux qux qux |\n' +
									'+-----------------+\n'
								],
								['Different columns can have different alignment',
									{
										title:'Table',
										columns:[
											{title:'Column 1',align:'left'},
											{title:'Column 2',align:'center'},
											{title:'Column 3',align:'right'}
										],
										rows:[
											['foo','bar bar bar','baz baz'],
											['bar bar bar','baz baz','qux qux qux qux'],
											['baz baz','qux qux qux qux','foo'],
											['qux qux qux qux','foo','bar bar bar']
										]
									},
									'+-----------------------------------------------------+\n' +
									'|                        Table                        |\n' +
									'+-----------------------------------------------------+\n' +
									'|    Column 1     |    Column 2     |    Column 3     |\n' +
									'|-----------------+-----------------+-----------------|\n' +
									'| foo             |   bar bar bar   |         baz baz |\n' +
									'|-----------------+-----------------+-----------------|\n' +
									'| bar bar bar     |     baz baz     | qux qux qux qux |\n' +
									'|-----------------+-----------------+-----------------|\n' +
									'| baz baz         | qux qux qux qux |             foo |\n' +
									'|-----------------+-----------------+-----------------|\n' +
									'| qux qux qux qux |       foo       |     bar bar bar |\n' +
									'+-----------------------------------------------------+\n'
								],

							/*** tests for column formatters ***/
								['A column formatter can be specified for each column',
									{
										title:'Table',
										columns:[
											{title:'Description'},
											{
												title:'Price (US Dollars)',
												align:'right',
												formatter:function (_value) {return 'US $' + _value.toFixed (2)}
											},
											{
												title:'Inflation (%)',
												align:'right',
												formatter:function (_value) {return _value.toFixed (1) + ' %'}
											}
										],
										rows:[
											['bread (1 loaf)',1.4,2.1564],
											['milk (1 pint)',1.99,3.9041],
											['sugar (200g)',2.49,6.8]
										]
									},
									'+-----------------------------------------------------+\n' +
									'|                        Table                        |\n' +
									'+-----------------------------------------------------+\n' +
									'|  Description   | Price (US Dollars) | Inflation (%) |\n' +
									'|----------------+--------------------+---------------|\n' +
									'| bread (1 loaf) |           US $1.40 |         2.2 % |\n' +
									'|----------------+--------------------+---------------|\n' +
									'| milk (1 pint)  |           US $1.99 |         3.9 % |\n' +
									'|----------------+--------------------+---------------|\n' +
									'| sugar (200g)   |           US $2.49 |         6.8 % |\n' +
									'+-----------------------------------------------------+\n'
								],
								['A column formatter can be specified in the form of a value transformer expression string',
									{
										title:'Price Comparisons',
										columns:[
											{title:'Description'},
											{
												title:'Price (US Dollars)',
												align:'right',
												formatter:'"US $" + value.toFixed (2)'
											},
											{
												title:'Inflation (%)',
												align:'right',
												formatter:'value.toFixed (1) + " %"'
											}
										],
										rows:[
											['bread (1 loaf)',1.4,2.1564],
											['milk (1 pint)',1.99,3.9041],
											['sugar (200g)',2.49,6.8]
										]
									},
									'+-----------------------------------------------------+\n' +
									'|                  Price Comparisons                  |\n' +
									'+-----------------------------------------------------+\n' +
									'|  Description   | Price (US Dollars) | Inflation (%) |\n' +
									'|----------------+--------------------+---------------|\n' +
									'| bread (1 loaf) |           US $1.40 |         2.2 % |\n' +
									'|----------------+--------------------+---------------|\n' +
									'| milk (1 pint)  |           US $1.99 |         3.9 % |\n' +
									'|----------------+--------------------+---------------|\n' +
									'| sugar (200g)   |           US $2.49 |         6.8 % |\n' +
									'+-----------------------------------------------------+\n'
								],
								['A column formatter is called as an instance method on the column description object',
									{
										title:'Table',
										columns:[
											{
												title:'Price',
												align:'right',
												currency:'US $',
												formatter:function (_value) {return this.currency + _value.toFixed (2)}
											}
										],
										rows:[
											[1.4],
											[1.99],
											[2.49]
										]
									},
									'+----------+\n' +
									'|  Table   |\n' +
									'+----------+\n' +
									'|  Price   |\n' +
									'|----------|\n' +
									'| US $1.40 |\n' +
									'|----------|\n' +
									'| US $1.99 |\n' +
									'|----------|\n' +
									'| US $2.49 |\n' +
									'+----------+\n'
								],
								['Column width is calculated based on the formatted column data and not the raw, unformatted column data',
									{
										title:'Table',
										columns:[
											{
												title:'Col',
												formatter:function (_value) {return _value.toFixed (2)}
											}
										],
										rows:[
											[2.34545756785645],
											[67.3106034049435],
											[105.10303042]
										]
									},
									'+--------+\n' +
									'| Table  |\n' +
									'+--------+\n' +
									'|  Col   |\n' +
									'|--------|\n' +
									'| 2.35   |\n' +
									'|--------|\n' +
									'| 67.31  |\n' +
									'|--------|\n' +
									'| 105.10 |\n' +
									'+--------+\n'
								],

							/*** tests for column min and max values ***/
								/*** test support for explicitly specifying the min and max values ***/
									['When a value is specified for the minValue property in the column description for a column, that value is respected',
										{
											title:'Table',
											columns:[
												{
													title:'Column',
													minValue:10,
													formatter:function (_value) {return _value - this.minValue}
												}
											],
											rows:[
												[15],
												[12],
												[27]
											]
										},
										'+--------+\n' +
										'| Table  |\n' +
										'+--------+\n' +
										'| Column |\n' +
										'|--------|\n' +
										'| 5      |\n' +
										'|--------|\n' +
										'| 2      |\n' +
										'|--------|\n' +
										'| 17     |\n' +
										'+--------+\n'
									],
									['When a value is specified for the maxValue property in the column description for a column, that value is respected',
										{
											title:'Table',
											columns:[
												{
													title:'Column',
													maxValue:30,
													formatter:function (_value) {return this.maxValue - _value}
												}
											],
											rows:[
												[15],
												[12],
												[27]
											]
										},
										'+--------+\n' +
										'| Table  |\n' +
										'+--------+\n' +
										'| Column |\n' +
										'|--------|\n' +
										'| 15     |\n' +
										'|--------|\n' +
										'| 18     |\n' +
										'|--------|\n' +
										'| 3      |\n' +
										'+--------+\n'
									],

								/*** test support for computing the min and max values ***/
									['When no value is specified for the minValue property in the column description for a column, it is calculated from the column values and set on the column description',
										{
											title:'Table',
											columns:[
												{
													title:'Column',
													formatter:function (_value) {return _value - this.minValue}
												}
											],
											rows:[
												[15],
												[12],
												[27]
											]
										},
										'+--------+\n' +
										'| Table  |\n' +
										'+--------+\n' +
										'| Column |\n' +
										'|--------|\n' +
										'| 3      |\n' +
										'|--------|\n' +
										'| 0      |\n' +
										'|--------|\n' +
										'| 15     |\n' +
										'+--------+\n'
									],
									['When no value is specified for the maxValue property in the column description for a column, it is calculated from the column values and set on the column description',
										{
											title:'Table',
											columns:[
												{
													title:'Column',
													formatter:function (_value) {return this.maxValue - _value}
												}
											],
											rows:[
												[15],
												[12],
												[27]
											]
										},
										'+--------+\n' +
										'| Table  |\n' +
										'+--------+\n' +
										'| Column |\n' +
										'|--------|\n' +
										'| 12     |\n' +
										'|--------|\n' +
										'| 15     |\n' +
										'|--------|\n' +
										'| 0      |\n' +
										'+--------+\n'
									]
					]]
				])
			]
		});
	}
});

//


koh5_pano



Your browser does not support the HTML5 canvas element.


Drag mouse to navigate.

Navigation





17.Aug.2010, Martin Wengenmayer