Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
fix(contact-chips): don't rely on debug info to get access to control…
Browse files Browse the repository at this point in the history
…ler scope

- fix exception when `debugInfoEnabled(false)` is set
- remove unused variables in tests
- remove commented out and unused code in tests

Fixes #11699
  • Loading branch information
Splaktar committed Mar 9, 2020
1 parent 5228f23 commit 2f77095
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 38 deletions.
38 changes: 1 addition & 37 deletions src/components/chips/contact-chips.spec.js
Expand Up @@ -35,7 +35,7 @@ describe('<md-contact-chips>', function() {
}
];
scope.contacts = [];
scope.keys = [$mdConstant.KEY_CODE.COMMA]
scope.keys = [$mdConstant.KEY_CODE.COMMA];

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

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

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

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

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

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

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

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

var element = buildChips(CONTACT_CHIPS_TEMPLATE);
var ctrl = element.controller('mdContactChips');

var autocompleteElement = element.find('md-autocomplete');
var autocompleteCtrl = autocompleteElement.controller('mdAutocomplete');
Expand All @@ -152,27 +147,6 @@ describe('<md-contact-chips>', function() {
var matches = autocompleteCtrl.matches;
expect(matches.length).toBe(3);
}));

/* it('should not filter when disabled', inject(function($timeout) {
scope.querySearch = jasmine.createSpy('querySearch').and.callFake(function(q) {
return scope.allContacts;
});
scope.contacts.push(scope.allContacts[2]);
scope.filterSelected = false;
var element = buildChips(CONTACT_CHIPS_TEMPLATE);
var ctrl = element.controller('mdContactChips');
$timeout.flush();
var autocompleteElement = element.find('md-autocomplete');
var autocompleteCtrl = autocompleteElement.controller('mdAutocomplete');
element.scope().$apply(function() {
autocompleteCtrl.scope.searchText = 'NAME';
autocompleteCtrl.keydown({});
});
var matches = autocompleteCtrl.matches;
expect(matches.length).toBe(3);
}));*/
});

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

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

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

function simulateInputEnterKey(ctrl) {
var event = {};
event.preventDefault = jasmine.createSpy('preventDefault');
inject(function($mdConstant) {
event.keyCode = $mdConstant.KEY_CODE.ENTER;
});
ctrl.inputKeydown(event);
}

function keydownEvent(keyCode, target) {
return {
keyCode: keyCode,
Expand Down
2 changes: 1 addition & 1 deletion src/components/chips/js/contactChipsController.js
Expand Up @@ -40,7 +40,7 @@ MdContactChipsCtrl.prototype.init = function() {
// Timeout required to allow the child elements to be compiled.
this.$timeout(function() {
deRegister.push(
element.find('md-chips').scope().$watchCollection('$mdChipsCtrl.items', function() {
element.find('md-chips').controller('mdChips').$scope.$watchCollection('$mdChipsCtrl.items', function() {
// Make sure our input and wrapper have the correct ARIA attributes
ctrl.setupChipsAria();
ctrl.setupAutocompleteAria();
Expand Down

0 comments on commit 2f77095

Please sign in to comment.