69 lines
2.9 KiB
JavaScript
69 lines
2.9 KiB
JavaScript
import './index';
|
|
|
|
describe('Ticket', () => {
|
|
describe('Component vnTravelThermographCreate', () => {
|
|
let controller;
|
|
let $scope;
|
|
let $httpBackend;
|
|
let $httpParamSerializer;
|
|
const travelId = 3;
|
|
const dmsTypeId = 5;
|
|
|
|
beforeEach(ngModule('travel'));
|
|
|
|
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
|
|
$scope = $rootScope.$new();
|
|
$httpBackend = _$httpBackend_;
|
|
$httpParamSerializer = _$httpParamSerializer_;
|
|
controller = $componentController('vnTravelThermographCreate', {$scope});
|
|
controller._travel = {
|
|
id: travelId
|
|
};
|
|
}));
|
|
|
|
describe('travel() setter', () => {
|
|
it('should set the travel data and then call setDefaultParams() and getAllowedContentTypes()', () => {
|
|
spyOn(controller, 'setDefaultParams');
|
|
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');
|
|
});
|
|
});
|
|
});
|
|
});
|