salix/client/core/src/components/dialog/dialog.spec.js

54 lines
1.7 KiB
JavaScript
Raw Normal View History

2017-10-05 12:28:57 +00:00
describe('Component vnDialog', () => {
let $componentController;
let $element;
let controller;
2017-10-05 12:28:57 +00:00
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject(_$componentController_ => {
$componentController = _$componentController_;
$element = angular.element('<vn-dialog></vn-dialog>');
controller = $componentController('vnDialog', {$element: $element, $transclude: null});
2017-10-05 12:28:57 +00:00
}));
describe('show()', () => {
it(`should handle escape keypress event, define element.style.display to not none and call onOpen function`, () => {
2017-10-05 12:28:57 +00:00
window.innerHeight = 600;
window.innerWidth = 800;
controller.dialog = {style: {display: 'none'}};
controller.onOpen = () => {};
2017-10-05 12:28:57 +00:00
spyOn(controller, 'onOpen');
controller.show();
expect(controller.element.style.display).not.toEqual('none');
2017-10-05 12:28:57 +00:00
expect(controller.onOpen).toHaveBeenCalledWith();
});
});
describe('hide()', () => {
it(`should call onResponse()`, () => {
controller.onResponse = () => {};
spyOn(controller, 'onResponse');
2017-10-05 12:28:57 +00:00
controller.hide();
expect(controller.onResponse).toHaveBeenCalled();
2017-10-05 12:28:57 +00:00
});
});
describe('fireResponse()', () => {
it(`should call onResponse()`, () => {
2018-02-23 12:04:44 +00:00
let responseRes;
controller.onResponse = response => {
2018-02-23 12:04:44 +00:00
responseRes = response;
return false;
};
let responseRet = controller.fireResponse('answer');
2018-02-23 12:04:44 +00:00
expect(responseRes).toEqual({response: 'answer'});
expect(responseRet).toEqual(false);
});
});
2017-10-05 12:28:57 +00:00
});