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
define([
    'intern!tdd',
    'intern/chai!assert',
    'intern/dojo/node!leadfoot/helpers/pollUntil',
    'intern/dojo/node!leadfoot/keys',
    'require'
], function (test, assert, pollUntil, keys, require) {
    function testUpDownKeys(gridId, cellNavigation) {
        var rootQuery = '#' + gridId + ' #' + gridId + '-row-';
        return function () {
            return this.remote
                .findByCssSelector(rootQuery + '0' + (cellNavigation ? ' .dgrid-column-col1' : ''))
                    .click()
                    .type([keys.ARROW_DOWN])
                    .end()
                .findByCssSelector(rootQuery + '1' + (cellNavigation ? ' .dgrid-column-col1' : ''))
                    .getAttribute('class')
                    .then(function (classNames) {
                        var arr = classNames.split(' '),
                            containsClass = (arr.indexOf('dgrid-focus') !== -1);
                        assert.ok(containsClass, 'the down arrow key should move focus one element down');
                    })
                    .type([keys.ARROW_UP])
                    .end()
                .findByCssSelector(rootQuery + '0' + (cellNavigation ? ' .dgrid-column-col1' : ''))
                    .getAttribute('class')
                    .then(function (classNames) {
                        var arr = classNames.split(' '),
                            containsClass = (arr.indexOf('dgrid-focus') !== -1);
                        assert.ok(containsClass, 'the up arrow key should move focus one element up');
                    })
                    .end();
        };
    }
 
    function testLeftRightKeys(gridId, header) {
        var rootQuery = header ? ('#' + gridId + ' .dgrid-header') : ('#' + gridId + ' #' + gridId + '-row-0');
        return function () {
            return this.remote
                .findByCssSelector(rootQuery + ' .dgrid-column-col1')
                    .click()
                    .type([keys.ARROW_RIGHT])
                    .end()
                .findByCssSelector(rootQuery + ' .dgrid-column-col2')
                    .getAttribute('class')
                    .then(function (classNames) {
                        var arr = classNames.split(' '),
                            containsClass = (arr.indexOf('dgrid-focus') !== -1);
                        assert.ok(containsClass, 'the right arrow key should move focus one element right');
                    })
                    .type([keys.ARROW_LEFT])
                    .end()
                .findByCssSelector(rootQuery + ' .dgrid-column-col1')
                    .getAttribute('class')
                    .then(function (classNames) {
                        var arr = classNames.split(' '),
                            containsClass = (arr.indexOf('dgrid-focus') !== -1);
                        assert.ok(containsClass, 'the left arrow key should move focus one element left');
                    })
                    .end();
        };
    }
 
    function testHomeEndKeys(gridId, cellNavigation, lastId) {
        var rootQuery = '#' + gridId + ' #' + gridId + '-row-';
        lastId = lastId || 99;
 
        return function () {
            return this.remote
                .findByCssSelector(rootQuery + '0' + (cellNavigation ? ' .dgrid-column-col1' : ''))
                    .click()
                    .type([keys.END])
                    .end()
                .setFindTimeout(1000)
                .findByCssSelector('#' + gridId + '-row-' + lastId + (cellNavigation ? ' .dgrid-column-col1' : ''))
                    .getAttribute('class')
                    .then(function (classNames) {
                        var arr = classNames.split(' '),
                        containsClass = arr.indexOf('dgrid-focus') !== -1;
                        assert.ok(containsClass, 'the end key should move focus to the last element in the list');
                    })
                    .type([keys.HOME])
                    .end()
                .findByCssSelector(rootQuery + '0' + (cellNavigation ? ' .dgrid-column-col1' : ''))
                    .getAttribute('class')
                    .then(function (classNames) {
                        var arr = classNames.split(' '),
                            containsClass = (arr.indexOf('dgrid-focus') !== -1);
                        assert.ok(containsClass, 'the home key should move focus to the first element in the list');
                    })
                    .end();
        };
    }
 
    test.suite('Keyboard functional tests', function () {
        test.before(function () {
            // Get our html page. This page should load all necessary scripts
            // since this functional test module runs on the server and can't load
            // such scripts. Further, in the html page, set a global "ready" var
            // to true to tell the runner to continue.
            return this.remote
                .get(require.toUrl('./Keyboard.html'))
                .then(pollUntil(function () {
                    return window.ready;
                }, null, 5000));
        });
 
        test.test('grid (cellNavigation: true) -> up + down arrow keys',
            testUpDownKeys('grid', true));
 
        test.test('grid (cellNavigation: false) -> up + down arrow keys',
            testUpDownKeys('rowGrid'));
 
        test.test('list -> up + down arrow keys',
            testUpDownKeys('list'));
 
        test.test('grid row -> left + right arrow keys',
            testLeftRightKeys('grid'));
 
        test.test('grid header -> left + right arrow keys',
            testUpDownKeys('grid', true));
 
        test.test('simple grid (cellNavigation: true) -> home + end keys',
            testHomeEndKeys('grid', true));
 
        test.test('simple grid (cellNavigation: false) -> home + end keys',
            testHomeEndKeys('rowGrid'));
 
        test.test('simple list -> home + end keys',
            testHomeEndKeys('list'));
 
        test.test('on-demand grid (cellNavigation: true) -> home + end keys',
            testHomeEndKeys('grid-ondemand', true));
 
        test.test('on-demand simple grid (cellNavigation: false) -> home + end keys',
            testHomeEndKeys('rowGrid-ondemand', false));
 
        test.test('on-demand simple list -> home + end keys',
            testHomeEndKeys('list-ondemand', false));
 
        test.test('on-demand grid with large data set -> home + end keys',
            testHomeEndKeys('grid-large-data-set', true, 14499));
    });
});