left menu front test #511

This commit is contained in:
Joan Sanchez 2018-08-17 11:05:09 +02:00
parent 8ccab773c0
commit 4b7c87e6d0
1 changed files with 50 additions and 0 deletions

View File

@ -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();
});
});
});