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
define([
    'intern!tdd',
    'intern/chai!assert',
    'dojo/on',
    'dgrid/List',
    'dgrid/util/misc'
], function (test, assert, on, List, miscUtil) {
    test.suite('List', function() {
        test.suite('resize', function() {
            var list;
 
            test.afterEach(function() {
                if (list && list._started) {
                    list.destroy();
                }
            });
 
            test.test('default throttle', function() {
                var originalThrottleDelayed = miscUtil.throttleDelayed;
                var throttleCalled = false;
 
                miscUtil.throttleDelayed = function() {
                    return function() {
                        throttleCalled = true;
                    };
                };
 
                try {
                    list = new List();
 
                    document.body.appendChild(list.domNode);
                    // necessary to start up list since resize handler only runs if list is started up
                    list.startup();
 
                    on.emit(window, 'resize', {});
                    assert.isTrue(throttleCalled, 'Default window resize handler should be called');
                }
                finally {
                    miscUtil.throttleDelayed = originalThrottleDelayed;
                }
            });
 
            test.test('custom throttle: string', function() {
                var originalDebounce = miscUtil.debounce;
                var throttleCalled = false;
 
                miscUtil.debounce = function() {
                    return function() {
                        throttleCalled = true;
                    };
                };
 
                try {
                    list = new List({
                        resizeThrottleMethod: 'debounce'
                    });
 
                    document.body.appendChild(list.domNode);
                    list.startup();
 
                    on.emit(window, 'resize', {});
                    assert.isTrue(throttleCalled, 'Configured window resize handler should be called');
                }
                finally {
                    miscUtil.debounce = originalDebounce;
                }
            });
 
            test.test('custom throttle: invalid string', function() {
                var originalThrottleDelayed = miscUtil.throttleDelayed;
                var throttleCalled = false;
 
                miscUtil.throttleDelayed = function() {
                    return function() {
                        throttleCalled = true;
                    };
                };
 
                try {
                    list = new List({
                        resizeThrottleMethod: 'not a valid throttle function name'
                    });
 
                    document.body.appendChild(list.domNode);
                    list.startup();
 
                    on.emit(window, 'resize', {});
                    assert.isTrue(throttleCalled, 'Default window resize handler should be called');
                }
                finally {
                    miscUtil.throttleDelayed = originalThrottleDelayed;
                }
            });
 
            test.test('custom throttle: function', function() {
                var throttleCalled = false;
                var throttleDelay;
 
                list = new List({
                    resizeThrottleMethod: function(callback, delay) {
                        throttleDelay = delay;
 
                        return function() {
                            throttleCalled = true;
                        };
                    }
                });
 
                document.body.appendChild(list.domNode);
                list.startup();
 
                assert.strictEqual(miscUtil.defaultDelay, throttleDelay, 'Custom throttle function should receive delay value');
 
                on.emit(window, 'resize', {});
                assert.isTrue(throttleCalled, 'Custom window resize handler should be called');
            });
        });
    });
});