diff --git a/src/keypad.controller.js b/src/keypad.controller.js index 914b926..b0b658e 100644 --- a/src/keypad.controller.js +++ b/src/keypad.controller.js @@ -37,7 +37,7 @@ export class KeypadController { }; // The numbers that make up the keypad - this.numbers = this.bcKeypadConfig.numbers; + this.numbers = this.bcKeypadConfig.numbers.slice(); // Pull the last number off of the array so that we can inject it outside of the ng-repeat this.lastNumber = this.numbers.splice(this.numbers.length - 1, 1)[0]; diff --git a/src/keypad.controller.spec.js b/src/keypad.controller.spec.js index 66554cd..8eee00a 100644 --- a/src/keypad.controller.spec.js +++ b/src/keypad.controller.spec.js @@ -207,7 +207,8 @@ describe('KeypadController', () => { it('should add to the number model when number key is clicked', () => { const ORIGINAL_LENGTH = vm.bcNumberModel.length; - const numberButton = element[0].querySelectorAll('.bc-keypad__key > button')[2]; + const buttonArray = element[0].querySelectorAll('.bc-keypad__key > button'); + const numberButton = buttonArray[2]; angular.element(numberButton).triggerHandler('click'); expect(vm.bcNumberModel.length).toEqual(ORIGINAL_LENGTH + 1); @@ -277,6 +278,66 @@ describe('KeypadController', () => { }); + describe('Config Invariance', () => { + let $scope; + let element; + let vm; + const defaultNumbers = + [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]; // eslint-disable-line no-magic-numbers + + beforeEach(() => { + $scope = $rootScope.$new(); + $scope.buttonLeft = function($event, numbers) {}; + $scope.buttonRight = function($event, numbers) {}; + $scope.numbers = ''; + element = angular.element(` + + `); + element = $compile(element)($scope); + $scope.$apply(); + vm = element.isolateScope().vm; + + spyOn($scope, 'buttonLeft'); + spyOn($scope, 'buttonRight'); + }); + + it('config should still contain the same numbers after keypad constructed', () => { + const buttons = vm.bcKeypadConfig.numbers; + + expect(buttons).toEqual(defaultNumbers); + }); + + it('config should still remain the same after keypad constructions', () => { + for (let i = 0; i < 3; i = i + 1) { // eslint-disable-line no-magic-numbers + $scope = $rootScope.$new(); + $scope.numbers = ''; + element = angular.element(` + + `); + element = $compile(element)($scope); + $scope.$apply(); + vm = element.isolateScope().vm; + + const buttons = vm.bcKeypadConfig.numbers; + + expect(buttons).toEqual(defaultNumbers); + } + }); + + it('the keypad should have 12 buttons given a left and right method', () => { + const buttonArray = element[0].querySelectorAll('.bc-keypad__key'); + + expect(buttonArray.length).toEqual(defaultNumbers.length + 2); + }); + + }); + });