81 lines
3.2 KiB
JavaScript
81 lines
3.2 KiB
JavaScript
import './index';
|
|
import crudModel from 'core/mocks/crud-model';
|
|
|
|
describe('Claim', () => {
|
|
describe('Component vnClaimPhotos', () => {
|
|
let $scope;
|
|
let $httpBackend;
|
|
let controller;
|
|
let $httpParamSerializer;
|
|
|
|
beforeEach(ngModule('claim'));
|
|
|
|
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
|
|
$httpParamSerializer = _$httpParamSerializer_;
|
|
$httpBackend = _$httpBackend_;
|
|
$scope = $rootScope.$new();
|
|
const $element = angular.element('<vn-claim-photos></vn-claim-photos>');
|
|
controller = $componentController('vnClaimPhotos', {$element, $scope});
|
|
controller.$.model = crudModel;
|
|
controller.claim = {
|
|
id: 1,
|
|
client: {id: 101, name: 'Bruce Wayne'}
|
|
};
|
|
}));
|
|
|
|
describe('deleteDms()', () => {
|
|
it('should make an HTTP Post query', () => {
|
|
const dmsId = 1;
|
|
const dmsIndex = 0;
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
jest.spyOn(controller.$.model, 'remove');
|
|
controller.photos = [{dmsFk: 1}];
|
|
controller.dmsIndex = dmsIndex;
|
|
|
|
$httpBackend.when('POST', `claimDms/${dmsId}/removeFile`).respond({});
|
|
$httpBackend.expect('POST', `claimDms/${dmsId}/removeFile`);
|
|
controller.deleteDms('accept');
|
|
$httpBackend.flush();
|
|
|
|
expect(controller.$.model.remove).toHaveBeenCalledWith(dmsIndex);
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Photo deleted');
|
|
});
|
|
});
|
|
|
|
describe('setDefaultParams()', () => {
|
|
it('should make an HTTP GET query, then set all dms properties', () => {
|
|
const params = {filter: {
|
|
where: {code: 'claim'}
|
|
}};
|
|
let serializedParams = $httpParamSerializer(params);
|
|
$httpBackend.when('GET', `DmsTypes/findOne?${serializedParams}`).respond({});
|
|
$httpBackend.expect('GET', `DmsTypes/findOne?${serializedParams}`);
|
|
controller.setDefaultParams();
|
|
$httpBackend.flush();
|
|
|
|
expect(controller.dms).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('create()', () => {
|
|
it('should make an HTTP Post query, then refresh the model data', () => {
|
|
const claimId = 1;
|
|
const dmsIndex = 0;
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
jest.spyOn(controller.$.model, 'refresh');
|
|
controller.photos = [{dmsFk: 1}];
|
|
controller.dmsIndex = dmsIndex;
|
|
controller.dms = {files: []};
|
|
|
|
$httpBackend.when('POST', `claims/${claimId}/uploadFile`).respond({});
|
|
$httpBackend.expect('POST', `claims/${claimId}/uploadFile`);
|
|
controller.create();
|
|
$httpBackend.flush();
|
|
|
|
expect(controller.$.model.refresh).toHaveBeenCalledWith();
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Photo uploaded!');
|
|
});
|
|
});
|
|
});
|
|
});
|