2018-08-22 10:55:15 +00:00
|
|
|
import './index.js';
|
|
|
|
|
|
|
|
describe('Item', () => {
|
|
|
|
describe('Component vnItemIndex', () => {
|
|
|
|
let $state;
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('item'));
|
2018-08-22 10:55:15 +00:00
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_) => {
|
2018-08-22 10:55:15 +00:00
|
|
|
$state = _$state_;
|
|
|
|
$httpBackend = _$httpBackend_;
|
2018-12-22 10:59:26 +00:00
|
|
|
controller = $componentController('vnItemIndex', {$state});
|
2018-08-22 10:55:15 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
describe('onCloneAccept()', () => {
|
2019-10-30 15:57:14 +00:00
|
|
|
it('should do nothing if response is not accept', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.$state, 'go');
|
2018-08-22 10:55:15 +00:00
|
|
|
|
|
|
|
let response = 'ERROR!';
|
|
|
|
controller.itemSelected = 'check me';
|
|
|
|
|
|
|
|
controller.onCloneAccept(response);
|
|
|
|
|
|
|
|
expect(controller.$state.go).not.toHaveBeenCalledWith();
|
|
|
|
expect(controller.itemSelected).toEqual('check me');
|
|
|
|
});
|
|
|
|
|
2019-10-30 15:57:14 +00:00
|
|
|
it('should do nothing if response is accept but itemSelected is not defined in the controller', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.$state, 'go');
|
2018-08-22 10:55:15 +00:00
|
|
|
|
2019-10-30 15:57:14 +00:00
|
|
|
let response = 'accept';
|
2018-08-22 10:55:15 +00:00
|
|
|
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', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.$state, 'go');
|
2018-08-22 10:55:15 +00:00
|
|
|
|
2019-10-30 15:57:14 +00:00
|
|
|
let response = 'accept';
|
2018-08-22 10:55:15 +00:00
|
|
|
controller.itemSelected = {id: 1};
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.when('POST', `Items/1/clone`).respond({id: 99});
|
|
|
|
$httpBackend.expect('POST', `Items/1/clone`);
|
2018-08-22 10:55:15 +00:00
|
|
|
controller.onCloneAccept(response);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('item.card.tags', {id: 99});
|
|
|
|
expect(controller.itemSelected).toBeNull();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|