tooltip front test #492

This commit is contained in:
Joan Sanchez 2018-09-26 14:15:00 +02:00
parent 65edae7f83
commit 80cf804714
1 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,65 @@
import './tooltip';
import template from './tooltip.html';
describe('Component vnTooltip', () => {
let $element;
let $scope;
let $httpBackend;
let $timeout;
let controller;
beforeEach(() => {
angular.mock.module('client');
});
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_, _$timeout_) => {
$scope = $rootScope.$new();
$timeout = _$timeout_;
$element = angular.element(`<div>${template}</div>`);
$httpBackend = _$httpBackend_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
controller = _$componentController_('vnTooltip', {$element, $scope, $timeout, $transclude: null});
}));
describe('show()', () => {
it(`should define parent property and add a class named 'show' to the element`, () => {
spyOn(controller, 'relocate');
spyOn(controller, 'cancelTimeout');
controller.show({name: 'parentElement'});
expect(controller.parent).toEqual({name: 'parentElement'});
expect($element[0].classList).toContain('show');
});
});
describe('hide()', () => {
it(`should remove a class named 'show' from the element`, () => {
spyOn(controller, 'cancelTimeout');
controller.hide();
expect($element[0].classList).not.toContain('show');
});
});
describe('cancelTimeout()', () => {
it(`should call $timeout cancel method and unset relocateTimeout property`, () => {
spyOn(controller.$timeout, 'cancel');
controller.relocateTimeout = {name: 'MyTimeout'};
controller.cancelTimeout();
expect(controller.$timeout.cancel).toHaveBeenCalledWith({name: 'MyTimeout'});
expect(controller.relocateTimeout).toBeNull();
});
it(`should not call $timeout cancel method`, () => {
spyOn(controller.$timeout, 'cancel');
controller.relocateTimeout = {name: 'MyTimeout'};
expect(controller.$timeout.cancel).not.toHaveBeenCalledWith();
expect(controller.relocateTimeout).toBeDefined();
});
});
});