77 lines
3.0 KiB
JavaScript
77 lines
3.0 KiB
JavaScript
import './index';
|
|
|
|
describe('Ticket', () => {
|
|
describe('Component vnTicketTrackingEdit', () => {
|
|
let controller;
|
|
let $httpBackend;
|
|
|
|
beforeEach(angular.mock.module('ticket', $translateProvider => {
|
|
$translateProvider.translations('en', {});
|
|
}));
|
|
|
|
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(`/api/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: 101};
|
|
spyOn(controller.card, 'reload');
|
|
spyOn(controller.$.watcher, 'updateOriginalData');
|
|
spyOn(controller.vnApp, 'showSuccess');
|
|
spyOn(controller.$state, 'go');
|
|
|
|
$httpBackend.expectPOST(`/api/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.$translate.instant('Data saved!'));
|
|
expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.tracking.index');
|
|
});
|
|
});
|
|
});
|
|
});
|