nnnjjj123
2020-11-17 1b2c1edb61190eeb19f465ff031eaa3b2a1b8dbc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
define([
    'intern!tdd',
    'intern/chai!assert',
    'dojo/_base/declare',
    'dojo/aspect',
    'dojo/Deferred',
    'dojo/query',
    'dgrid/test/data/createSyncStore',
    'dgrid/test/data/createHierarchicalStore',
    'dgrid/OnDemandGrid',
    'dgrid/ColumnSet',
    'dgrid/Keyboard',
    'dgrid/Tree',
    '../addCss!'
], function (test, assert, declare, aspect, Deferred, query, createSyncStore, createHierarchicalStore,
        OnDemandGrid, ColumnSet, Keyboard, Tree) {
 
    var grid;
    var handles;
 
    test.suite('ColumnSet mixin', function () {
        test.before(function () {
            var ColumnSetGrid = declare([ OnDemandGrid, Keyboard, ColumnSet ]);
            grid = new ColumnSetGrid({
                columnSets: [
                    [
                        [
                            { field: 'column1', label: 'Column 1' }
                        ]
                    ],
                    [
                        [
                            { field: 'column2', label: 'Column 2' },
                            { field: 'column3', label: 'Column 3' }
                        ]
                    ]
                ]
            });
 
            // Give the grid a specific width (as well as its columns) so that
            // expected behaviors occur regardless of browser window dimensions
            grid.domNode.style.width = '1000px';
            grid.styleColumnSet('0', 'width: 400px;');
            grid.styleColumn('1-0-0', 'width: 300px;');
            grid.styleColumn('1-0-1', 'width: 1000px;');
            document.body.appendChild(grid.domNode);
            grid.startup();
        });
 
        test.beforeEach(function () {
            var data = [];
            handles = [];
 
            for (var i = 0; i < 3; i++) {
                data.push({ id: i + 1, column1: 'Column 1', column2: 'Column 2', column3: 'Column 3' });
            }
 
            grid.set('collection', createSyncStore({ data: data }));
        });
 
        test.afterEach(function () {
            for (var i = handles.length; i--;) {
                handles[i].remove();
            }
        });
 
        test.after(function () {
            grid.destroy();
        });
 
        test.test('Re-inserted rows should maintain previous column set scroll positions', function () {
            var dfd = this.async(1000);
            var scrollAmount = 250;
 
            function assertScroll(messageSuffix) {
                var element = query('.dgrid-column-set-1 [data-dgrid-column-set-id="1"]', grid.row(1).element)[0];
                assert.strictEqual(element.scrollLeft, scrollAmount,
                    'Column Set scrollLeft should equal ' + scrollAmount + messageSuffix);
            }
 
            handles.push(aspect.after(grid, '_onColumnSetScroll', dfd.callback(function () {
                assertScroll(' before put');
                grid.collection.putSync(grid.collection.getSync(1));
                assertScroll(' after put');
            })));
 
            grid._scrollColumnSet('1', scrollAmount);
        });
 
        test.test('Horizontal scroll caused by cell focus should remain synchronized', function () {
            var dfd = this.async(1000);
 
            handles.push(aspect.after(grid, '_onColumnSetScroll', dfd.callback(function () {
                var element = query('.dgrid-column-set-1 [data-dgrid-column-set-id="1"]', grid.row(1).element)[0];
                assert.isTrue(element.scrollLeft > 0,
                    'Column Set 1 should have scrolled in response to right cell being focused');
            })));
 
            grid.focus(grid.cell(1, '1-0-1'));
        });
    });
 
    test.suite('ColumnSet + Tree mixins', function () {
        test.beforeEach(function () {
            var TreeColumnSetGrid = declare([ OnDemandGrid, ColumnSet, Tree ]);
            var data = [];
 
            for (var i = 0; i < 5; i++) {
                var parentId = '' + i;
                data.push({
                    id: parentId,
                    name: 'Root ' + i
                });
                for (var k = 0; k < 5; k++) {
                    data.push({
                        id: i + ':' + k,
                        parent: parentId,
                        name: 'Child ' + k,
                        hasChildren: false
                    });
                }
            }
 
            var store = createHierarchicalStore({
                data: data
            });
 
            grid = new TreeColumnSetGrid({
                collection: store,
                enableTreeTransitions: false,
                columnSets: [ [
                    [ { renderExpando: true, label: 'Name', field: 'name', sortable: false } ]
                ] ]
            });
 
            document.body.appendChild(grid.domNode);
            grid.startup();
        });
 
        test.afterEach(function () {
            for (var i = handles.length; i--;) {
                handles[i].remove();
            }
            grid.destroy();
        });
 
        test.test('re-expand after horizontal scroll should restore correct scrollLeft', function () {
            var scrollAmount = 250;
            grid.styleColumn('0-0-0', 'width: 10000px;');
 
            return grid.expand(0, true).then(function () {
                return grid.expand(0, false);
            }).then(function () {
                var scrollDfd = new Deferred();
                handles.push(aspect.after(grid, '_onColumnSetScroll', function () {
                    scrollDfd.resolve();
                }));
 
                grid._scrollColumnSet('0', scrollAmount);
                return scrollDfd.promise;
            }).then(function () {
                return grid.expand(0, true);
            }).then(function () {
                var element = query('.dgrid-column-set-0 [data-dgrid-column-set-id="0"]',
                    grid.row('0:0').element)[0];
 
                assert.strictEqual(element.scrollLeft, scrollAmount,
                    'Column Set should have expected scroll position for re-expanded rows');
            });
        });
    });
});