Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 2f77095

Browse files
committed
fix(contact-chips): don't rely on debug info to get access to controller scope
- fix exception when `debugInfoEnabled(false)` is set - remove unused variables in tests - remove commented out and unused code in tests Fixes #11699
1 parent 5228f23 commit 2f77095

File tree

2 files changed

+2
-38
lines changed

2 files changed

+2
-38
lines changed

src/components/chips/contact-chips.spec.js

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('<md-contact-chips>', function() {
3535
}
3636
];
3737
scope.contacts = [];
38-
scope.keys = [$mdConstant.KEY_CODE.COMMA]
38+
scope.keys = [$mdConstant.KEY_CODE.COMMA];
3939

4040
scope.highlightFlags = 'i';
4141
}));
@@ -54,7 +54,6 @@ describe('<md-contact-chips>', function() {
5454
describe('basic functionality', function() {
5555
it('should show the placeholder', inject(function() {
5656
var element = buildChips(CONTACT_CHIPS_TEMPLATE);
57-
var ctrl = element.controller('mdContactChips');
5857

5958
expect(element.find('input').length).toBe(1);
6059
expect(element.find('input')[0].placeholder).toBe('To');
@@ -69,7 +68,6 @@ describe('<md-contact-chips>', function() {
6968

7069
it('should trigger ng-change on chip addition/removal', function() {
7170
var element = buildChips(CONTACT_CHIPS_TEMPLATE);
72-
var ctrl = element.controller('mdContactChips');
7371
var chipsElement = element.find('md-chips');
7472
var chipsCtrl = chipsElement.controller('mdChips');
7573

@@ -103,7 +101,6 @@ describe('<md-contact-chips>', function() {
103101
scope.contacts.push(scope.allContacts[2]);
104102

105103
var element = buildChips(CONTACT_CHIPS_TEMPLATE);
106-
var ctrl = element.controller('mdContactChips');
107104
var chip = angular.element(element[0].querySelector('.md-chip-content'));
108105

109106
expect(chip.find('img').length).toBe(1);
@@ -115,7 +112,6 @@ describe('<md-contact-chips>', function() {
115112
scope.contacts.push(noImageContact);
116113

117114
var element = buildChips(CONTACT_CHIPS_TEMPLATE);
118-
var ctrl = element.controller('mdContactChips');
119115
var chip = angular.element(element[0].querySelector('.md-chip-content'));
120116

121117
expect(chip.find('img').length).toBe(0);
@@ -138,7 +134,6 @@ describe('<md-contact-chips>', function() {
138134
scope.contacts.push(scope.allContacts[2]);
139135

140136
var element = buildChips(CONTACT_CHIPS_TEMPLATE);
141-
var ctrl = element.controller('mdContactChips');
142137

143138
var autocompleteElement = element.find('md-autocomplete');
144139
var autocompleteCtrl = autocompleteElement.controller('mdAutocomplete');
@@ -152,27 +147,6 @@ describe('<md-contact-chips>', function() {
152147
var matches = autocompleteCtrl.matches;
153148
expect(matches.length).toBe(3);
154149
}));
155-
156-
/* it('should not filter when disabled', inject(function($timeout) {
157-
scope.querySearch = jasmine.createSpy('querySearch').and.callFake(function(q) {
158-
return scope.allContacts;
159-
});
160-
scope.contacts.push(scope.allContacts[2]);
161-
scope.filterSelected = false;
162-
var element = buildChips(CONTACT_CHIPS_TEMPLATE);
163-
var ctrl = element.controller('mdContactChips');
164-
$timeout.flush();
165-
166-
var autocompleteElement = element.find('md-autocomplete');
167-
var autocompleteCtrl = autocompleteElement.controller('mdAutocomplete');
168-
element.scope().$apply(function() {
169-
autocompleteCtrl.scope.searchText = 'NAME';
170-
autocompleteCtrl.keydown({});
171-
});
172-
173-
var matches = autocompleteCtrl.matches;
174-
expect(matches.length).toBe(3);
175-
}));*/
176150
});
177151

178152
describe('custom separator keys', function() {
@@ -195,7 +169,6 @@ describe('<md-contact-chips>', function() {
195169

196170
var element = buildChips(CONTACT_CHIPS_TEMPLATE_SEPARATOR);
197171
var ctrl = element.controller('mdContactChips');
198-
var chipsCtrl = angular.element(element[0].querySelector('md-chips')).controller('mdChips');
199172

200173
var autocompleteElement = element.find('md-autocomplete');
201174
var autocompleteCtrl = autocompleteElement.controller('mdAutocomplete');
@@ -235,15 +208,6 @@ describe('<md-contact-chips>', function() {
235208
return container;
236209
}
237210

238-
function simulateInputEnterKey(ctrl) {
239-
var event = {};
240-
event.preventDefault = jasmine.createSpy('preventDefault');
241-
inject(function($mdConstant) {
242-
event.keyCode = $mdConstant.KEY_CODE.ENTER;
243-
});
244-
ctrl.inputKeydown(event);
245-
}
246-
247211
function keydownEvent(keyCode, target) {
248212
return {
249213
keyCode: keyCode,

src/components/chips/js/contactChipsController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ MdContactChipsCtrl.prototype.init = function() {
4040
// Timeout required to allow the child elements to be compiled.
4141
this.$timeout(function() {
4242
deRegister.push(
43-
element.find('md-chips').scope().$watchCollection('$mdChipsCtrl.items', function() {
43+
element.find('md-chips').controller('mdChips').$scope.$watchCollection('$mdChipsCtrl.items', function() {
4444
// Make sure our input and wrapper have the correct ARIA attributes
4545
ctrl.setupChipsAria();
4646
ctrl.setupAutocompleteAria();

0 commit comments

Comments
 (0)