2019-01-22 09:04:42 +00:00
|
|
|
import './index';
|
|
|
|
|
|
|
|
describe('Ticket', () => {
|
|
|
|
describe('Component vnTicketTrackingEdit', () => {
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('ticket'));
|
2019-01-22 09:04:42 +00:00
|
|
|
|
2020-07-23 14:46:16 +00:00
|
|
|
beforeEach(inject(($componentController, _$httpBackend_, $translate, vnApp) => {
|
2019-01-22 09:04:42 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
2020-03-18 07:35:59 +00:00
|
|
|
const $element = angular.element('<vn-ticket-tracking-edit></vn-ticket-tracking-edit>');
|
|
|
|
controller = $componentController('vnTicketTrackingEdit', {$element});
|
2019-01-22 09:04:42 +00:00
|
|
|
controller.ticket = {id: 1};
|
|
|
|
controller.$ = {watcher: {updateOriginalData: () => {}}};
|
|
|
|
controller.card = {reload: () => {}};
|
|
|
|
controller.vnApp = {showSuccess: () => {}};
|
|
|
|
controller.$translate = $translate;
|
|
|
|
controller.vnApp = vnApp;
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('stateFk setter/getter', () => {
|
|
|
|
it('should set params.stateFk and set isPickerDesignedState', () => {
|
|
|
|
let stateFk = {id: 1};
|
|
|
|
controller.stateFk = stateFk;
|
|
|
|
|
|
|
|
expect(controller.params.stateFk).toEqual(stateFk);
|
|
|
|
expect(controller.isPickerDesignedState).toEqual(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('workerFk setter', () => {
|
|
|
|
it('should set params.workerFk', () => {
|
|
|
|
controller.workerFk = 1;
|
|
|
|
|
|
|
|
expect(controller.params.workerFk).toEqual(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getPickerDesignedState()', () => {
|
|
|
|
it('should get the state that has the code PICKER_DESIGNED', () => {
|
|
|
|
let filter = {
|
|
|
|
where: {
|
|
|
|
code: 'PICKER_DESIGNED'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
let json = encodeURIComponent(JSON.stringify(filter));
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.expectGET(`States?filter=${json}`).respond([{id: 22}]);
|
2019-01-22 09:04:42 +00:00
|
|
|
controller.getPickerDesignedState();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.pickerDesignedState).toEqual(22);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onSubmit()', () => {
|
|
|
|
it('should POST the data, call updateOriginalData, reload, showSuccess and go functions', () => {
|
2021-06-23 11:24:23 +00:00
|
|
|
controller.params = {stateFk: 22, workerFk: 1101};
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller.card, 'reload');
|
|
|
|
jest.spyOn(controller.$.watcher, 'updateOriginalData');
|
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
jest.spyOn(controller.$state, 'go');
|
2019-01-22 09:04:42 +00:00
|
|
|
|
2023-10-27 16:03:40 +00:00
|
|
|
$httpBackend.expectPOST(`Tickets/state`, controller.params).respond({});
|
2019-01-22 09:04:42 +00:00
|
|
|
controller.onSubmit();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.card.reload).toHaveBeenCalledWith();
|
|
|
|
expect(controller.$.watcher.updateOriginalData).toHaveBeenCalledWith();
|
2020-07-23 14:07:08 +00:00
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith(controller.$t('Data saved!'));
|
2019-01-22 09:04:42 +00:00
|
|
|
expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.tracking.index');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|