forked from btford/angular-modal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodal.spec.js
More file actions
199 lines (149 loc) · 4.6 KB
/
modal.spec.js
File metadata and controls
199 lines (149 loc) · 4.6 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
199
'use strict';
describe('btfModal', function() {
var btfModal,
container,
rootScope,
body = angular.element(window.document.body);
beforeEach(module('btford.modal'));
beforeEach(inject(function(_btfModal_, $rootScope, $templateCache, _$httpBackend_) {
btfModal = _btfModal_;
rootScope = $rootScope;
rootScope.greeting = 'こんばんは';
$templateCache.put('test.html', [200, '<div>{{greeting}}</div>', {}]);
container = angular.element('<div></div>');
}));
afterEach(function() {
container = null;
});
it('should not show a modal initially', function() {
var modal = btfModal({
templateUrl: 'test.html',
container: container
});
rootScope.$digest();
expect(container.text()).toBe('');
});
it('should throw if called without a `template` or `templateUrl` option', function() {
expect(function () { btfModal({}); }).toThrow();
});
it('should throw if called with both `template` and `templateUrl` options', function() {
expect(function () {
btfModal({
template: 'foo',
templateUrl: 'foo.html'
});
}).toThrow();
});
describe('#activate', function () {
it('should show a modal when activated with `templateUrl`', function() {
var modal = btfModal({
templateUrl: 'test.html',
container: container
});
modal.activate();
rootScope.$digest();
expect(container.text()).toBe('こんばんは');
});
it('should show a modal when activated with `template`', function() {
var modal = btfModal({
template: '<span>{{greeting}}</span>',
container: container
});
modal.activate();
rootScope.$digest();
expect(container.text()).toBe('こんばんは');
});
it('should instantiate a controller via the `controller` option', function() {
var modal = btfModal({
template: '<span>{{greeting}}</span>',
controller: function ($scope) {
$scope.greeting = 'goodnight'
},
container: container
});
modal.activate();
rootScope.$digest();
expect(container.text()).toBe('goodnight');
});
it('should expose a controller to the scope via the `controllerAs` option', function() {
var modal = btfModal({
template: '<span>{{ctrl.greeting}}</span>',
controller: function () {
this.greeting = 'boa noite'
},
controllerAs: 'ctrl',
container: container
});
modal.activate();
rootScope.$digest();
expect(container.text()).toBe('boa noite');
});
it('should pass locals to the modal scope', function() {
var modal = btfModal({
template: '<span>{{greeting}}</span>',
container: container
});
modal.activate({
greeting: 'bon soir'
});
rootScope.$digest();
expect(container.text()).toBe('bon soir');
});
it('should not activate multiple times', function() {
var modal = btfModal({
template: '<span>x</span>',
container: container
});
modal.activate();
rootScope.$digest();
modal.activate();
rootScope.$digest();
expect(container.text()).toBe('x');
});
});
describe('#deactivate', function () {
it('should remove a modal when deactivated', function() {
var modal = btfModal({
template: '<span>{{greeting}}</span>',
container: container
});
modal.activate();
rootScope.$digest();
modal.deactivate();
rootScope.$digest();
expect(container.text()).toBe('');
});
it('should destroy the scope when deactivated', function() {
var destroySpy = jasmine.createSpy('onDestroy');
var modal = btfModal({
template: '<span>{{greeting}}</span>',
container: container,
controller: function ($scope) {
$scope.$on('$destroy', destroySpy);
}
});
modal.activate();
rootScope.$digest();
expect(destroySpy).not.toHaveBeenCalled();
modal.deactivate();
rootScope.$digest();
expect(destroySpy).toHaveBeenCalled();
});
});
describe('#active', function () {
it('should return the state of the modal', function() {
var modal = btfModal({
template: '<span>{{greeting}}</span>',
container: container
});
rootScope.$digest();
expect(modal.active()).toBe(false);
modal.activate();
rootScope.$digest();
expect(modal.active()).toBe(true);
modal.deactivate();
rootScope.$digest();
expect(modal.active()).toBe(false);
});
});
});