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(`
${template}
`); $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(); }); }); });