-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntegrationExample.test.js
More file actions
201 lines (165 loc) · 7.9 KB
/
Copy pathIntegrationExample.test.js
File metadata and controls
201 lines (165 loc) · 7.9 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
200
201
describe('Testing scopes', function() {
"use strict";
var $rootScope, $scope, $compile, element, Inspector, Monitor;
var compileTpl = function(tpl,scope) {
var el = $compile(tpl)(scope);
scope.$digest();
return el;
};
beforeEach(module('integration-example'));
beforeEach(module('scope-aware'));
beforeEach(inject(function(_$rootScope_, _$compile_, _Inspector_, _Monitor_) {
$rootScope = _$rootScope_;
$compile = _$compile_;
$scope = $rootScope.$new();
var tpl = '<div id="main" ng-controller="MainCtrl" class="mainctrl">' +
' <h1>1. {{name}}</h1>' +
' Give me a name: <input ng-model="name">' +
' Set the default category: <input ng-model="category">' +
' <ul>' +
' <li ng-repeat="itm in items">' +
' {{itm.val}}' +
' <data-marker data-category="{{itm.val}}"></data-marker>' +
' </li> ' +
' </ul>' +
' ' +
' <div ng-controller="SubCtrl" class="subctrl">' +
' <h2>2. {{name}}</h2>' +
' Give me a name: <input ng-model="name">' +
' <ul>' +
' <li ng-repeat="itm in items">' +
' {{itm.val}}' +
' <data-marker data-category="{{itm.val}}"></data-marker>' +
' <data-shared-marker></data-shared-marker>' +
' <section class="inline" ng-include=" \'objects.form\' "></section>' +
' </li> ' +
' </ul>' +
' ' +
' <div ng-controller="SubSubCtrl" class="subsubctrl">' +
' <h3>3. {{name}}</h3>' +
' Give me a name: <input ng-model="name">' +
' <ul>' +
' <li ng-repeat="itm in items">' +
' {{itm}}' +
' <section class="inline" ng-include=" \'primitives.form\' "></section>' +
' </li> ' +
' </ul>' +
' </div>' +
' </div>' +
'</div>';
element = compileTpl(tpl,$scope);
Inspector = _Inspector_;
Monitor = _Monitor_;
}));
describe('integration-example model', function() {
var mainctrlElement, mainctrlScope,
subctrlElement, subctrlScope,
subsubctrlElement, subsubctrlScope;
beforeEach(function() {
mainctrlElement = element;
mainctrlScope = element.scope();
subctrlElement = angular.element(element.find('div')[0]);
subctrlScope = subctrlElement.scope();
subsubctrlElement = angular.element(element.find('div')[1]);
subsubctrlScope = subsubctrlElement.scope();
});
describe('controller model', function() {
it('inherits name prototypally', function() {
mainctrlScope.name = 'New name given by MainCtrl';
expect(subctrlScope).toHaveInheritedMembers('name');
expect(subctrlScope).toPossiblyShadow('name');
expect(subctrlScope.name).toEqual(mainctrlScope.name);
});
it('shadows name of the parent controller because it\'s a string', function() {
subctrlScope.name = 'New name given by SubCtrl';
expect(mainctrlScope.name).toEqual('MainCtrl');
expect(subctrlScope).toHaveMembers('name');
expect(subctrlScope).not.toHaveInheritedMembers('name');
expect(subctrlScope).toShadow('name');
});
});
describe('marker directive model', function() {
var markerScope;
beforeEach(function() {
markerScope = angular.element(element.find('data-marker')[0]).isolateScope();
});
it('has isolate scope', function() {
expect(markerScope).toHaveMembers('category');
expect(markerScope).not.toHaveInheritedMembers('name');
});
it('doesn\'t shadow the category of the parent', function() {
markerScope.$parent.category = 'Any category';
markerScope.category = 'C';
expect(markerScope.$parent.category).toEqual('Any category');
expect(markerScope.category).toEqual('C');
expect(markerScope).not.toShadow('category');
});
});
describe('shared marker directive model', function() {
var sharedMarkerElement, sharedMarkerScope, liParentScope;
beforeEach(function() {
sharedMarkerElement = angular.element(element.find('data-shared-marker')[0]);
sharedMarkerScope = sharedMarkerElement.scope();
liParentScope = sharedMarkerElement.parent().scope();
});
it('has shared scope', function() {
expect(sharedMarkerScope).toHaveMembers('name', 'items', 'itm');
});
it('clobbers the members of the parent', function() {
sharedMarkerScope.name = 'Name changed by shared directive';
expect(liParentScope.name).toEqual(sharedMarkerScope.name);
});
it('shows the category value if category is somewhere in the parent scope chain', function() {
expect(sharedMarkerElement.text()).toMatch(new RegExp('^unknown', 'g'));
//get the input <input ng-model="category">
var inputCategory = element.find('input')[1];
angular.element(inputCategory).val('A').triggerHandler('input');
$scope.$digest();
expect(sharedMarkerElement.text()).toEqual('very high');
});
});
describe('ng-include model inside SubCtrl', function() {
var includeElement, includeScope;
beforeEach(function() {
includeElement = angular.element(subctrlElement.find('section')[0]);
includeScope = includeElement.scope();
});
it('inherits values prototypally', function() {
expect(includeScope).toHaveInheritedMembers('name', 'itm', 'items');
expect(includeScope).toPossiblyShadow('name');
expect(includeScope).not.toPossiblyShadow('itm', 'items');
});
it('doesn\'t shadow the itm', function() {
expect(includeScope.itm.val).toEqual('D');
angular.element(includeElement.find('input')).val('A').triggerHandler('input');
$scope.$digest();
expect(includeScope.itm.val).toEqual('A');
expect(includeScope).not.toShadow('itm');
});
});
describe('ng-include model inside SubSubCtrl', function() {
var includeElement, includeScope;
beforeEach(function() {
includeElement = angular.element(subsubctrlElement.find('section')[0]);
includeScope = includeElement.scope();
});
it('inherits values prototypally', function() {
expect(includeScope).toHaveInheritedMembers('name', 'itm', 'items');
expect(includeScope).toPossiblyShadow('name', 'itm');
expect(includeScope).not.toPossiblyShadow('items');
});
it('shadows the itm', function() {
var stat = {running : false};
Monitor.monitor($rootScope, stat);
stat.running = false;
expect(includeScope.itm).toEqual('A');
angular.element(includeElement.find('input')).val('C').triggerHandler('input');
$scope.$digest();
expect(includeScope.itm).toEqual('C');
expect(includeScope.$parent.itm).toEqual('A');
expect(includeScope).toShadow('itm');
Monitor.monitor($rootScope, stat);
});
});
});
});