salix/client/ticket/src/data/step-three/index.spec.js

69 lines
2.4 KiB
JavaScript
Raw Normal View History

import './index.js';
describe('ticket', () => {
describe('Component vnTicketDataStepThree', () => {
let $componentController;
let $state;
let controller;
let $httpBackend;
let vnApp;
beforeEach(() => {
angular.mock.module('ticket');
});
beforeEach(angular.mock.inject((_$componentController_, _$state_, _$httpBackend_, _vnApp_) => {
$componentController = _$componentController_;
$state = _$state_;
spyOn($state, 'go');
vnApp = _vnApp_;
spyOn(vnApp, 'showError');
$httpBackend = _$httpBackend_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
controller = $componentController('vnTicketDataStepThree', {$state: $state});
}));
describe('onSubmit()', () => {
it(`should return an error if the item doesn't have option property in the controller`, () => {
controller.ticket = {};
controller.onSubmit();
expect(vnApp.showError).toHaveBeenCalledWith('Choose an option');
});
it('should perform a post query correctly then call two functions()', () => {
controller.card = {reload: () => {}};
spyOn(controller.card, 'reload');
controller.ticket = {
id: 1,
agencyModeFk: 1,
addressFk: 121,
warehouseFk: 1,
shipped: Date.now(),
landed: Date.now(),
option: 1
};
let data = {
agencyModeFk: 1,
addressFk: 121,
warehouseFk: 1,
shipped: Date.now(),
landed: Date.now(),
option: 1
};
$httpBackend.whenPOST(`/ticket/api/tickets/1/componentUpdate`, data).respond('ok');
$httpBackend.expectPOST(`/ticket/api/tickets/1/componentUpdate`, data);
controller.onSubmit();
$httpBackend.flush();
expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.summary', jasmine.any(Object));
expect(controller.card.reload).toHaveBeenCalledWith();
});
});
});
});