2019-07-30 06:51:38 +00:00
|
|
|
import './index';
|
|
|
|
|
|
|
|
describe('Claim', () => {
|
|
|
|
describe('Component vnClaimDmsCreate', () => {
|
|
|
|
let controller;
|
|
|
|
let $scope;
|
|
|
|
let $httpBackend;
|
|
|
|
let $httpParamSerializer;
|
|
|
|
|
|
|
|
beforeEach(ngModule('claim'));
|
|
|
|
|
|
|
|
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
|
|
|
|
$scope = $rootScope.$new();
|
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
$httpParamSerializer = _$httpParamSerializer_;
|
|
|
|
controller = $componentController('vnClaimDmsCreate', {$scope});
|
|
|
|
controller._claim = {
|
|
|
|
id: 15,
|
|
|
|
client: {id: 101, name: 'Bruce wayne'},
|
|
|
|
ticketFk: 16
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('claim() setter', () => {
|
2019-08-08 06:37:03 +00:00
|
|
|
it('should set the claim data and then call setDefaultParams() and getAllowedContentTypes()', () => {
|
2019-07-30 06:51:38 +00:00
|
|
|
spyOn(controller, 'setDefaultParams');
|
2019-08-08 06:37:03 +00:00
|
|
|
spyOn(controller, 'getAllowedContentTypes');
|
2019-07-30 06:51:38 +00:00
|
|
|
controller._claim = undefined;
|
|
|
|
controller.claim = {
|
|
|
|
id: 15,
|
|
|
|
client: {id: 101, name: 'Bruce wayne'},
|
|
|
|
ticketFk: 16
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(controller.claim).toBeDefined();
|
|
|
|
expect(controller.setDefaultParams).toHaveBeenCalledWith();
|
2019-08-08 06:37:03 +00:00
|
|
|
expect(controller.getAllowedContentTypes).toHaveBeenCalledWith();
|
2019-07-30 06:51:38 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setDefaultParams()', () => {
|
|
|
|
it('should perform a GET query and define the dms property on controller', () => {
|
|
|
|
const params = {filter: {
|
|
|
|
where: {code: 'claim'}
|
|
|
|
}};
|
|
|
|
let serializedParams = $httpParamSerializer(params);
|
|
|
|
$httpBackend.when('GET', `/api/DmsTypes/findOne?${serializedParams}`).respond({id: 14, code: 'claim'});
|
|
|
|
$httpBackend.expect('GET', `/api/DmsTypes/findOne?${serializedParams}`);
|
|
|
|
controller.setDefaultParams();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.dms).toBeDefined();
|
|
|
|
expect(controller.dms.reference).toEqual(15);
|
|
|
|
expect(controller.dms.dmsTypeId).toEqual(14);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onFileChange()', () => {
|
|
|
|
it('should set dms hasFileAttached property to true if has any files', () => {
|
|
|
|
const files = [{id: 1, name: 'MyFile'}];
|
|
|
|
controller.onFileChange(files);
|
|
|
|
$scope.$apply();
|
|
|
|
|
|
|
|
expect(controller.dms.hasFileAttached).toBeTruthy();
|
|
|
|
});
|
|
|
|
});
|
2019-08-08 06:37:03 +00:00
|
|
|
|
|
|
|
describe('getAllowedContentTypes()', () => {
|
|
|
|
it('should make an HTTP GET request to get the allowed content types', () => {
|
|
|
|
const expectedResponse = ['image/png', 'image/jpg'];
|
|
|
|
$httpBackend.when('GET', `/api/claimDms/allowedContentTypes`).respond(expectedResponse);
|
|
|
|
$httpBackend.expect('GET', `/api/claimDms/allowedContentTypes`);
|
|
|
|
controller.getAllowedContentTypes();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.allowedContentTypes).toBeDefined();
|
|
|
|
expect(controller.allowedContentTypes).toEqual('image/png, image/jpg');
|
|
|
|
});
|
|
|
|
});
|
2019-07-30 06:51:38 +00:00
|
|
|
});
|
|
|
|
});
|