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

75 lines
2.9 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
beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $translate, vnApp) => {
$httpBackend = _$httpBackend_;
controller = $componentController('vnTicketTrackingEdit');
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}]);
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: 101};
spyOn(controller.card, 'reload');
spyOn(controller.$.watcher, 'updateOriginalData');
spyOn(controller.vnApp, 'showSuccess');
spyOn(controller.$state, 'go');
$httpBackend.expectPOST(`TicketTrackings/changeState`, 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.$translate.instant('Data saved!'));
expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.tracking.index');
});
});
});
});