Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit 370b820

Browse files
committed
Merge pull request #76 from thgreasi/angular1.2
Added DOM checks for each model test.
2 parents e53fcdf + 04eda30 commit 370b820

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

test/sortable.spec.js

+48-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ describe('uiSortable', function() {
33
// Ensure the sortable angular module is loaded
44
beforeEach(module('ui.sortable'));
55

6+
beforeEach(function() {
7+
this.addMatchers({
8+
toEqualListContent: function (list) {
9+
if (list && list.length) {
10+
return list.children().map(function(){ return this.innerHTML; }).toArray();
11+
}
12+
return [];
13+
}
14+
});
15+
});
16+
617
var EXTRA_DY_PERCENTAGE = 0.25;
718

819
describe('Simple use', function() {
@@ -60,11 +71,13 @@ describe('uiSortable', function() {
6071
var dy = (1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
6172
li.simulate('drag', { dy: dy });
6273
expect($rootScope.items).toEqual(["One", "Three", "Two"]);
74+
expect($rootScope.items).toEqualListContent(element);
6375

6476
li = element.find(':eq(1)');
6577
dy = -(1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
6678
li.simulate('drag', { dy: dy });
6779
expect($rootScope.items).toEqual(["Three", "One", "Two"]);
80+
expect($rootScope.items).toEqualListContent(element);
6881

6982
$(element).remove();
7083
});
@@ -92,21 +105,25 @@ describe('uiSortable', function() {
92105
var dy = (1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
93106
li.simulate('drag', { dy: dy });
94107
expect($rootScope.items.map(function(x){ return x.text; })).toEqual(["One", "Two", "Three", "Four"]);
108+
expect($rootScope.items.map(function(x){ return x.text; })).toEqualListContent(element);
95109

96110
li = element.find(':eq(1)');
97111
dy = (2 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
98112
li.simulate('drag', { dy: dy });
99113
expect($rootScope.items.map(function(x){ return x.text; })).toEqual(["One", "Three", "Four", "Two"]);
114+
expect($rootScope.items.map(function(x){ return x.text; })).toEqualListContent(element);
100115

101116
li = element.find(':eq(2)');
102117
dy = -(2 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
103118
li.simulate('drag', { dy: dy });
104119
expect($rootScope.items.map(function(x){ return x.text; })).toEqual(["Four", "One", "Three", "Two"]);
120+
expect($rootScope.items.map(function(x){ return x.text; })).toEqualListContent(element);
105121

106122
li = element.find(':eq(3)');
107123
dy = -(2 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
108124
li.simulate('drag', { dy: dy });
109125
expect($rootScope.items.map(function(x){ return x.text; })).toEqual(["Four", "Two", "One", "Three"]);
126+
expect($rootScope.items.map(function(x){ return x.text; })).toEqualListContent(element);
110127

111128
// also placing right above the locked node seems a bit harder !?!?
112129

@@ -131,11 +148,13 @@ describe('uiSortable', function() {
131148
var dy = (1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
132149
li.simulate('drag', { dy: dy });
133150
expect($rootScope.items).toEqual(["One", "Three", "Two"]);
151+
expect($rootScope.items).toEqualListContent(element);
134152

135153
li = element.find(':eq(1)');
136154
dy = -(1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
137155
li.simulate('drag', { dy: dy });
138156
expect($rootScope.items).toEqual(["Three", "One", "Two"]);
157+
expect($rootScope.items).toEqualListContent(element);
139158

140159
$(element).remove();
141160
});
@@ -158,11 +177,13 @@ describe('uiSortable', function() {
158177
var dy = (1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
159178
li.simulate('drag', { dy: dy });
160179
expect($rootScope.items).toEqual(["One", "Three", "Two"]);
180+
expect($rootScope.items).toEqualListContent(element);
161181

162182
li = element.find(':eq(1)');
163183
dy = -(1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
164184
li.simulate('drag', { dy: dy });
165185
expect($rootScope.items).toEqual(["Three", "One", "Two"]);
186+
expect($rootScope.items).toEqualListContent(element);
166187

167188
$(element).remove();
168189
});
@@ -203,13 +224,17 @@ describe('uiSortable', function() {
203224
li1.simulate('drag', { dy: dy });
204225
expect($rootScope.itemsTop).toEqual(["Top Two", "Top Three"]);
205226
expect($rootScope.itemsBottom).toEqual(["Bottom One", "Top One", "Bottom Two", "Bottom Three"]);
227+
expect($rootScope.itemsTop).toEqualListContent(elementTop);
228+
expect($rootScope.itemsBottom).toEqualListContent(elementBottom);
206229

207230
li1 = elementBottom.find(':eq(1)');
208231
li2 = elementTop.find(':eq(1)');
209232
dy = -EXTRA_DY_PERCENTAGE * li1.outerHeight() - (li1.position().top - li2.position().top);
210233
li1.simulate('drag', { dy: dy });
211234
expect($rootScope.itemsTop).toEqual(["Top Two", "Top One", "Top Three"]);
212235
expect($rootScope.itemsBottom).toEqual(["Bottom One", "Bottom Two", "Bottom Three"]);
236+
expect($rootScope.itemsTop).toEqualListContent(elementTop);
237+
expect($rootScope.itemsBottom).toEqualListContent(elementBottom);
213238

214239
$(elementTop).remove();
215240
$(elementBottom).remove();
@@ -238,13 +263,17 @@ describe('uiSortable', function() {
238263
li1.simulate('drag', { dy: dy });
239264
expect($rootScope.itemsTop).toEqual(["Top Two", "Top Three"]);
240265
expect($rootScope.itemsBottom).toEqual(["Bottom One", "Top One", "Bottom Two", "Bottom Three"]);
266+
expect($rootScope.itemsTop).toEqualListContent(elementTop);
267+
expect($rootScope.itemsBottom).toEqualListContent(elementBottom);
241268

242269
li1 = elementBottom.find(':eq(1)');
243270
li2 = elementTop.find(':eq(1)');
244271
dy = -EXTRA_DY_PERCENTAGE * li1.outerHeight() - (li1.position().top - li2.position().top);
245272
li1.simulate('drag', { dy: dy });
246273
expect($rootScope.itemsTop).toEqual(["Top Two", "Top One", "Top Three"]);
247274
expect($rootScope.itemsBottom).toEqual(["Bottom One", "Bottom Two", "Bottom Three"]);
275+
expect($rootScope.itemsTop).toEqualListContent(elementTop);
276+
expect($rootScope.itemsBottom).toEqualListContent(elementBottom);
248277

249278
$(elementTop).remove();
250279
$(elementBottom).remove();
@@ -273,13 +302,17 @@ describe('uiSortable', function() {
273302
li1.simulate('drag', { dy: dy });
274303
expect($rootScope.itemsTop).toEqual(["Top Two", "Top Three"]);
275304
expect($rootScope.itemsBottom).toEqual(["Bottom One", "Top One", "Bottom Two", "Bottom Three"]);
305+
expect($rootScope.itemsTop).toEqualListContent(elementTop);
306+
expect($rootScope.itemsBottom).toEqualListContent(elementBottom);
276307

277308
li1 = elementBottom.find(':eq(1)');
278309
li2 = elementTop.find(':eq(1)');
279310
dy = -EXTRA_DY_PERCENTAGE * li1.outerHeight() - (li1.position().top - li2.position().top);
280311
li1.simulate('drag', { dy: dy });
281312
expect($rootScope.itemsTop).toEqual(["Top Two", "Top One", "Top Three"]);
282313
expect($rootScope.itemsBottom).toEqual(["Bottom One", "Bottom Two", "Bottom Three"]);
314+
expect($rootScope.itemsTop).toEqualListContent(elementTop);
315+
expect($rootScope.itemsBottom).toEqualListContent(elementBottom);
283316

284317
$(elementTop).remove();
285318
$(elementBottom).remove();
@@ -324,16 +357,19 @@ describe('uiSortable', function() {
324357
var dy = (1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
325358
li.simulate('drag', { dy: dy });
326359
expect($rootScope.items).toEqual(["One", "Two", "Three"]);
360+
expect($rootScope.items).toEqualListContent(element);
327361

328362
li = element.find(':eq(0)');
329363
dy = (2 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
330364
li.simulate('drag', { dy: dy });
331365
expect($rootScope.items).toEqual(["Two", "Three", "One"]);
366+
expect($rootScope.items).toEqualListContent(element);
332367

333368
li = element.find(':eq(2)');
334369
dy = -(2 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
335370
li.simulate('drag', { dy: dy });
336371
expect($rootScope.items).toEqual(["One", "Two", "Three"]);
372+
expect($rootScope.items).toEqualListContent(element);
337373

338374
$(element).remove();
339375
});
@@ -367,27 +403,35 @@ describe('uiSortable', function() {
367403
li1.simulate('drag', { dy: dy });
368404
expect($rootScope.itemsTop).toEqual(["Top One", "Top Two", "Top Three"]);
369405
expect($rootScope.itemsBottom).toEqual(["Bottom One", "Bottom Two", "Bottom Three"]);
406+
expect($rootScope.itemsTop).toEqualListContent(elementTop);
407+
expect($rootScope.itemsBottom).toEqualListContent(elementBottom);
370408

371409
li1 = elementBottom.find(':eq(1)');
372410
li2 = elementTop.find(':eq(1)');
373411
dy = -EXTRA_DY_PERCENTAGE * li1.outerHeight() - (li1.position().top - li2.position().top);
374412
li1.simulate('drag', { dy: dy });
375413
expect($rootScope.itemsTop).toEqual(["Top One", "Top Two", "Top Three"]);
376414
expect($rootScope.itemsBottom).toEqual(["Bottom One", "Bottom Two", "Bottom Three"]);
415+
expect($rootScope.itemsTop).toEqualListContent(elementTop);
416+
expect($rootScope.itemsBottom).toEqualListContent(elementBottom);
377417

378418
li1 = elementTop.find(':eq(0)');
379419
li2 = elementBottom.find(':eq(0)');
380420
dy = EXTRA_DY_PERCENTAGE * li1.outerHeight() + (li2.position().top - li1.position().top);
381421
li1.simulate('drag', { dy: dy });
382422
expect($rootScope.itemsTop).toEqual(["Top Two", "Top Three"]);
383423
expect($rootScope.itemsBottom).toEqual(["Bottom One", "Top One", "Bottom Two", "Bottom Three"]);
424+
expect($rootScope.itemsTop).toEqualListContent(elementTop);
425+
expect($rootScope.itemsBottom).toEqualListContent(elementBottom);
384426

385427
li1 = elementBottom.find(':eq(1)');
386428
li2 = elementTop.find(':eq(1)');
387429
dy = -EXTRA_DY_PERCENTAGE * li1.outerHeight() - (li1.position().top - li2.position().top);
388430
li1.simulate('drag', { dy: dy });
389431
expect($rootScope.itemsTop).toEqual(["Top Two", "Top One", "Top Three"]);
390432
expect($rootScope.itemsBottom).toEqual(["Bottom One", "Bottom Two", "Bottom Three"]);
433+
expect($rootScope.itemsTop).toEqualListContent(elementTop);
434+
expect($rootScope.itemsBottom).toEqualListContent(elementBottom);
391435

392436
$(elementTop).remove();
393437
$(elementBottom).remove();
@@ -416,7 +460,8 @@ describe('uiSortable', function() {
416460
li.simulate('drag', { dy: dy });
417461
expect($rootScope.items).toEqual(["One", "Three", "Two"]);
418462
expect($rootScope.logs).toEqual(["Moved element Two"]);
419-
expect(logsElement.find('li').html()).toEqual("Moved element Two");
463+
expect($rootScope.items).toEqualListContent(element);
464+
expect($rootScope.logs).toEqualListContent(logsElement);
420465

421466
$(element).remove();
422467
$(logsElement).remove();
@@ -446,7 +491,8 @@ describe('uiSortable', function() {
446491
li.simulate('drag', { dy: dy });
447492
expect($rootScope.items).toEqual(["One", "Three", "Two"]);
448493
expect($rootScope.logs).toEqual(["Moved element Two"]);
449-
expect(logsElement.find('li').html()).toEqual("Moved element Two");
494+
expect($rootScope.items).toEqualListContent(element);
495+
expect($rootScope.logs).toEqualListContent(logsElement);
450496

451497
$(element).remove();
452498
$(logsElement).remove();

0 commit comments

Comments
 (0)