Ext-mess.backup
5.7 KB
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
189
190
191
192
193
194
195
196
197
198
describe("Ext-mess", function() {
xdescribe("Ext.repaint", function() {
it("should create a mask in the body", function(){
var body = Ext.getBody();
spyOn(Ext, "getBody").andCallThrough();
spyOn(body, "createChild").andCallThrough();
Ext.repaint();
expect(Ext.getBody).toHaveBeenCalled();
expect(body.createChild).toHaveBeenCalledWith({cls: "x-mask x-mask-transparent", tag: "div"});
});
});
describe("Ext.num", function() {
it("should work with an integer", function() {
expect(Ext.num(3)).toEqual(3);
});
it("should work with a negative integer", function() {
expect(Ext.num(-7)).toEqual(-7);
});
it("should work with a float", function() {
expect(Ext.num(5.43)).toEqual(5.43);
});
it("should work with a negative float", function() {
expect(Ext.num(-9.8)).toEqual(-9.8);
});
it("should work with Math.PI", function() {
expect(Ext.num(Math.PI)).toEqual(Math.PI);
});
it("should return undefined with null", function() {
expect(Ext.num(null)).toBeUndefined();
});
it("should work with null, with defaults", function() {
expect(Ext.num(null, 4)).toEqual(4);
});
it("should return undefined with undefined", function() {
expect(Ext.num(undefined)).toBeUndefined();
});
it("should work with undefined, with defaults", function() {
expect(Ext.num(undefined, 42)).toEqual(42);
});
it("should return undefined with boolean", function() {
expect(Ext.num(true)).toBeUndefined();
});
it("should work with boolean, with defaults", function() {
expect(Ext.num(true, 12)).toEqual(12);
});
it("should return undefined with empty string", function() {
expect(Ext.num("")).toBeUndefined();
});
it("should work with string argument in the form of a number", function() {
expect(Ext.num('666')).toEqual(666);
});
it("should return undefined with a string containing only spaces", function() {
expect(Ext.num(" ")).toBeUndefined();
});
it("should return undefined with non empty string", function() {
expect(Ext.num("foo")).toBeUndefined();
});
it("should return undefined with empty array", function() {
expect(Ext.num([])).toBeUndefined();
});
it("should return undefined with non empty array", function() {
expect(Ext.num([1, 2, 3])).toBeUndefined();
});
it("should return undefined with array with a single item", function() {
expect(Ext.num([3])).toBeUndefined();
});
});
describe("Ext.pluck", function() {
it("should return results", function() {
var results = Ext.pluck([{
n: 11,
c: 17
}, {
n: 13,
p: true
}, {
n: 18,
p: false
}], 'n');
expect(results).toEqual([11, 13, 18]);
});
});
describe("Ext.toArray", function() {
var span1,
span2,
span3,
span4,
div,
htmlCollection;
beforeEach(function() {
div = Ext.getBody().createChild({tag: "div"});
span1 = div.createChild({tag: "span"});
span2 = div.createChild({tag: "span"});
span3 = div.createChild({tag: "span"});
span4 = div.createChild({tag: "span"});
htmlCollection = div.dom.getElementsByTagName("span");
});
it("should convert iterable to an array", function() {
expect(Ext.toArray(htmlCollection)).toEqual([span1.dom, span2.dom, span3.dom, span4.dom]);
});
it("should convert a part of an iterable to an array", function() {
expect(Ext.toArray(htmlCollection, 1, 3)).toEqual([span2.dom, span3.dom]);
});
});
xdescribe("Ext.urlDecode", function() {
it ("should return an empty object if string is empty", function (){
expect(Ext.urlDecode("")).toEqual({});
});
it("should decode 2 keys", function(){
expect(Ext.urlDecode("foo=1&bar=2")).toEqual({
foo: "1",
bar: "2"
});
});
it("should decode 2 keys, one of them an array (overwrite off)", function() {
expect(Ext.urlDecode("foo=1&bar=2&bar=3&bar=4", false)).toEqual({
foo: "1",
bar: ['2', '3', '4']
});
});
it("should decode 2 keys, one of them an array (overwrite on)", function() {
expect(Ext.urlDecode("foo=1&bar=2&bar=3&bar=4", true)).toEqual({
foo: "1",
bar: "4"
});
});
});
xdescribe("Ext.urlEncode", function() {
it("should encode 2 keys", function() {
expect(Ext.urlEncode({
foo: "1",
bar: "2"
})).toEqual("foo=1&bar=2");
});
it("should encode 2 keys, one of them an array", function() {
expect(Ext.urlEncode({
foo: "1",
bar: ['2', '3', '4']
})).toEqual("foo=1&bar=2&bar=3&bar=4");
});
it("should encode 2 keys, one of them an array, with pre: test=1", function() {
expect(Ext.urlEncode({
foo: "1",
bar: ['2', '3', '4']
}, "test=1")).toEqual("test=1&foo=1&bar=2&bar=3&bar=4");
});
});
});