From 80cf8047146a726b3e08ded9cc35d063bcb0a150 Mon Sep 17 00:00:00 2001 From: Joan Date: Wed, 26 Sep 2018 14:15:00 +0200 Subject: [PATCH] tooltip front test #492 --- .../src/components/tooltip/tooltip.spec.js | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 client/core/src/components/tooltip/tooltip.spec.js diff --git a/client/core/src/components/tooltip/tooltip.spec.js b/client/core/src/components/tooltip/tooltip.spec.js new file mode 100644 index 000000000..b3d62a12e --- /dev/null +++ b/client/core/src/components/tooltip/tooltip.spec.js @@ -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(`
${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(); + }); + }); +});