/
dialogs-services.tests.js
171 lines (138 loc) · 6.13 KB
/
dialogs-services.tests.js
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
describe('Module dialogs.services', function(){
var modalOptions = {
templateUrl : '',
controller : '',
backdrop: true,
backdropClass: "dialogs-backdrop-default",
keyboard: true,
windowClass: "dialogs-default",
size: 'lg',
animation: false,
resolve : {
data : jasmine.any(Function)
}
};
describe('Provider: dialogsProvider and Service: dialogs', function(){
var provider;
beforeEach(function(){
module('dialogs.services', function(dialogsProvider){
provider = dialogsProvider;
});
});
it('should open modal instance with default error params', inject(function($modal){
spyOn($modal, 'open');
var service = provider.$get[1]($modal).error();
errorModalOptions = modalOptions;
errorModalOptions.templateUrl = '/dialogs/error.html';
errorModalOptions.controller = 'errorDialogCtrl';
expect($modal.open).toHaveBeenCalled();
expect($modal.open).toHaveBeenCalledWith(errorModalOptions);
}));
it('should open modal instance with default wait params', inject(function($modal){
spyOn($modal, 'open');
var service = provider.$get[1]($modal).wait();
waitModalOptions = modalOptions;
waitModalOptions.templateUrl = '/dialogs/wait.html';
waitModalOptions.controller = 'waitDialogCtrl';
expect($modal.open).toHaveBeenCalled();
expect($modal.open).toHaveBeenCalledWith(waitModalOptions);
}));
it('should open modal instance with default notify params', inject(function($modal){
spyOn($modal, 'open');
var service = provider.$get[1]($modal).notify();
notifyModalOptions = modalOptions;
notifyModalOptions.templateUrl = '/dialogs/notify.html';
notifyModalOptions.controller = 'notifyDialogCtrl';
expect($modal.open).toHaveBeenCalled();
expect($modal.open).toHaveBeenCalledWith(notifyModalOptions);
}));
it('should open modal instance with default confirm params', inject(function($modal){
spyOn($modal, 'open');
var service = provider.$get[1]($modal).confirm();
confirmModalOptions = modalOptions;
confirmModalOptions.templateUrl = '/dialogs/confirm.html';
confirmModalOptions.controller = 'confirmDialogCtrl';
expect($modal.open).toHaveBeenCalled();
expect($modal.open).toHaveBeenCalledWith(confirmModalOptions);
}));
it('should open modal instance with default create params', inject(function($modal){
spyOn($modal, 'open');
createModalOptions = modalOptions;
createModalOptions.templateUrl = '/dialogs/create.html';
createModalOptions.controller = 'createDialogCtrl';
var service = provider.$get[1]($modal).create(
createModalOptions.templateUrl,
createModalOptions.controller
);
expect($modal.open).toHaveBeenCalled();
expect($modal.open).toHaveBeenCalledWith(jasmine.objectContaining(createModalOptions));
}));
it('should open modal with backdrop value from useBackdrop config', inject(function($modal){
provider.useBackdrop(false);
spyOn($modal, 'open');
var service = provider.$get[1]($modal).error();
errorModalOptions = angular.copy(modalOptions);
errorModalOptions.templateUrl = '/dialogs/error.html';
errorModalOptions.controller = 'errorDialogCtrl';
errorModalOptions.backdrop = false;
expect($modal.open).toHaveBeenCalled();
expect($modal.open).toHaveBeenCalledWith(errorModalOptions);
}));
it('should open modal with keyboard value from useEscClose config', inject(function($modal){
provider.useEscClose(false);
spyOn($modal, 'open');
var service = provider.$get[1]($modal).error();
errorModalOptions = angular.copy(modalOptions);
errorModalOptions.templateUrl = '/dialogs/error.html';
errorModalOptions.controller = 'errorDialogCtrl';
errorModalOptions.keyboard = false;
expect($modal.open).toHaveBeenCalled();
expect($modal.open).toHaveBeenCalledWith(errorModalOptions);
}));
it('should open modal with windowClass value from useClass config', inject(function($modal){
provider.useClass("some-class");
spyOn($modal, 'open');
var service = provider.$get[1]($modal).error();
errorModalOptions = angular.copy(modalOptions);
errorModalOptions.templateUrl = '/dialogs/error.html';
errorModalOptions.controller = 'errorDialogCtrl';
errorModalOptions.windowClass = "some-class";
expect($modal.open).toHaveBeenCalled();
expect($modal.open).toHaveBeenCalledWith(errorModalOptions);
}));
it('should copy data when opening create dialog when useCopy is true in config', inject(function($modal){
provider.useCopy(true);
spyOn(angular, 'copy');
createModalOptions = modalOptions;
createModalOptions.templateUrl = '/dialogs/create.html';
createModalOptions.controller = 'createDialogCtrl';
var service = provider.$get[1]($modal).create(
createModalOptions.templateUrl,
createModalOptions.controller
);
expect(angular.copy).toHaveBeenCalled();
}));
it('should open modal with size value from setSize config', inject(function($modal){
provider.setSize("md");
spyOn($modal, 'open');
var service = provider.$get[1]($modal).error();
errorModalOptions = angular.copy(modalOptions);
errorModalOptions.templateUrl = '/dialogs/error.html';
errorModalOptions.controller = 'errorDialogCtrl';
errorModalOptions.size = "md";
expect($modal.open).toHaveBeenCalled();
expect($modal.open).toHaveBeenCalledWith(errorModalOptions);
}));
it('should open modal with animation true when useAnimation config is executed', inject(function($modal){
provider.useAnimation();
spyOn($modal, 'open');
var service = provider.$get[1]($modal).error();
errorModalOptions = angular.copy(modalOptions);
errorModalOptions.templateUrl = '/dialogs/error.html';
errorModalOptions.controller = 'errorDialogCtrl';
errorModalOptions.animation = true;
expect($modal.open).toHaveBeenCalled();
expect($modal.open).toHaveBeenCalledWith(errorModalOptions);
}));
});
});