CLient side unit test for dialog onKeypress()

This commit is contained in:
Carlos 2017-10-09 14:30:23 +02:00
parent aec32f5e4a
commit c341009489
1 changed files with 24 additions and 0 deletions

View File

@ -158,4 +158,28 @@ describe('Component vnDialog', () => {
expect(controller.hide).toHaveBeenCalledWith();
});
});
describe('onKeypress()', () => {
it(`should call hide() if the key pressed equal the code 27`, () => {
let controller = $componentController('vnDialog', {$element});
controller.element = document.createElement('div');
let event = {target: controller.element};
event.keyCode = 27;
spyOn(controller, 'hide');
controller.onKeypress(event);
expect(controller.hide).toHaveBeenCalledWith();
});
it(`should't call hide() as the key pressed equal the code 999`, () => {
let controller = $componentController('vnDialog', {$element});
controller.element = document.createElement('div');
let event = {target: controller.element};
event.keyCode = 999;
spyOn(controller, 'hide');
controller.onKeypress(event);
expect(controller.hide).not.toHaveBeenCalledWith();
});
});
});