2020-01-17 07:43:10 +00:00
|
|
|
import './index';
|
|
|
|
|
|
|
|
describe('Ticket', () => {
|
2020-01-22 08:04:26 +00:00
|
|
|
describe('Component vnTravelThermographCreate', () => {
|
2020-01-17 07:43:10 +00:00
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
let $httpParamSerializer;
|
2020-01-22 08:04:26 +00:00
|
|
|
const travelId = 3;
|
|
|
|
const dmsTypeId = 5;
|
2020-01-17 07:43:10 +00:00
|
|
|
|
2020-01-22 08:04:26 +00:00
|
|
|
beforeEach(ngModule('travel'));
|
2020-01-17 07:43:10 +00:00
|
|
|
|
2020-07-23 14:46:16 +00:00
|
|
|
beforeEach(inject(($componentController, _$httpBackend_, _$httpParamSerializer_) => {
|
2020-01-17 07:43:10 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
$httpParamSerializer = _$httpParamSerializer_;
|
2020-03-18 11:55:22 +00:00
|
|
|
const $element = angular.element('<vn-travel-thermograph-create></vn-travel-thermograph-create>');
|
|
|
|
controller = $componentController('vnTravelThermographCreate', {$element});
|
2020-01-22 08:04:26 +00:00
|
|
|
controller._travel = {
|
|
|
|
id: travelId
|
2020-01-17 07:43:10 +00:00
|
|
|
};
|
|
|
|
}));
|
|
|
|
|
2020-01-22 08:04:26 +00:00
|
|
|
describe('travel() setter', () => {
|
|
|
|
it('should set the travel data and then call setDefaultParams() and getAllowedContentTypes()', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller, 'setDefaultParams');
|
|
|
|
jest.spyOn(controller, 'getAllowedContentTypes');
|
2020-01-22 08:04:26 +00:00
|
|
|
controller.travel = {
|
|
|
|
id: travelId
|
2020-01-17 07:43:10 +00:00
|
|
|
};
|
|
|
|
|
2020-01-22 08:04:26 +00:00
|
|
|
expect(controller.travel).toBeDefined();
|
2020-01-17 07:43:10 +00:00
|
|
|
expect(controller.setDefaultParams).toHaveBeenCalledWith();
|
|
|
|
expect(controller.getAllowedContentTypes).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setDefaultParams()', () => {
|
|
|
|
it('should perform a GET query and define the dms property on controller', () => {
|
|
|
|
const params = {filter: {
|
2020-01-22 08:04:26 +00:00
|
|
|
where: {code: 'miscellaneous'}
|
2020-01-17 07:43:10 +00:00
|
|
|
}};
|
|
|
|
let serializedParams = $httpParamSerializer(params);
|
2020-07-23 15:10:07 +00:00
|
|
|
$httpBackend.expect('GET', `DmsTypes/findOne?${serializedParams}`).respond({id: dmsTypeId, code: 'miscellaneous'});
|
2020-01-17 07:43:10 +00:00
|
|
|
controller.setDefaultParams();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.dms).toBeDefined();
|
2020-01-22 08:04:26 +00:00
|
|
|
expect(controller.dms.reference).toEqual(travelId);
|
|
|
|
expect(controller.dms.dmsTypeId).toEqual(dmsTypeId);
|
2020-01-17 07:43:10 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getAllowedContentTypes()', () => {
|
|
|
|
it('should make an HTTP GET request to get the allowed content types', () => {
|
2020-01-22 08:04:26 +00:00
|
|
|
const expectedResponse = ['application/pdf', 'image/png', 'image/jpg'];
|
2020-12-18 17:02:41 +00:00
|
|
|
$httpBackend.expect('GET', `DmsContainers/allowedContentTypes`).respond(expectedResponse);
|
2020-01-17 07:43:10 +00:00
|
|
|
controller.getAllowedContentTypes();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.allowedContentTypes).toBeDefined();
|
2020-01-22 08:04:26 +00:00
|
|
|
expect(controller.allowedContentTypes).toEqual('application/pdf, image/png, image/jpg');
|
2020-01-17 07:43:10 +00:00
|
|
|
});
|
|
|
|
});
|
2020-05-27 11:11:41 +00:00
|
|
|
|
|
|
|
describe('onAddThermographClick()', () => {
|
|
|
|
it('should call the show() function of the create thermograph dialog', () => {
|
2020-05-27 12:54:29 +00:00
|
|
|
controller.$.newThermographDialog = {show: jest.fn()};
|
|
|
|
controller.$.modelsModel = {refresh: jest.fn()};
|
|
|
|
controller.$.temperaturesModel = {refresh: jest.fn()};
|
2020-05-27 12:54:54 +00:00
|
|
|
|
2020-05-27 11:11:41 +00:00
|
|
|
const event = new Event('click');
|
|
|
|
jest.spyOn(event, 'preventDefault');
|
|
|
|
|
|
|
|
controller.onAddThermographClick(event);
|
|
|
|
|
|
|
|
expect(event.preventDefault).toHaveBeenCalledTimes(1);
|
|
|
|
expect(controller.$.newThermographDialog.show).toHaveBeenCalledTimes(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onNewThermographAccept()', () => {
|
2021-10-19 09:08:03 +00:00
|
|
|
it('should set the created thermograph data on to the controller for the autocomplete to use it', () => {
|
|
|
|
const id = 'the created id';
|
|
|
|
const warehouseId = 1;
|
|
|
|
const temperatureId = 'cool';
|
|
|
|
const model = 'my model';
|
|
|
|
|
|
|
|
controller.newThermograph = {
|
|
|
|
thermographId: id,
|
|
|
|
warehouseId: warehouseId,
|
|
|
|
temperatureFk: temperatureId,
|
|
|
|
model: model
|
|
|
|
};
|
|
|
|
const response = {
|
|
|
|
id: id,
|
|
|
|
warehouseId: warehouseId,
|
|
|
|
temperatureFk: temperatureId,
|
|
|
|
model: model
|
|
|
|
};
|
2020-05-27 11:11:41 +00:00
|
|
|
$httpBackend.when('POST', `Thermographs/createThermograph`).respond(response);
|
|
|
|
controller.onNewThermographAccept();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.dms.thermographId).toEqual(response.id);
|
|
|
|
});
|
|
|
|
});
|
2020-01-17 07:43:10 +00:00
|
|
|
});
|
|
|
|
});
|