client side unit test for dialog onButtonClick()
This commit is contained in:
parent
1301fefe68
commit
e6acc57fae
|
@ -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;
|
||||
|
|
|
@ -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!');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue