#482 popover.js Front unit test

This commit is contained in:
Carlos Jimenez 2018-08-23 13:53:29 +02:00
parent 67afda853c
commit c2f89e7089
1 changed files with 85 additions and 0 deletions

View File

@ -0,0 +1,85 @@
import './popover';
describe('Component vnPopover', () => {
let $componentController;
let $httpBackend;
let $timeout;
let $element;
let controller;
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_, _$timeout_, _$document_) => {
$componentController = _$componentController_;
$timeout = _$timeout_;
$timeout.cancel = () => {};
$element = angular.element(`<div class="shown"></div>`);
$httpBackend = _$httpBackend_;
_$httpBackend_.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
controller = $componentController('vnPopover', {$httpBackend, $element});
}));
describe('show()', () => {
it(`should do nothing if _shown is defined in the controller`, () => {
controller._shown = true;
spyOn(controller, 'relocate');
controller.show();
expect(controller.relocate).not.toHaveBeenCalledWith();
});
it(`should not call on onOpen() as it is not defined in the controller`, () => {
controller.show();
expect(controller.onOpen).toBeUndefined();
});
it(`should call onOpen() if its defined`, () => {
controller.onOpen = () => {};
spyOn(controller, 'onOpen');
controller.show();
expect(controller.onOpen).toHaveBeenCalledWith();
});
});
describe('hide()', () => {
it(`should do nothing if _shown is defined in the controller`, () => {
controller._shown = false;
controller.hide();
expect($element[0].classList).toContain('shown');
});
it(`should set _shown property to false and then call onClose() if its defined`, () => {
controller._shown = true;
controller.onClose = () => {};
spyOn(controller, 'onClose');
controller.hide();
$timeout.flush();
expect(controller._shown).toBeFalsy();
expect(controller.onClose).toHaveBeenCalledWith();
});
it(`should set _shown property to false and then call deregisterCallback() if its defined`, () => {
controller._shown = true;
controller.deregisterCallback = () => {};
spyOn(controller, 'deregisterCallback');
controller.hide();
expect(controller._shown).toBeFalsy();
expect(controller.deregisterCallback).toHaveBeenCalledWith();
});
});
});