97 lines
4.3 KiB
JavaScript
97 lines
4.3 KiB
JavaScript
import './index';
|
|
|
|
describe('Ticket', () => {
|
|
describe('Component vnTravelThermographCreate', () => {
|
|
let controller;
|
|
let $httpBackend;
|
|
let $httpParamSerializer;
|
|
const travelId = 3;
|
|
const dmsTypeId = 5;
|
|
|
|
beforeEach(ngModule('travel'));
|
|
|
|
beforeEach(angular.mock.inject(($componentController, _$httpBackend_, _$httpParamSerializer_) => {
|
|
$httpBackend = _$httpBackend_;
|
|
$httpParamSerializer = _$httpParamSerializer_;
|
|
const $element = angular.element('<vn-travel-thermograph-create></vn-travel-thermograph-create>');
|
|
controller = $componentController('vnTravelThermographCreate', {$element});
|
|
controller._travel = {
|
|
id: travelId
|
|
};
|
|
}));
|
|
|
|
describe('travel() setter', () => {
|
|
it('should set the travel data and then call setDefaultParams() and getAllowedContentTypes()', () => {
|
|
jest.spyOn(controller, 'setDefaultParams');
|
|
jest.spyOn(controller, 'getAllowedContentTypes');
|
|
controller.travel = {
|
|
id: travelId
|
|
};
|
|
|
|
expect(controller.travel).toBeDefined();
|
|
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: {
|
|
where: {code: 'miscellaneous'}
|
|
}};
|
|
let serializedParams = $httpParamSerializer(params);
|
|
$httpBackend.when('GET', `DmsTypes/findOne?${serializedParams}`).respond({id: dmsTypeId, code: 'miscellaneous'});
|
|
$httpBackend.expect('GET', `DmsTypes/findOne?${serializedParams}`);
|
|
controller.setDefaultParams();
|
|
$httpBackend.flush();
|
|
|
|
expect(controller.dms).toBeDefined();
|
|
expect(controller.dms.reference).toEqual(travelId);
|
|
expect(controller.dms.dmsTypeId).toEqual(dmsTypeId);
|
|
});
|
|
});
|
|
|
|
describe('getAllowedContentTypes()', () => {
|
|
it('should make an HTTP GET request to get the allowed content types', () => {
|
|
const expectedResponse = ['application/pdf', 'image/png', 'image/jpg'];
|
|
$httpBackend.when('GET', `TravelThermographs/allowedContentTypes`).respond(expectedResponse);
|
|
$httpBackend.expect('GET', `TravelThermographs/allowedContentTypes`);
|
|
controller.getAllowedContentTypes();
|
|
$httpBackend.flush();
|
|
|
|
expect(controller.allowedContentTypes).toBeDefined();
|
|
expect(controller.allowedContentTypes).toEqual('application/pdf, image/png, image/jpg');
|
|
});
|
|
});
|
|
|
|
describe('onAddThermographClick()', () => {
|
|
it('should call the show() function of the create thermograph dialog', () => {
|
|
controller.$.newThermographDialog = {show: jest.fn()};
|
|
controller.$.modelsModel = {refresh: jest.fn()};
|
|
controller.$.temperaturesModel = {refresh: jest.fn()};
|
|
// jest.spyOn(controller.$.newThermographDialog, 'show');
|
|
// jest.spyOn(controller.$.modelsModel, 'refresh');
|
|
// jest.spyOn(controller.$.temperaturesModel, 'refresh');
|
|
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()', () => {
|
|
it('should set the created thermograph id on to the controller for the autocomplete to use it', () => {
|
|
const response = {id: 'the created id'};
|
|
$httpBackend.when('POST', `Thermographs/createThermograph`).respond(response);
|
|
controller.onNewThermographAccept();
|
|
$httpBackend.flush();
|
|
|
|
expect(controller.dms.thermographId).toEqual(response.id);
|
|
});
|
|
});
|
|
});
|
|
});
|