salix/modules/item/front/index/index.spec.js

59 lines
2.0 KiB
JavaScript

import './index.js';
describe('Item', () => {
describe('Component vnItemIndex', () => {
let $state;
let controller;
let $httpBackend;
beforeEach(ngModule('item'));
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_) => {
$state = _$state_;
$httpBackend = _$httpBackend_;
controller = $componentController('vnItemIndex', {$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();
});
});
});
});