From 4b7c87e6d00bda22d5d3d932e10047ec4e7bb1a7 Mon Sep 17 00:00:00 2001 From: Joan Date: Fri, 17 Aug 2018 11:05:09 +0200 Subject: [PATCH] left menu front test #511 --- .../components/left-menu/left-menu.spec.js | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 client/salix/src/components/left-menu/left-menu.spec.js diff --git a/client/salix/src/components/left-menu/left-menu.spec.js b/client/salix/src/components/left-menu/left-menu.spec.js new file mode 100644 index 000000000..a0686ab68 --- /dev/null +++ b/client/salix/src/components/left-menu/left-menu.spec.js @@ -0,0 +1,50 @@ +import './left-menu.js'; + +describe('Component vnLeftMenu', () => { + let $scope; + let $state; + let $httpBackend; + let controller; + let aclService; + + beforeEach(() => { + angular.mock.module('salix'); + }); + + beforeEach(angular.mock.inject((_$componentController_, $rootScope, _aclService_, _$state_, _$httpBackend_) => { + $scope = $rootScope.$new(); + $state = _$state_; + $state.current.data = { + routes: [] + }; + $state.current.name = 'client.card.summary'; + aclService = _aclService_; + $httpBackend = _$httpBackend_; + $httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({}); + controller = _$componentController_('vnLeftMenu', {$scope: $scope, $state: $state, aclService: aclService}); + controller.items = [ + {description: 'Client', href: 'client', icon: null}, + {description: 'Client', href: 'client.card', icon: null}, + {description: 'Client summary', href: 'client.card.summary', icon: 'myicon'} + ]; + })); + + describe('depth() setter', () => { + it(`should set depth property and call activateItem()`, () => { + spyOn(controller, 'activateItem'); + controller.depth = 3; + + expect(controller.depth).toEqual(3); + expect(controller.activateItem).toHaveBeenCalledWith(); + }); + }); + + describe('activateItem()', () => { + it(`should set active property to a route item if the current state matches up to a given depth`, () => { + controller._depth = 3; + controller.activateItem(); + + expect(controller.items[2].active).toBeTruthy(); + }); + }); +});