76 lines
3.0 KiB
JavaScript
76 lines
3.0 KiB
JavaScript
import './index';
|
|
|
|
describe('Ticket', () => {
|
|
describe('Component vnTicketTrackingEdit', () => {
|
|
let controller;
|
|
let $httpBackend;
|
|
|
|
beforeEach(ngModule('ticket'));
|
|
|
|
beforeEach(inject(($componentController, _$httpBackend_, $translate, vnApp) => {
|
|
$httpBackend = _$httpBackend_;
|
|
const $element = angular.element('<vn-ticket-tracking-edit></vn-ticket-tracking-edit>');
|
|
controller = $componentController('vnTicketTrackingEdit', {$element});
|
|
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));
|
|
$httpBackend.expectGET(`States?filter=${json}`).respond([{id: 22}]);
|
|
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};
|
|
jest.spyOn(controller.card, 'reload');
|
|
jest.spyOn(controller.$.watcher, 'updateOriginalData');
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
jest.spyOn(controller.$state, 'go');
|
|
|
|
$httpBackend.expectPOST(`TicketTrackings/changeState`, controller.params).respond({});
|
|
controller.onSubmit();
|
|
$httpBackend.flush();
|
|
|
|
expect(controller.card.reload).toHaveBeenCalledWith();
|
|
expect(controller.$.watcher.updateOriginalData).toHaveBeenCalledWith();
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith(controller.$t('Data saved!'));
|
|
expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.tracking.index');
|
|
});
|
|
});
|
|
});
|
|
});
|