#503 client/item/src/index/index.js Front unit test

This commit is contained in:
Carlos Jimenez 2018-08-22 12:55:15 +02:00
parent 700e5f1dfb
commit 7abeebeecb
1 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,63 @@
import './index.js';
describe('Item', () => {
describe('Component vnItemIndex', () => {
let $componentController;
let $state;
let controller;
let $httpBackend;
beforeEach(() => {
angular.mock.module('item');
});
beforeEach(angular.mock.inject((_$componentController_, _$state_, _$httpBackend_) => {
$componentController = _$componentController_;
$state = _$state_;
$httpBackend = _$httpBackend_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
controller = $componentController('vnItemIndex', {$state: $state});
}));
describe('onCloneAccept()', () => {
it('should do nothing if response is not ACCEPT', () => {
spyOn(controller.$state, 'go');
let response = 'ERROR!';
controller.itemSelected = 'check me';
controller.onCloneAccept(response);
expect(controller.$state.go).not.toHaveBeenCalledWith();
expect(controller.itemSelected).toEqual('check me');
});
it('should do nothing if response is ACCEPT but itemSelected is not defined in the controller', () => {
spyOn(controller.$state, 'go');
let response = 'ACCEPT';
controller.itemSelected = undefined;
controller.onCloneAccept(response);
expect(controller.$state.go).not.toHaveBeenCalledWith();
expect(controller.itemSelected).toBeUndefined();
});
it('should perform a post query and then call go() then update itemSelected in the controller', () => {
spyOn(controller.$state, 'go');
let response = 'ACCEPT';
controller.itemSelected = {id: 1};
$httpBackend.when('POST', `/item/api/Items/1/clone`).respond({id: 99});
$httpBackend.expect('POST', `/item/api/Items/1/clone`);
controller.onCloneAccept(response);
$httpBackend.flush();
expect(controller.$state.go).toHaveBeenCalledWith('item.card.tags', {id: 99});
expect(controller.itemSelected).toBeNull();
});
});
});
});