-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ajax-list.es6
188 lines (161 loc) · 5.52 KB
/
test.ajax-list.es6
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import sinon from 'sinon';
import AjaxListClass from '../src/models/AjaxList';
import assert from 'assert';
describe('ajax-call: AjaxList', () => {
it('Constructor', (done) => {
let AjaxList = new AjaxListClass();
AjaxList.should.containEql({});
AjaxList.should.have.property('result', 0);
AjaxList.should.have.property('message', '');
AjaxList.should.have.property('value', {});
AjaxList.should.have.property('items', []);
done();
});
it('Add item', (done) => {
let AjaxList = new AjaxListClass();
AjaxList.addItem({a:1});
AjaxList.should.have.property('result', 0);
AjaxList.should.have.property('message', '');
AjaxList.should.have.property('value', {});
AjaxList.should.have.property('items', [{a:1}]);
done();
});
it('Add more item', (done) => {
let AjaxList = new AjaxListClass();
AjaxList.addItem(1);
AjaxList.addItem(2);
AjaxList.addItem(4);
AjaxList.addItem(3);
AjaxList.addItem({a:1,b:2,c:3});
AjaxList.should.have.property('result', 0);
AjaxList.should.have.property('message', '');
AjaxList.should.have.property('value', {});
AjaxList.should.have.property('items', [1, 2, 4, 3, {a:1,b:2,c:3}]);
done();
});
it('Set items with array', (done) => {
let AjaxList = new AjaxListClass();
AjaxList.items = [1, 3, 5, 10];
AjaxList.should.have.property('result', 0);
AjaxList.should.have.property('message', '');
AjaxList.should.have.property('value', {});
AjaxList.should.have.property('items', [1, 3, 5, 10]);
AjaxList.addItem(500);
AjaxList.should.have.property('items', [1, 3, 5, 10, 500]);
done();
});
it('Set items with non array', (done) => {
let AjaxList = new AjaxListClass();
(() => AjaxList.items = 'string')
.should.throw(TypeError, { message: 'Items must be array!' });
done();
});
it('Concat items', (done) => {
let AjaxList = new AjaxListClass();
AjaxList.items = [1, 3, 5, 10];
AjaxList.should.have.property('result', 0);
AjaxList.should.have.property('message', '');
AjaxList.should.have.property('value', {});
AjaxList.should.have.property('items', [1, 3, 5, 10]);
AjaxList.concatItems(100);
AjaxList.should.have.property('items', [1, 3, 5, 10, 100]);
AjaxList.concatItems(['a', 'b', 'c']);
AjaxList.should.have.property('items', [1, 3, 5, 10, 100, 'a', 'b', 'c']);
AjaxList.concatItems(111, [8, 7, 6]);
AjaxList.should.have.property('items',
[1, 3, 5, 10, 100, 'a', 'b', 'c', 111, 8, 7, 6]);
done();
});
it('Add unique item', (done) => {
let AjaxList = new AjaxListClass();
AjaxList.addUniqueItem(1);
AjaxList.addUniqueItem(2);
AjaxList.addUniqueItem(4);
AjaxList.addUniqueItem(3);
AjaxList.addUniqueItem({a:1,b:2,c:3});
AjaxList.should.have.property('result', 0);
AjaxList.should.have.property('message', '');
AjaxList.should.have.property('value', {});
AjaxList.should.have.property('uniqueItems').instanceof(Set);
[...AjaxList.uniqueItems].should.be.eql([1, 2, 4, 3, {a:1,b:2,c:3}]);
AjaxList.addUniqueItem(2);
AjaxList.addUniqueItem(4);
AjaxList.addUniqueItem(3);
AjaxList.should.have.property('uniqueItems').instanceof(Set);
[...AjaxList.uniqueItems].should.be.eql([1, 2, 4, 3, {a:1,b:2,c:3}]);
done();
});
describe('Set unique items', () => {
let AjaxList;
before(() => {
AjaxList = new AjaxListClass();
AjaxList.should.have.property('result', 0);
AjaxList.should.have.property('message', '');
AjaxList.should.have.property('value', {});
AjaxList.should.have.property('items', []);
});
it('set unique items with array value', (done) => {
AjaxList.uniqueItems = [1, 2, 555, {a:1,b:2,c:3}];
AjaxList.should.have.property('uniqueItems').instanceof(Set);
[...AjaxList.uniqueItems].should.be.eql([1, 2, 555, {a:1,b:2,c:3}]);
AjaxList.uniqueItems = [1, 3, 5, 10, 100, 'a', 'b', 'c', 111, 8, 7, 6];
AjaxList.should.have.property('uniqueItems').instanceof(Set);
[...AjaxList.uniqueItems].should.be.eql(
[1, 3, 5, 10, 100, 'a', 'b', 'c', 111, 8, 7, 6]);
done();
});
it('set unique items without array value', (done) => {
AjaxList.uniqueItems = {a:1,b:2,c:3};
AjaxList.should.have.property('uniqueItems').instanceof(Set);
[...AjaxList.uniqueItems].should.be.eql([{a:1,b:2,c:3}]);
AjaxList.uniqueItems = 'string';
AjaxList.should.have.property('uniqueItems').instanceof(Set);
[...AjaxList.uniqueItems].should.be.eql(['string']);
done();
});
});
it('get struct empty', (done) => {
let AjaxList = new AjaxListClass();
let struct = AjaxList.getStruct();
assert.deepEqual(struct, {
code: 0,
success: true,
result: 0,
message: '',
value: {},
items: []
});
done();
});
it('get struct not empty', (done) => {
let AjaxList = new AjaxListClass();
AjaxList.addItem(1);
AjaxList.addItem(2);
let struct = AjaxList.getStruct();
assert.deepEqual(struct, {
code: 0,
success: true,
result: 0,
message: '',
value: {},
items: [1, 2]
});
done();
});
it('get struct not empty with uniqueItems', (done) => {
let AjaxList = new AjaxListClass();
AjaxList.addUniqueItem(1);
AjaxList.addUniqueItem(2);
let struct = AjaxList.getStruct();
assert.deepEqual(struct, {
code: 0,
success: true,
result: 0,
message: '',
value: {},
items: [],
uniqueItems: [1, 2]
});
done();
});
});