Debian Codegraph @

tests/qunit/resources/mediawiki.widgets/Table/mediawiki.widgets.TableWidget.test.js

raw symbols SCIP
1 /*!
2 * MediaWiki Widgets TableWidget tests.
3 */
4
5 QUnit.module( 'mediawiki.widgets.TableWidget' );
6
7 ( function () {
8 const widgetA = new mw.widgets.TableWidget( {
9 rows: [
10 {
11 key: 'foo',
12 label: 'Foo'
13 },
14 {
15 key: 'bar',
16 label: 'Bar'
17 }
18 ],
19 cols: [
20 {
21 label: 'A'
22 },
23 {
24 label: 'B'
25 }
26 ]
27 } ),
28 widgetB = new mw.widgets.TableWidget( {
29 rows: [
30 {
31 key: 'foo'
32 },
33 {
34 key: 'bar'
35 }
36 ],
37 cols: [
38 {}, {}, {}
39 ],
40 data: [
41 [ '11', '12', '13' ],
42 [ '21', '22', '23' ]
43 ]
44 } ),
45 widgetAexpectedRowProps = {
46 index: 1,
47 key: 'bar',
48 label: 'Bar'
49 },
50 widgetAexpectedInitialData = [
51 [ '', '' ],
52 [ '', '' ]
53 ],
54 widgetAexpectedDataAfterValue = [
55 [ '', '' ],
56 [ '3', '' ]
57 ],
58 widgetAexpectedDataAfterRowColumnInsertions = [
59 [ '', '', '' ],
60 [ 'a', 'b', 'c' ],
61 [ '3', '', '' ]
62 ],
63 widgetAexpectedDataAfterColumnRemoval = [
64 [ '', '' ],
65 [ 'b', 'c' ],
66 [ '', '' ]
67 ];
68
69 // See https://phabricator.wikimedia.org/T151262#4253730 about skipped tests
70
71 QUnit.test( 'TableWidgetModel initialization', ( assert ) => {
72 assert.deepEqual( widgetA.model.data, widgetAexpectedInitialData, 'Table data is initialized properly' );
73 } );
74
75 QUnit.test( 'TableWidgetModel#getRowProperties', ( assert ) => {
76 assert.deepEqual( widgetA.model.getRowProperties( 'bar' ), widgetAexpectedRowProps, 'Row props are returned successfully' );
77 } );
78
79 QUnit.test( 'TableWidget#setValue', ( assert ) => {
80 widgetA.setValue( 'bar', 0, '3' );
81 assert.deepEqual( widgetA.model.data, widgetAexpectedDataAfterValue, 'Table data is modified successfully' );
82 } );
83
84 QUnit.skip( 'TableWidget#insertColumn/insertRow', ( assert ) => {
85 widgetA.insertColumn();
86 widgetA.insertRow( [ 'a', 'b', 'c' ], 1, 'baz', 'Baz' );
87 assert.deepEqual( widgetA.model.data, widgetAexpectedDataAfterRowColumnInsertions, 'Row and column are added successfully' );
88 } );
89
90 QUnit.skip( 'TableWidget#removeColumn', ( assert ) => {
91 widgetA.removeColumn( 0 );
92 assert.deepEqual( widgetA.model.data, widgetAexpectedDataAfterColumnRemoval, 'Columns are removed successfully' );
93 } );
94
95 QUnit.skip( 'TableWidget#removeRow by index', ( assert ) => {
96 widgetA.removeRow( -1 );
97 assert.deepEqual( widgetA.model.data, widgetAexpectedDataAfterColumnRemoval, 'Invalid row removal by index does not change table data' );
98 } );
99
100 QUnit.skip( 'TableWidget#removeRow by key', ( assert ) => {
101 widgetA.removeRow( 'qux' );
102 assert.deepEqual( widgetA.model.data, widgetAexpectedDataAfterColumnRemoval, 'Invalid row removal by key does not change table data' );
103 } );
104
105 QUnit.test( 'TableWidget populate text inputs', ( assert ) => {
106 assert.deepEqual( widgetB.getItems()[ 0 ].getItems()[ 2 ].getValue(), '13', 'Initial data is populated in text inputs properly' );
107 } );
108 }() );