forked from dwmkerr/angular-modal-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.spec.js
110 lines (80 loc) · 3.06 KB
/
template.spec.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
describe('template', () => {
var ModalService = null;
var rootScope = null;
var $httpBackend = null;
angular.module('templatetests', ['angularModalService'])
.controller('TemplateController', ($scope) => {
});
beforeEach(() => {
angular.mock.module('templatetests');
inject((_ModalService_, $rootScope, $injector) => {
ModalService = _ModalService_;
rootScope = $rootScope;
$httpBackend = $injector.get('$httpBackend');
$httpBackend.when('GET', 'some/template.html').respond("<div>template</div>");
$httpBackend.when('GET', 'some/invalid/template.html').respond(404, 'Not Found');
});
});
afterEach(inject(function($templateCache) {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
$templateCache.removeAll();
}));
it('should http get the specified template url', function() {
$httpBackend.expectGET('some/template.html');
ModalService.showModal({
controller: "TemplateController",
templateUrl: "some/template.html"
}).then(function(modal) {
expect(modal).not.toBe(null);
});
$httpBackend.flush();
});
it('should fail to get an invalid template url', function() {
ModalService.showModal({
controller: "TemplateController",
templateUrl: "some/invalid/template.html"
}).then(function(modal) {
}).catch(function(error) {
expect(error).not.toBe(null);
});
$httpBackend.flush();
});
it('should use the template cache for subsequent requests for the same template',
inject(function($templateCache) {
$httpBackend.expectGET('templatetobecached.html').respond('<div>template</div>');
ModalService.showModal({
controller: "TemplateController",
templateUrl: "templatetobecached.html"
}).then(function(modal) {
// The template should now be cached...
spyOn($templateCache, 'get').and.callThrough();
ModalService.showModal({
controller: "TemplateController",
templateUrl: "templatetobecached.html"
}).then(function(modal) {
// ...so get should have been called.
expect(modal).not.toBe(null);
expect($templateCache.get).toHaveBeenCalledWith('templatetobecached.html');
});
});
$httpBackend.flush();
}));
it('should use the template cache correctly if the template is precached',
inject(function($templateCache, $http) {
$httpBackend.expectGET('templatetobeprecached.html').respond('<div>template</div>');
// Fetch the template (i.e. precache).
$http.get('templatetobeprecached.html', {cache: $templateCache});
// The template should now be cached...
spyOn($templateCache, 'get').and.callThrough();
ModalService.showModal({
controller: "TemplateController",
templateUrl: "templatetobeprecached.html"
}).then(function(modal) {
// ...so get should have been called.
expect(modal).not.toBe(null);
expect($templateCache.get).toHaveBeenCalledWith('templatetobeprecached.html');
});
$httpBackend.flush();
}));
});