Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/keypad.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
63 changes: 62 additions & 1 deletion src/keypad.controller.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(`
<bc-keypad
bc-number-model="numbers"
bc-left-button-method="buttonLeft($event, numbers)"
bc-right-button-method="buttonRight($event, numbers)"
></bc-keypad>
`);
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(`
<bc-keypad
bc-number-model="numbers"
></bc-keypad>
`);
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);
});

});


});