66 lines
2.4 KiB
JavaScript
66 lines
2.4 KiB
JavaScript
|
import './index';
|
||
|
|
||
|
describe('Ticket', () => {
|
||
|
describe('Component vnTicketDmsCreate', () => {
|
||
|
let controller;
|
||
|
let $scope;
|
||
|
let $httpBackend;
|
||
|
let $httpParamSerializer;
|
||
|
|
||
|
beforeEach(ngModule('ticket'));
|
||
|
|
||
|
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
|
||
|
$scope = $rootScope.$new();
|
||
|
$httpBackend = _$httpBackend_;
|
||
|
$httpParamSerializer = _$httpParamSerializer_;
|
||
|
controller = $componentController('vnTicketDmsCreate', {$scope});
|
||
|
controller._ticket = {
|
||
|
id: 15,
|
||
|
client: {id: 101, name: 'Bruce wayne'},
|
||
|
warehouseFk: 1,
|
||
|
companyFk: 1
|
||
|
};
|
||
|
}));
|
||
|
|
||
|
describe('client() setter', () => {
|
||
|
it('should set the ticket data and then call setDefaultParams()', () => {
|
||
|
spyOn(controller, 'setDefaultParams');
|
||
|
controller.ticket = {
|
||
|
id: 15,
|
||
|
name: 'Bruce wayne'
|
||
|
};
|
||
|
|
||
|
expect(controller.ticket).toBeDefined();
|
||
|
expect(controller.setDefaultParams).toHaveBeenCalledWith();
|
||
|
});
|
||
|
});
|
||
|
|
||
|
describe('setDefaultParams()', () => {
|
||
|
it('should perform a GET query and define the dms property on controller', () => {
|
||
|
const params = {filter: {
|
||
|
where: {code: 'ticket'}
|
||
|
}};
|
||
|
let serializedParams = $httpParamSerializer(params);
|
||
|
$httpBackend.when('GET', `/api/DmsTypes/findOne?${serializedParams}`).respond({id: 14, code: 'ticket'});
|
||
|
$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 hasFile property to true if has any files', () => {
|
||
|
const files = [{id: 1, name: 'MyFile'}];
|
||
|
controller.onFileChange(files);
|
||
|
$scope.$apply();
|
||
|
|
||
|
expect(controller.dms.hasFile).toBeTruthy();
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
});
|