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

Commit d4de3ff

Browse files
thgreasidouglasduteil
authored andcommitted
Added DOM checks for each model test.
1 parent cf3b6c4 commit d4de3ff

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

test/sortable.spec.js

+49-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ 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+
console.log(list.children().map(function(){ return this.innerHTML; }).toArray());
11+
return list.children().map(function(){ return this.innerHTML; }).toArray();
12+
}
13+
return [];
14+
}
15+
});
16+
});
17+
618
var EXTRA_DY_PERCENTAGE = 0.25;
719

820
describe('Simple use', function() {
@@ -60,11 +72,13 @@ describe('uiSortable', function() {
6072
var dy = (1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
6173
li.simulate('drag', { dy: dy });
6274
expect($rootScope.items).toEqual(["One", "Three", "Two"]);
75+
expect($rootScope.items).toEqualListContent(element);
6376

6477
li = element.find(':eq(1)');
6578
dy = -(1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
6679
li.simulate('drag', { dy: dy });
6780
expect($rootScope.items).toEqual(["Three", "One", "Two"]);
81+
expect($rootScope.items).toEqualListContent(element);
6882

6983
$(element).remove();
7084
});
@@ -92,21 +106,25 @@ describe('uiSortable', function() {
92106
var dy = (1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
93107
li.simulate('drag', { dy: dy });
94108
expect($rootScope.items.map(function(x){ return x.text; })).toEqual(["One", "Two", "Three", "Four"]);
109+
expect($rootScope.items.map(function(x){ return x.text; })).toEqualListContent(element);
95110

96111
li = element.find(':eq(1)');
97112
dy = (2 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
98113
li.simulate('drag', { dy: dy });
99114
expect($rootScope.items.map(function(x){ return x.text; })).toEqual(["One", "Three", "Four", "Two"]);
115+
expect($rootScope.items.map(function(x){ return x.text; })).toEqualListContent(element);
100116

101117
li = element.find(':eq(2)');
102118
dy = -(2 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
103119
li.simulate('drag', { dy: dy });
104120
expect($rootScope.items.map(function(x){ return x.text; })).toEqual(["Four", "One", "Three", "Two"]);
121+
expect($rootScope.items.map(function(x){ return x.text; })).toEqualListContent(element);
105122

106123
li = element.find(':eq(3)');
107124
dy = -(2 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
108125
li.simulate('drag', { dy: dy });
109126
expect($rootScope.items.map(function(x){ return x.text; })).toEqual(["Four", "Two", "One", "Three"]);
127+
expect($rootScope.items.map(function(x){ return x.text; })).toEqualListContent(element);
110128

111129
// also placing right above the locked node seems a bit harder !?!?
112130

@@ -131,11 +149,13 @@ describe('uiSortable', function() {
131149
var dy = (1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
132150
li.simulate('drag', { dy: dy });
133151
expect($rootScope.items).toEqual(["One", "Three", "Two"]);
152+
expect($rootScope.items).toEqualListContent(element);
134153

135154
li = element.find(':eq(1)');
136155
dy = -(1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
137156
li.simulate('drag', { dy: dy });
138157
expect($rootScope.items).toEqual(["Three", "One", "Two"]);
158+
expect($rootScope.items).toEqualListContent(element);
139159

140160
$(element).remove();
141161
});
@@ -158,11 +178,13 @@ describe('uiSortable', function() {
158178
var dy = (1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
159179
li.simulate('drag', { dy: dy });
160180
expect($rootScope.items).toEqual(["One", "Three", "Two"]);
181+
expect($rootScope.items).toEqualListContent(element);
161182

162183
li = element.find(':eq(1)');
163184
dy = -(1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
164185
li.simulate('drag', { dy: dy });
165186
expect($rootScope.items).toEqual(["Three", "One", "Two"]);
187+
expect($rootScope.items).toEqualListContent(element);
166188

167189
$(element).remove();
168190
});
@@ -203,13 +225,17 @@ describe('uiSortable', function() {
203225
li1.simulate('drag', { dy: dy });
204226
expect($rootScope.itemsTop).toEqual(["Top Two", "Top Three"]);
205227
expect($rootScope.itemsBottom).toEqual(["Bottom One", "Top One", "Bottom Two", "Bottom Three"]);
228+
expect($rootScope.itemsTop).toEqualListContent(elementTop);
229+
expect($rootScope.itemsBottom).toEqualListContent(elementBottom);
206230

207231
li1 = elementBottom.find(':eq(1)');
208232
li2 = elementTop.find(':eq(1)');
209233
dy = -EXTRA_DY_PERCENTAGE * li1.outerHeight() - (li1.position().top - li2.position().top);
210234
li1.simulate('drag', { dy: dy });
211235
expect($rootScope.itemsTop).toEqual(["Top Two", "Top One", "Top Three"]);
212236
expect($rootScope.itemsBottom).toEqual(["Bottom One", "Bottom Two", "Bottom Three"]);
237+
expect($rootScope.itemsTop).toEqualListContent(elementTop);
238+
expect($rootScope.itemsBottom).toEqualListContent(elementBottom);
213239

214240
$(elementTop).remove();
215241
$(elementBottom).remove();
@@ -238,13 +264,17 @@ describe('uiSortable', function() {
238264
li1.simulate('drag', { dy: dy });
239265
expect($rootScope.itemsTop).toEqual(["Top Two", "Top Three"]);
240266
expect($rootScope.itemsBottom).toEqual(["Bottom One", "Top One", "Bottom Two", "Bottom Three"]);
267+
expect($rootScope.itemsTop).toEqualListContent(elementTop);
268+
expect($rootScope.itemsBottom).toEqualListContent(elementBottom);
241269

242270
li1 = elementBottom.find(':eq(1)');
243271
li2 = elementTop.find(':eq(1)');
244272
dy = -EXTRA_DY_PERCENTAGE * li1.outerHeight() - (li1.position().top - li2.position().top);
245273
li1.simulate('drag', { dy: dy });
246274
expect($rootScope.itemsTop).toEqual(["Top Two", "Top One", "Top Three"]);
247275
expect($rootScope.itemsBottom).toEqual(["Bottom One", "Bottom Two", "Bottom Three"]);
276+
expect($rootScope.itemsTop).toEqualListContent(elementTop);
277+
expect($rootScope.itemsBottom).toEqualListContent(elementBottom);
248278

249279
$(elementTop).remove();
250280
$(elementBottom).remove();
@@ -273,13 +303,17 @@ describe('uiSortable', function() {
273303
li1.simulate('drag', { dy: dy });
274304
expect($rootScope.itemsTop).toEqual(["Top Two", "Top Three"]);
275305
expect($rootScope.itemsBottom).toEqual(["Bottom One", "Top One", "Bottom Two", "Bottom Three"]);
306+
expect($rootScope.itemsTop).toEqualListContent(elementTop);
307+
expect($rootScope.itemsBottom).toEqualListContent(elementBottom);
276308

277309
li1 = elementBottom.find(':eq(1)');
278310
li2 = elementTop.find(':eq(1)');
279311
dy = -EXTRA_DY_PERCENTAGE * li1.outerHeight() - (li1.position().top - li2.position().top);
280312
li1.simulate('drag', { dy: dy });
281313
expect($rootScope.itemsTop).toEqual(["Top Two", "Top One", "Top Three"]);
282314
expect($rootScope.itemsBottom).toEqual(["Bottom One", "Bottom Two", "Bottom Three"]);
315+
expect($rootScope.itemsTop).toEqualListContent(elementTop);
316+
expect($rootScope.itemsBottom).toEqualListContent(elementBottom);
283317

284318
$(elementTop).remove();
285319
$(elementBottom).remove();
@@ -324,16 +358,19 @@ describe('uiSortable', function() {
324358
var dy = (1 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
325359
li.simulate('drag', { dy: dy });
326360
expect($rootScope.items).toEqual(["One", "Two", "Three"]);
361+
expect($rootScope.items).toEqualListContent(element);
327362

328363
li = element.find(':eq(0)');
329364
dy = (2 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
330365
li.simulate('drag', { dy: dy });
331366
expect($rootScope.items).toEqual(["Two", "Three", "One"]);
367+
expect($rootScope.items).toEqualListContent(element);
332368

333369
li = element.find(':eq(2)');
334370
dy = -(2 + EXTRA_DY_PERCENTAGE) * li.outerHeight();
335371
li.simulate('drag', { dy: dy });
336372
expect($rootScope.items).toEqual(["One", "Two", "Three"]);
373+
expect($rootScope.items).toEqualListContent(element);
337374

338375
$(element).remove();
339376
});
@@ -367,27 +404,35 @@ describe('uiSortable', function() {
367404
li1.simulate('drag', { dy: dy });
368405
expect($rootScope.itemsTop).toEqual(["Top One", "Top Two", "Top Three"]);
369406
expect($rootScope.itemsBottom).toEqual(["Bottom One", "Bottom Two", "Bottom Three"]);
407+
expect($rootScope.itemsTop).toEqualListContent(elementTop);
408+
expect($rootScope.itemsBottom).toEqualListContent(elementBottom);
370409

371410
li1 = elementBottom.find(':eq(1)');
372411
li2 = elementTop.find(':eq(1)');
373412
dy = -EXTRA_DY_PERCENTAGE * li1.outerHeight() - (li1.position().top - li2.position().top);
374413
li1.simulate('drag', { dy: dy });
375414
expect($rootScope.itemsTop).toEqual(["Top One", "Top Two", "Top Three"]);
376415
expect($rootScope.itemsBottom).toEqual(["Bottom One", "Bottom Two", "Bottom Three"]);
416+
expect($rootScope.itemsTop).toEqualListContent(elementTop);
417+
expect($rootScope.itemsBottom).toEqualListContent(elementBottom);
377418

378419
li1 = elementTop.find(':eq(0)');
379420
li2 = elementBottom.find(':eq(0)');
380421
dy = EXTRA_DY_PERCENTAGE * li1.outerHeight() + (li2.position().top - li1.position().top);
381422
li1.simulate('drag', { dy: dy });
382423
expect($rootScope.itemsTop).toEqual(["Top Two", "Top Three"]);
383424
expect($rootScope.itemsBottom).toEqual(["Bottom One", "Top One", "Bottom Two", "Bottom Three"]);
425+
expect($rootScope.itemsTop).toEqualListContent(elementTop);
426+
expect($rootScope.itemsBottom).toEqualListContent(elementBottom);
384427

385428
li1 = elementBottom.find(':eq(1)');
386429
li2 = elementTop.find(':eq(1)');
387430
dy = -EXTRA_DY_PERCENTAGE * li1.outerHeight() - (li1.position().top - li2.position().top);
388431
li1.simulate('drag', { dy: dy });
389432
expect($rootScope.itemsTop).toEqual(["Top Two", "Top One", "Top Three"]);
390433
expect($rootScope.itemsBottom).toEqual(["Bottom One", "Bottom Two", "Bottom Three"]);
434+
expect($rootScope.itemsTop).toEqualListContent(elementTop);
435+
expect($rootScope.itemsBottom).toEqualListContent(elementBottom);
391436

392437
$(elementTop).remove();
393438
$(elementBottom).remove();
@@ -416,7 +461,8 @@ describe('uiSortable', function() {
416461
li.simulate('drag', { dy: dy });
417462
expect($rootScope.items).toEqual(["One", "Three", "Two"]);
418463
expect($rootScope.logs).toEqual(["Moved element Two"]);
419-
expect(logsElement.find('li').html()).toEqual("Moved element Two");
464+
expect($rootScope.items).toEqualListContent(element);
465+
expect($rootScope.logs).toEqualListContent(logsElement);
420466

421467
$(element).remove();
422468
$(logsElement).remove();
@@ -446,7 +492,8 @@ describe('uiSortable', function() {
446492
li.simulate('drag', { dy: dy });
447493
expect($rootScope.items).toEqual(["One", "Three", "Two"]);
448494
expect($rootScope.logs).toEqual(["Moved element Two"]);
449-
expect(logsElement.find('li').html()).toEqual("Moved element Two");
495+
expect($rootScope.items).toEqualListContent(element);
496+
expect($rootScope.logs).toEqualListContent(logsElement);
450497

451498
$(element).remove();
452499
$(logsElement).remove();

0 commit comments

Comments
 (0)