salix/modules/ticket/front/tracking/edit/index.spec.js

76 lines
3.0 KiB
JavaScript
Raw Normal View History

2019-01-22 09:04:42 +00:00
import './index';
describe('Ticket', () => {
describe('Component vnTicketTrackingEdit', () => {
let controller;
let $httpBackend;
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);
});
});
2024-01-10 12:55:01 +00:00
describe('userFk setter', () => {
it('should set params.userFk', () => {
controller.userFk = 1;
2019-01-22 09:04:42 +00:00
2024-01-10 12:55:01 +00:00
expect(controller.params.userFk).toEqual(1);
2019-01-22 09:04:42 +00:00
});
});
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));
$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', () => {
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
$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();
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');
});
});
});
});