client side unit test for dialog onButtonClick()

This commit is contained in:
Carlos 2017-10-06 15:33:21 +02:00
parent 1301fefe68
commit e6acc57fae
2 changed files with 34 additions and 2 deletions

View File

@ -71,11 +71,9 @@ export default class Dialog extends Component {
}
onButtonClick(event) {
console.log(event);
let buttonBar = this.element.querySelector('.button-bar');
let buttons = buttonBar.querySelector('tpl-buttons');
let node = event.target;
while (node.parentNode != buttons) {
if (node == buttonBar) return;
node = node.parentNode;

View File

@ -88,4 +88,38 @@ describe('Component vnDialog', () => {
expect(controller.lastEvent).toEqual(null);
});
});
describe('onButtonClick()', () => {
it(`should call realHide if cancel isn't false`, () => {
let controller = $componentController('vnDialog', {$element});
controller.element = document.createElement('div');
controller.element.className = 'tpl-buttons';
let childElement = document.createElement('div');
childElement.className = 'button-bar';
controller.element.appendChild(childElement);
let event = {target: controller.element, attribute: true};
spyOn(controller, 'realHide');
spyOn(controller, 'fireResponse').and.returnValue(true);
controller.onButtonClick(event);
expect(controller.realHide).toHaveBeenCalledWith();
});
it(`should call fireResponse with the value of response`, () => {
let controller = $componentController('vnDialog', {$element});
controller.element = document.createElement('div');
controller.element.className = 'tpl-buttons';
let childElement = document.createElement('div');
childElement.className = 'button-bar';
controller.element.appendChild(childElement);
let event = {target: controller.element};
let attribute = document.createAttribute('response');
attribute.value = 'I am the response!';
controller.element.setAttributeNode(attribute);
spyOn(controller, 'fireResponse');
controller.onButtonClick(event);
expect(controller.fireResponse).toHaveBeenCalledWith('I am the response!');
});
});
});