2018-08-12 08:55:16 +00:00
|
|
|
import './index.js';
|
2018-05-16 06:13:39 +00:00
|
|
|
|
|
|
|
describe('ticket', () => {
|
2019-04-16 13:00:21 +00:00
|
|
|
describe('Component vnTicketBasicDataStepThree', () => {
|
2018-10-18 09:41:25 +00:00
|
|
|
let now = Date.now();
|
2018-05-16 06:13:39 +00:00
|
|
|
let $state;
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
2018-08-12 08:55:16 +00:00
|
|
|
let vnApp;
|
2018-05-16 06:13:39 +00:00
|
|
|
|
2019-09-13 14:09:14 +00:00
|
|
|
beforeEach(angular.mock.module('ticket', $translateProvider => {
|
|
|
|
$translateProvider.translations('en', {});
|
|
|
|
}));
|
2018-05-16 06:13:39 +00:00
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_, _vnApp_) => {
|
2018-05-16 06:13:39 +00:00
|
|
|
$state = _$state_;
|
2018-08-12 08:55:16 +00:00
|
|
|
spyOn($state, 'go');
|
|
|
|
vnApp = _vnApp_;
|
|
|
|
spyOn(vnApp, 'showError');
|
2018-05-16 06:13:39 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
2019-04-16 13:00:21 +00:00
|
|
|
controller = $componentController('vnTicketBasicDataStepThree', {$state});
|
2018-05-16 06:13:39 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
describe('onSubmit()', () => {
|
2018-08-12 08:55:16 +00:00
|
|
|
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');
|
|
|
|
|
2018-05-16 06:13:39 +00:00
|
|
|
controller.ticket = {
|
|
|
|
id: 1,
|
|
|
|
agencyModeFk: 1,
|
|
|
|
addressFk: 121,
|
2019-07-26 09:48:01 +00:00
|
|
|
zoneFk: 3,
|
2018-05-16 06:13:39 +00:00
|
|
|
warehouseFk: 1,
|
2018-10-18 09:41:25 +00:00
|
|
|
shipped: now,
|
|
|
|
landed: now,
|
2018-05-16 06:13:39 +00:00
|
|
|
option: 1
|
|
|
|
};
|
|
|
|
|
|
|
|
let data = {
|
2019-07-26 09:48:01 +00:00
|
|
|
agencyModeId: 1,
|
|
|
|
addressId: 121,
|
|
|
|
zoneId: 3,
|
|
|
|
warehouseId: 1,
|
2018-10-18 09:41:25 +00:00
|
|
|
shipped: now,
|
|
|
|
landed: now,
|
2018-05-16 06:13:39 +00:00
|
|
|
option: 1
|
|
|
|
};
|
2018-08-01 07:47:34 +00:00
|
|
|
|
2019-07-26 09:48:01 +00:00
|
|
|
$httpBackend.whenPOST(`/api/tickets/1/componentUpdate`, data).respond('ok');
|
|
|
|
$httpBackend.expectPOST(`/api/tickets/1/componentUpdate`, data);
|
2018-08-12 08:55:16 +00:00
|
|
|
controller.onSubmit();
|
|
|
|
$httpBackend.flush();
|
2018-05-16 06:13:39 +00:00
|
|
|
|
2018-08-12 08:55:16 +00:00
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.summary', jasmine.any(Object));
|
|
|
|
expect(controller.card.reload).toHaveBeenCalledWith();
|
2018-05-16 06:13:39 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-08-12 08:55:16 +00:00
|
|
|
});
|