1
+ 'use strict' ;
2
+
3
+ describe ( 'uiSortable' , function ( ) {
4
+
5
+ // Ensure the sortable angular module is loaded
6
+ beforeEach ( module ( 'ui.sortable' ) ) ;
7
+ beforeEach ( module ( 'ui.sortable.testHelper' ) ) ;
8
+ beforeEach ( module ( 'ui.sortable.testDirectives' ) ) ;
9
+
10
+ var EXTRA_DY_PERCENTAGE , listContent , listInnerContent ;
11
+
12
+ beforeEach ( inject ( function ( sortableTestHelper ) {
13
+ EXTRA_DY_PERCENTAGE = sortableTestHelper . EXTRA_DY_PERCENTAGE ;
14
+ listContent = sortableTestHelper . listContent ;
15
+ listInnerContent = sortableTestHelper . listInnerContent ;
16
+ } ) ) ;
17
+
18
+ describe ( 'Inner directives related' , function ( ) {
19
+
20
+ var host ;
21
+
22
+ beforeEach ( inject ( function ( ) {
23
+ host = $ ( '<div id="test-host"></div>' ) ;
24
+ $ ( 'body' ) . append ( host ) ;
25
+ } ) ) ;
26
+
27
+ afterEach ( function ( ) {
28
+ host . remove ( ) ;
29
+ host = null ;
30
+ } ) ;
31
+
32
+ it ( 'should work when inner directives are used' , function ( ) {
33
+ inject ( function ( $compile , $rootScope ) {
34
+ var element ;
35
+ element = $compile ( '' . concat (
36
+ '<ul ui-sortable="opts" ng-model="items">' ,
37
+ '<li ng-repeat="item in items" id="s-{{$index}}" class="sortable-item">' ,
38
+ '<ui-sortable-simple-test-directive ng-model="item"></ui-sortable-simple-test-directive>' ,
39
+ '</li>' ,
40
+ '</ul>' ) ) ( $rootScope ) ;
41
+
42
+ $rootScope . $apply ( function ( ) {
43
+ $rootScope . opts = { } ;
44
+ $rootScope . items = [ 'One' , 'Two' , 'Three' ] ;
45
+ } ) ;
46
+
47
+ host . append ( element ) ;
48
+
49
+ var li = element . find ( '> :eq(1)' ) ;
50
+ var dy = ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
51
+ li . simulate ( 'drag' , { dy : dy } ) ;
52
+ expect ( $rootScope . items ) . toEqual ( [ 'One' , 'Three' , 'Two' ] ) ;
53
+ expect ( $rootScope . items ) . toEqual ( listInnerContent ( element ) ) ;
54
+
55
+ li = element . find ( '> :eq(1)' ) ;
56
+ dy = - ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
57
+ li . simulate ( 'drag' , { dy : dy } ) ;
58
+ expect ( $rootScope . items ) . toEqual ( [ 'Three' , 'One' , 'Two' ] ) ;
59
+ expect ( $rootScope . items ) . toEqual ( listInnerContent ( element ) ) ;
60
+
61
+ $ ( element ) . remove ( ) ;
62
+ } ) ;
63
+ } ) ;
64
+
65
+ it ( 'should not $destroy direcives after sorting.' , function ( ) {
66
+ inject ( function ( $compile , $rootScope ) {
67
+ var element ;
68
+ element = $compile ( '' . concat (
69
+ '<ul ui-sortable="opts" ng-model="items">' ,
70
+ '<li ng-repeat="item in items" id="s-{{$index}}" class="sortable-item">' ,
71
+ '<ui-sortable-destroyable-test-directive ng-model="item"></ui-sortable-destroyable-test-directive>' ,
72
+ '</li>' ,
73
+ '</ul>' ) ) ( $rootScope ) ;
74
+
75
+ $rootScope . $apply ( function ( ) {
76
+ $rootScope . opts = { } ;
77
+ $rootScope . items = [ 'One' , 'Two' , 'Three' ] ;
78
+ } ) ;
79
+
80
+ host . append ( element ) ;
81
+
82
+ var li = element . find ( '> :eq(1)' ) ;
83
+ var dy = ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
84
+ li . simulate ( 'drag' , { dy : dy } ) ;
85
+ expect ( $rootScope . items ) . toEqual ( [ 'One' , 'Three' , 'Two' ] ) ;
86
+ expect ( $rootScope . items ) . toEqual ( listInnerContent ( element ) ) ;
87
+
88
+ li = element . find ( '> :eq(1)' ) ;
89
+ dy = - ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
90
+ li . simulate ( 'drag' , { dy : dy } ) ;
91
+ expect ( $rootScope . items ) . toEqual ( [ 'Three' , 'One' , 'Two' ] ) ;
92
+ expect ( $rootScope . items ) . toEqual ( listInnerContent ( element ) ) ;
93
+
94
+ $ ( element ) . remove ( ) ;
95
+ } ) ;
96
+ } ) ;
97
+
98
+ } ) ;
99
+
100
+ } ) ;
0 commit comments