jxdnsong
2020-10-23 a7929e6b3ec9ac17233f39e55a2b8ac63ea75f42
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
define([
    'intern!tdd',
    'intern/chai!assert',
    'dojo/_base/declare',
    'dojo/query',
    'dgrid/Grid',
    'dgrid/ColumnSet',
    'dgrid/test/data/orderedData'
], function (test, assert, declare, query, Grid, ColumnSet, orderedData) {
 
    var grid;
 
    function runClassNameTests() {
        var domNode = grid.domNode,
            node;
 
        assert.strictEqual(query('.dgrid-cell.field-order', domNode).length, 10,
            'Each row (including header) should contain a cell with the field-order class');
        assert.strictEqual(query('.dgrid-cell.field-name', domNode).length, 10,
            'Each row (including header) should contain a cell with the field-name class');
        assert.strictEqual(query('.dgrid-cell.field-description', domNode).length, 10,
            'Each row (including header) should contain a cell with the field-description class');
 
        assert.strictEqual(query('.dgrid-cell.field-name.name-column.main-column', domNode).length, 10,
            'Each row\'s (including header\'s) field-name cell should have the name-column and main-column classes');
 
        assert.strictEqual(query('.dgrid-cell.field-description.desc-row', domNode).length, 9,
            'Each body row\'s description cell should also have the desc-row class');
        node = query('.dgrid-header .dgrid-cell.field-description', domNode)[0];
        assert.strictEqual(node.className.indexOf('undefined'), -1,
            'Header row\'s description cell should NOT contain \'undefined\' due to className returning \'\'');
        assert.isTrue(query('.dgrid-content .dgrid-cell.field-description', domNode).every(function (cell) {
                return (/desc-\w+ desc-row/).test(cell.className);
            }),
            'Each body row\'s description cell has two desc-* classes (one being desc-row)');
    }
 
    test.suite('columns', function () {
        test.afterEach(function () {
            grid.destroy();
        });
 
        test.test('className property', function () {
            grid = new Grid({
                columns: {
                    order: 'Order',
                    name: {
                        label: 'Name',
                        className: 'name-column main-column'
                    },
                    description: {
                        label: 'Description',
                        className: function (object) {
                            return object ?
                                'desc-' + object.name.replace(/ /g, '') + ' desc-row' :
                                '';
                        }
                    }
                }
            });
            document.body.appendChild(grid.domNode);
            grid.startup();
            grid.renderArray(orderedData.items);
            runClassNameTests();
        });
    });
 
    test.suite('columnSets', function () {
        test.afterEach(function () {
            grid.destroy();
        });
 
        test.test('className property', function () {
            grid = new (declare([Grid, ColumnSet]))({
                columnSets: [
                    [[
                        { field: 'order', label: 'Order' },
                        {
                            field: 'name',
                            label: 'Name',
                            className: 'name-column main-column'
                        }
                    ]], [[
                        {
                            field: 'description',
                            label: 'Description',
                            className: function (object) {
                                return object ?
                                    'desc-' + object.name.replace(/ /g, '') + ' desc-row' :
                                    '';
                            }
                        }
                    ]]
                ]
            });
            document.body.appendChild(grid.domNode);
            grid.startup();
            grid.renderArray(orderedData.items);
            runClassNameTests();
        });
    });
});