salix/front/core/components/popover/index.spec.js

62 lines
1.8 KiB
JavaScript
Raw Permalink Normal View History

2018-08-23 11:53:29 +00:00
describe('Component vnPopover', () => {
let $element;
2018-10-18 18:48:21 +00:00
let $parent;
2018-11-06 13:27:16 +00:00
let controller;
2018-08-23 11:53:29 +00:00
beforeEach(ngModule('vnCore'));
2018-08-23 11:53:29 +00:00
2018-10-18 18:48:21 +00:00
beforeEach(inject(($compile, $rootScope, $document) => {
2018-10-19 07:33:12 +00:00
$element = $compile(`<vn-popover>test</vn-popover>`)($rootScope);
2018-10-18 18:48:21 +00:00
$document.find('body').append($element);
2018-11-06 13:27:16 +00:00
controller = $element.controller('vnPopover');
2018-08-23 11:53:29 +00:00
2018-10-18 18:48:21 +00:00
$parent = angular.element('<div/>');
$document.find('body').append($parent);
}));
2018-08-23 11:53:29 +00:00
2018-10-18 18:48:21 +00:00
afterEach(() => {
$element.remove();
$parent.remove();
});
2018-08-23 11:53:29 +00:00
2018-10-18 18:48:21 +00:00
describe('show()', () => {
it(`should enable the shown property and emit the open event`, () => {
2020-02-26 12:22:52 +00:00
jest.spyOn(controller, 'emit');
2018-11-06 13:27:16 +00:00
controller.show();
2018-08-23 11:53:29 +00:00
2018-11-06 13:27:16 +00:00
expect(controller.shown).toBeTruthy();
expect(controller.emit).toHaveBeenCalledWith('open');
2018-08-23 11:53:29 +00:00
});
2018-10-18 18:48:21 +00:00
it(`should do nothing if it's already shown`, () => {
2018-11-06 13:27:16 +00:00
controller.shown = true;
2020-02-26 12:22:52 +00:00
jest.spyOn(controller, 'emit');
2018-11-06 13:27:16 +00:00
controller.show();
2018-08-23 11:53:29 +00:00
2018-11-06 13:27:16 +00:00
expect(controller.emit).not.toHaveBeenCalledWith('open');
2018-08-23 11:53:29 +00:00
});
});
describe('hide()', () => {
2018-10-18 18:48:21 +00:00
it(`should disable the shown property and emit the close event`, inject($timeout => {
2018-11-06 13:27:16 +00:00
controller.show();
2020-02-26 12:22:52 +00:00
jest.spyOn(controller, 'emit');
2018-11-06 13:27:16 +00:00
controller.hide();
2018-08-23 11:53:29 +00:00
$timeout.flush();
2018-11-06 13:27:16 +00:00
expect(controller.shown).toBeFalsy();
expect(controller.emit).toHaveBeenCalledWith('close');
2018-10-18 18:48:21 +00:00
}));
2018-08-23 11:53:29 +00:00
2018-10-18 18:48:21 +00:00
it(`should do nothing if it's already hidden`, () => {
2018-11-06 13:27:16 +00:00
controller.shown = false;
2020-02-26 12:22:52 +00:00
jest.spyOn(controller, 'emit');
2018-11-06 13:27:16 +00:00
controller.hide();
2018-08-23 11:53:29 +00:00
2018-11-06 13:27:16 +00:00
expect(controller.emit).not.toHaveBeenCalledWith('close');
2018-08-23 11:53:29 +00:00
});
});
});