This repository has been archived by the owner on Jul 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
off-canvas.spec.js
114 lines (99 loc) · 3.19 KB
/
off-canvas.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
111
112
113
114
describe('cnOffCanvas', function() {
var cnOffCanvas,
rootScope,
container;
beforeEach(module('cn.offCanvas'));
beforeEach(inject(function(_cnOffCanvas_, $rootScope, $templateCache) {
cnOffCanvas = _cnOffCanvas_;
rootScope = $rootScope;
rootScope.foo = 'foo';
$templateCache.put('test.html', [200, '<div>{{foo}}</div>', {}]);
container = angular.element('<div></div>');
}));
afterEach(function() {
container = null;
});
describe('#init', function() {
it('should be closed initially', function() {
var offCanvas = cnOffCanvas({
templateUrl: 'test.html',
container: container
});
expect(offCanvas.isOpened).toBeFalsy();
});
it('should load content of navigation', function() {
cnOffCanvas({
templateUrl: 'test.html',
container: container
});
rootScope.$digest();
expect(container.text()).toBe('foo');
});
it('should throw if called without a `template` or `templateUrl` options', function() {
expect(function() { cnOffCanvas({}) }).toThrow(new Error('You must specify either a `template` or a `templateUrl` to create an off-canvas navigation.'));
});
it('should throw if called with both `template` and `templateUrl` options', function() {
expect(function() {
cnOffCanvas({
template: '<div></div>',
templateUrl: 'test.html'
});
}).toThrow();
});
it('should instantiate a controller via `controller` option', function() {
cnOffCanvas({
templateUrl: 'test.html',
controller: function($scope) {
$scope.foo = 'bar';
},
container: container
});
rootScope.$digest();
expect(container.text()).toBe('bar');
});
it('should instantiate expose a controller to the scope via the `controllerAs` option', function() {
cnOffCanvas({
template: '<div>{{ctrl.foo}}</div>',
controller: function() {
this.foo = 'bar';
},
controllerAs: 'ctrl',
container: container
});
rootScope.$digest();
expect(container.text()).toBe('bar');
});
});
describe('#toggle', function() {
var offCanvas;
beforeEach(function() {
offCanvas = cnOffCanvas({
templateUrl: 'test.html',
container: container
});
})
it('should open the off-canvas nav', function() {
offCanvas.toggle();
expect(offCanvas.isOpened).toBeTruthy();
});
it('should close the off-canvas nav', function() {
offCanvas.toggle();
expect(offCanvas.isOpened).toBeTruthy();
offCanvas.toggle();
expect(offCanvas.isOpened).toBeFalsy();
});
it('should toggle `is-off-canvas-opened` class to the container by default', function() {
offCanvas.toggle();
expect(container.hasClass('is-off-canvas-opened')).toBeTruthy();
});
it('should toggle a configurable class via `containerClass` option', function() {
offCanvas = cnOffCanvas({
templateUrl: 'test.html',
container: container,
containerClass: 'is-opened-nav'
});
offCanvas.toggle();
expect(container.hasClass('is-opened-nav')).toBeTruthy();
});
});
});