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
define([
    'intern!tdd',
    'intern/chai!assert',
    'dojo/_base/array',
    'dojo/_base/declare',
    'dojo/aspect',
    'dojo/dom-construct',
    'dijit/registry',
    'dijit/layout/BorderContainer',
    'dijit/layout/StackContainer',
    'dgrid/List',
    'dgrid/extensions/DijitRegistry',
    'dojo/domReady!'
], function (test, assert, arrayUtil, declare, aspect, domConstruct,
        registry, BorderContainer, StackContainer, List, DijitRegistry) {
 
    var list,
        DijitList = declare([ List, DijitRegistry ]);
 
    test.suite('DijitRegistry', function () {
        test.afterEach(function () {
            list.destroy();
        });
 
        test.test('Dijit registry population', function () {
            var id = 'myId';
            list = new DijitList({ id: id });
            assert.strictEqual(registry.byId(id), list,
                'dgrid instances with DijitRegistry mixin should appear in dijit/registry');
        });
 
        test.suite('#placeAt', function () {
            test.beforeEach(function () {
                list = new DijitList();
            });
 
            test.suite('DOM', function () {
                var referenceNode;
                test.before(function () {
                    referenceNode = domConstruct.create('div', null, document.body);
                });
 
                test.afterEach(function () {
                    domConstruct.empty(referenceNode);
                });
 
                test.after(function () {
                    domConstruct.destroy(referenceNode);
                });
 
                test.test('default placement (last child)', function () {
                    domConstruct.create('div', null, referenceNode);
                    list.placeAt(referenceNode);
                    assert.strictEqual(referenceNode.lastChild, list.domNode,
                        'placeAt with domNode should place dgrid instance as the last child by default');
                });
 
                test.test('specified placement', function () {
                    list.placeAt(referenceNode, 'after');
                    assert.strictEqual(referenceNode.nextSibling, list.domNode,
                        'placeAt with domNode and placement argument should operate like domConstruct.place');
                });
            });
 
            test.suite('Dijit (also tests startup/destroy)', function () {
                var containerWidget;
 
                test.afterEach(function () {
                    containerWidget.destroyRecursive();
                });
 
                function createContainerTest(Ctor) {
                    return function () {
                        containerWidget = new Ctor().placeAt(document.body);
                        containerWidget.startup();
 
                        var startupCalled = 0;
                        var destroyCalled = 0;
                        aspect.before(list, 'startup', function () {
                            startupCalled++;
                        });
                        aspect.before(list, 'destroy', function () {
                            destroyCalled++;
                        });
 
                        list.region = 'center'; // For BorderContainer (irrelevant for others)
                        list.placeAt(containerWidget);
 
                        assert.strictEqual(arrayUtil.indexOf(containerWidget.getChildren(), list), 0,
                            'placeAt with layout widget should place dgrid instance inside layout widget');
                        assert.strictEqual(startupCalled, 1,
                            'dgrid instance should be started up when placed inside a started-up layout widget');
 
                        containerWidget.destroyRecursive();
                        assert.strictEqual(destroyCalled, 1,
                            'list should be destroyed when destroyRecursive is called on its containing widget');
                    };
                }
 
                test.test('BorderContainer', createContainerTest(BorderContainer));
                test.test('StackContainer', createContainerTest(StackContainer));
            });
        });
    });
});