70 lines
2.5 KiB
JavaScript
70 lines
2.5 KiB
JavaScript
|
import './index';
|
||
|
|
||
|
describe('Claim', () => {
|
||
|
describe('Component vnClaimDmsEdit', () => {
|
||
|
let controller;
|
||
|
let $scope;
|
||
|
let $httpBackend;
|
||
|
let $state;
|
||
|
|
||
|
beforeEach(ngModule('claim'));
|
||
|
|
||
|
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => {
|
||
|
$scope = $rootScope.$new();
|
||
|
$httpBackend = _$httpBackend_;
|
||
|
$state = {params: {dmsId: 1}};
|
||
|
controller = $componentController('vnClaimDmsEdit', {$scope, $state});
|
||
|
controller._claim = {id: 1, ticketFk: 16};
|
||
|
}));
|
||
|
|
||
|
describe('claim() setter', () => {
|
||
|
it('should set the claim data and then call setDefaultParams()', () => {
|
||
|
spyOn(controller, 'setDefaultParams');
|
||
|
controller._claim = undefined;
|
||
|
controller.claim = {
|
||
|
id: 15,
|
||
|
ticketFk: 16
|
||
|
};
|
||
|
|
||
|
expect(controller.setDefaultParams).toHaveBeenCalledWith();
|
||
|
expect(controller.claim).toBeDefined();
|
||
|
});
|
||
|
});
|
||
|
|
||
|
describe('setDefaultParams()', () => {
|
||
|
it('should perform a GET query and define the dms property on controller', () => {
|
||
|
const dmsId = 1;
|
||
|
const expectedResponse = {
|
||
|
reference: 101,
|
||
|
warehouseFk: 1,
|
||
|
companyFk: 442,
|
||
|
dmsTypeFk: 12,
|
||
|
description: 'Test',
|
||
|
hasFile: false,
|
||
|
hasFileAttached: false
|
||
|
};
|
||
|
|
||
|
$httpBackend.when('GET', `/api/Dms/${dmsId}`).respond(expectedResponse);
|
||
|
$httpBackend.expect('GET', `/api/Dms/${dmsId}`).respond(expectedResponse);
|
||
|
controller.setDefaultParams();
|
||
|
$httpBackend.flush();
|
||
|
|
||
|
expect(controller.dms).toBeDefined();
|
||
|
expect(controller.dms.reference).toEqual(101);
|
||
|
expect(controller.dms.dmsTypeId).toEqual(12);
|
||
|
});
|
||
|
});
|
||
|
|
||
|
describe('onFileChange()', () => {
|
||
|
it('should set dms hasFileAttached property to true if has any files', () => {
|
||
|
const files = [{id: 1, name: 'MyFile'}];
|
||
|
controller.dms = {hasFileAttached: false};
|
||
|
controller.onFileChange(files);
|
||
|
$scope.$apply();
|
||
|
|
||
|
expect(controller.dms.hasFileAttached).toBeTruthy();
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
});
|