liuyg
2021-07-02 25ce610f6ecca7325e7a743dc032c4a76559c63d
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
define([
    'intern!tdd',
    'intern/chai!assert',
    'dgrid/Grid',
    'dgrid/ColumnSet',
    'dgrid/OnDemandGrid',
    'dgrid/Tree',
    'dgrid/extensions/CompoundColumns',
    'dgrid/extensions/SingleQuery',
    'dojo/_base/declare',
    'dojo/query',
    'dgrid/test/data/createHierarchicalStore',
    'dgrid/test/data/hierarchicalCountryData',
    '../addCss!'
], function (test, assert, Grid, ColumnSet, OnDemandGrid, Tree, CompoundColumns, SingleQuery, declare, query,
        createHierarchicalStore, data) {
 
    test.suite('tree indent', function () {
        var grid;
        var treeIndentWidth = 20;
 
        test.afterEach(function () {
            if (grid) {
                grid.destroy();
                grid = null;
            }
        });
 
        function testIndentWidth(id, level) {
            var row = grid.row(id);
            assert.ok(row.element, 'Expected child row exists for ID ' + id);
            query('.dgrid-expando-icon', row.element).forEach(function (element) {
                assert.strictEqual(element.style.marginLeft, treeIndentWidth * level + 'px',
                    'Child row should have expected indent width corresponding with indentation level ' + level);
            });
        }
 
        function level1Test() {
            return grid.expand('AF').then(function () {
                testIndentWidth('EG', 1);
            });
        }
 
        function level2Test() {
            return grid.expand('AF').then(function () {
                return grid.expand('EG');
            }).then(function () {
                testIndentWidth('Cairo', 2);
            });
        }
 
        test.suite('OnDemandGrid + tree', function () {
            test.beforeEach(function () {
                grid = new (declare([ OnDemandGrid, Tree ]))({
                    collection: createHierarchicalStore({ data: data }),
                    treeIndentWidth: treeIndentWidth,
                    enableTreeTransitions: false,
                    columns: [
                        {
                            field: 'name',
                            label: 'Name',
                            renderExpando: true
                        },
                        {
                            field: 'type',
                            label: 'Type'
                        }, {
                            field: 'population',
                            label: 'Population'
                        }
                    ]
                });
                document.body.appendChild(grid.domNode);
                grid.startup();
            });
 
            test.test('level 1', level1Test);
            test.test('level 2', level2Test);
 
            test.test('refreshCell', function () {
                return grid.expand('AF').then(function () {
                    return grid.expand('EG');
                }).then(function () {
                    var cell = grid.cell('Cairo', '0');
 
                    return grid.refreshCell(cell).then(level2Test);
                });
            });
        });
 
        test.suite('OnDemandGrid + tree + compound columns + column sets', function () {
            test.beforeEach(function () {
                grid = new (declare([ OnDemandGrid, Tree, CompoundColumns, ColumnSet ]))({
                    collection: createHierarchicalStore({ data: data }),
                    treeIndentWidth: treeIndentWidth,
                    enableTreeTransitions: false,
                    columnSets: [
                        [
                            [
                                {
                                    field: 'name',
                                    label: 'Name',
                                    renderExpando: true
                                }
                            ]
                        ],
                        [
                            [
                                {
                                    label: 'Information',
                                    children: [
                                        {
                                            field: 'type',
                                            label: 'Type'
                                        }, {
                                            field: 'population',
                                            label: 'Population'
                                        }
                                    ]
                                }
                            ]
                        ]
                    ]
                });
                document.body.appendChild(grid.domNode);
                grid.startup();
            });
 
            test.test('level 1', level1Test);
            test.test('level 2', level2Test);
        });
 
        test.suite('SingleQuery + Tree', function () {
            var store;
 
            test.beforeEach(function () {
                store = createHierarchicalStore({ data: [ { id: 1 } ] });
                grid = new (declare([ Grid, SingleQuery, Tree ]))({
                    collection: store,
                    columns: {
                        id: {
                            renderExpando: true,
                            label: 'ID'
                        }
                    },
                    treeIndentWidth: treeIndentWidth
                });
                document.body.appendChild(grid.domNode);
                grid.startup();
            });
 
            test.test('Child indentation, both when parent is collapsed and expanded', function () {
                store.addSync({ id: 2, parent: 1 });
                return grid.expand(1).then(function () {
                    testIndentWidth(2, 1);
                    store.addSync({ id: 3, parent: 1 });
                    testIndentWidth(3, 1);
                });
            });
 
            test.test('refreshCell on parent after a child is rendered', function () {
                store.addSync({ id: 2, parent: 1 });
                return grid.expand(1).then(function () {
                    grid.refreshCell(grid.cell(1, 'id'));
                    testIndentWidth(1, 0);
                });
            });
        });
    });
});