60 lines
2.1 KiB
JavaScript
60 lines
2.1 KiB
JavaScript
import './index.js';
|
|
|
|
describe('Item', () => {
|
|
describe('Component vnItemIndex', () => {
|
|
let controller;
|
|
let $httpBackend;
|
|
let $scope;
|
|
|
|
beforeEach(ngModule('item'));
|
|
|
|
beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope) => {
|
|
$httpBackend = _$httpBackend_;
|
|
$scope = $rootScope.$new();
|
|
const $element = angular.element('<vn-item-index></vn-item-index>');
|
|
controller = $componentController('vnItemIndex', {$element, $scope});
|
|
}));
|
|
|
|
describe('onCloneAccept()', () => {
|
|
it('should do nothing if response is not accept', () => {
|
|
jest.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', () => {
|
|
jest.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', () => {
|
|
jest.spyOn(controller.$state, 'go');
|
|
|
|
let response = 'accept';
|
|
controller.itemSelected = {id: 1};
|
|
|
|
$httpBackend.when('POST', `Items/1/clone`).respond({id: 99});
|
|
$httpBackend.expect('POST', `Items/1/clone`);
|
|
controller.onCloneAccept(response);
|
|
$httpBackend.flush();
|
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('item.card.tags', {id: 99});
|
|
expect(controller.itemSelected).toBeNull();
|
|
});
|
|
});
|
|
});
|
|
});
|