@@ -26,13 +26,12 @@ define(
26
26
function ( MCTDevice ) {
27
27
"use strict" ;
28
28
29
- var JQLITE_METHODS = [ 'parent' , 'append ' ] ;
29
+ var JQLITE_METHODS = [ 'replaceWith ' ] ;
30
30
31
31
describe ( "The mct-device directive" , function ( ) {
32
32
var mockAgentService ,
33
33
mockTransclude ,
34
34
mockElement ,
35
- mockParent ,
36
35
mockClone ,
37
36
testAttrs ,
38
37
directive ;
@@ -48,11 +47,8 @@ define(
48
47
) ;
49
48
mockTransclude = jasmine . createSpy ( "$transclude" ) ;
50
49
mockElement = jasmine . createSpyObj ( name , JQLITE_METHODS ) ;
51
- mockParent = jasmine . createSpyObj ( name , JQLITE_METHODS ) ;
52
50
mockClone = jasmine . createSpyObj ( name , JQLITE_METHODS ) ;
53
51
54
- mockElement . parent . andReturn ( mockParent ) ;
55
-
56
52
mockTransclude . andCallFake ( function ( fn ) {
57
53
fn ( mockClone ) ;
58
54
} ) ;
@@ -65,6 +61,15 @@ define(
65
61
directive = new MCTDevice ( mockAgentService ) ;
66
62
} ) ;
67
63
64
+ function expectInclusion ( ) {
65
+ expect ( mockElement . replaceWith )
66
+ . toHaveBeenCalledWith ( mockClone ) ;
67
+ }
68
+
69
+ function expectExclusion ( ) {
70
+ expect ( mockElement . replaceWith ) . not . toHaveBeenCalled ( ) ;
71
+ }
72
+
68
73
it ( "is applicable at the attribute level" , function ( ) {
69
74
expect ( directive . restrict ) . toEqual ( "A" ) ;
70
75
} ) ;
@@ -80,66 +85,66 @@ define(
80
85
it ( "restricts element inclusion for mobile devices" , function ( ) {
81
86
testAttrs . mctDevice = "mobile" ;
82
87
link ( ) ;
83
- expect ( mockParent . append ) . not . toHaveBeenCalled ( ) ;
88
+ expectExclusion ( ) ;
84
89
85
90
mockAgentService . isMobile . andReturn ( true ) ;
86
91
link ( ) ;
87
- expect ( mockParent . append ) . toHaveBeenCalledWith ( mockClone ) ;
92
+ expectInclusion ( ) ;
88
93
} ) ;
89
94
90
95
it ( "restricts element inclusion for tablet devices" , function ( ) {
91
96
testAttrs . mctDevice = "tablet" ;
92
97
mockAgentService . isMobile . andReturn ( true ) ;
93
98
link ( ) ;
94
- expect ( mockParent . append ) . not . toHaveBeenCalled ( ) ;
99
+ expectExclusion ( ) ;
95
100
96
101
mockAgentService . isTablet . andReturn ( true ) ;
97
102
link ( ) ;
98
- expect ( mockParent . append ) . toHaveBeenCalledWith ( mockClone ) ;
103
+ expectInclusion ( ) ;
99
104
} ) ;
100
105
101
106
it ( "restricts element inclusion for phone devices" , function ( ) {
102
107
testAttrs . mctDevice = "phone" ;
103
108
mockAgentService . isMobile . andReturn ( true ) ;
104
109
link ( ) ;
105
- expect ( mockParent . append ) . not . toHaveBeenCalled ( ) ;
110
+ expectExclusion ( ) ;
106
111
107
112
mockAgentService . isPhone . andReturn ( true ) ;
108
113
link ( ) ;
109
- expect ( mockParent . append ) . toHaveBeenCalledWith ( mockClone ) ;
114
+ expectInclusion ( ) ;
110
115
} ) ;
111
116
112
117
it ( "restricts element inclusion for desktop devices" , function ( ) {
113
118
testAttrs . mctDevice = "desktop" ;
114
119
mockAgentService . isMobile . andReturn ( true ) ;
115
120
link ( ) ;
116
- expect ( mockParent . append ) . not . toHaveBeenCalled ( ) ;
121
+ expectExclusion ( ) ;
117
122
118
123
mockAgentService . isMobile . andReturn ( false ) ;
119
124
link ( ) ;
120
- expect ( mockParent . append ) . toHaveBeenCalledWith ( mockClone ) ;
125
+ expectInclusion ( ) ;
121
126
} ) ;
122
127
123
128
it ( "restricts element inclusion for portrait orientation" , function ( ) {
124
129
testAttrs . mctDevice = "portrait" ;
125
130
link ( ) ;
126
- expect ( mockParent . append ) . not . toHaveBeenCalled ( ) ;
131
+ expectExclusion ( ) ;
127
132
128
133
mockAgentService . isPortrait . andReturn ( true ) ;
129
134
link ( ) ;
130
- expect ( mockParent . append ) . toHaveBeenCalledWith ( mockClone ) ;
135
+ expectInclusion ( ) ;
131
136
} ) ;
132
137
133
138
it ( "restricts element inclusion for landscape orientation" , function ( ) {
134
139
testAttrs . mctDevice = "landscape" ;
135
140
mockAgentService . isLandscape . andReturn ( false ) ;
136
141
mockAgentService . isPortrait . andReturn ( true ) ;
137
142
link ( ) ;
138
- expect ( mockParent . append ) . not . toHaveBeenCalled ( ) ;
143
+ expectExclusion ( ) ;
139
144
140
145
mockAgentService . isLandscape . andReturn ( true ) ;
141
146
link ( ) ;
142
- expect ( mockParent . append ) . toHaveBeenCalledWith ( mockClone ) ;
147
+ expectInclusion ( ) ;
143
148
} ) ;
144
149
145
150
it ( "allows multiple device characteristics to be requested" , function ( ) {
@@ -148,17 +153,17 @@ define(
148
153
testAttrs . mctDevice = "portrait mobile" ;
149
154
link ( ) ;
150
155
// Neither portrait nor mobile, not called
151
- expect ( mockParent . append ) . not . toHaveBeenCalled ( ) ;
156
+ expectExclusion ( ) ;
152
157
153
158
mockAgentService . isPortrait . andReturn ( true ) ;
154
159
link ( ) ;
155
160
156
161
// Was portrait, but not mobile, so no
157
- expect ( mockParent . append ) . not . toHaveBeenCalled ( ) ;
162
+ expectExclusion ( ) ;
158
163
159
164
mockAgentService . isMobile . andReturn ( true ) ;
160
165
link ( ) ;
161
- expect ( mockParent . append ) . toHaveBeenCalledWith ( mockClone ) ;
166
+ expectInclusion ( ) ;
162
167
} ) ;
163
168
} ) ;
164
169
}
0 commit comments