2019-06-06 11:59:11 +00:00
|
|
|
import './index';
|
|
|
|
|
|
|
|
describe('Ticket', () => {
|
|
|
|
describe('Component vnTicketDmsCreate', () => {
|
|
|
|
let controller;
|
|
|
|
let $scope;
|
|
|
|
let $httpBackend;
|
|
|
|
let $httpParamSerializer;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('ticket'));
|
2019-06-06 11:59:11 +00:00
|
|
|
|
|
|
|
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
|
|
|
|
$scope = $rootScope.$new();
|
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
$httpParamSerializer = _$httpParamSerializer_;
|
2020-03-18 07:35:59 +00:00
|
|
|
const $element = angular.element('<vn-ticket-dms-create></vn-ticket-dms-create>');
|
|
|
|
controller = $componentController('vnTicketDmsCreate', {$element});
|
2019-06-06 11:59:11 +00:00
|
|
|
controller._ticket = {
|
|
|
|
id: 15,
|
|
|
|
client: {id: 101, name: 'Bruce wayne'},
|
|
|
|
warehouseFk: 1,
|
|
|
|
companyFk: 1
|
|
|
|
};
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('client() setter', () => {
|
2019-08-08 06:37:03 +00:00
|
|
|
it('should set the ticket data and then call setDefaultParams() and getAllowedContentTypes()', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller, 'setDefaultParams');
|
|
|
|
jest.spyOn(controller, 'getAllowedContentTypes');
|
2019-06-06 11:59:11 +00:00
|
|
|
controller.ticket = {
|
|
|
|
id: 15,
|
|
|
|
name: 'Bruce wayne'
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(controller.ticket).toBeDefined();
|
|
|
|
expect(controller.setDefaultParams).toHaveBeenCalledWith();
|
2019-08-08 06:37:03 +00:00
|
|
|
expect(controller.getAllowedContentTypes).toHaveBeenCalledWith();
|
2019-06-06 11:59:11 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.when('GET', `DmsTypes/findOne?${serializedParams}`).respond({id: 14, code: 'ticket'});
|
|
|
|
$httpBackend.expect('GET', `DmsTypes/findOne?${serializedParams}`);
|
2019-06-06 11:59:11 +00:00
|
|
|
controller.setDefaultParams();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.dms).toBeDefined();
|
|
|
|
expect(controller.dms.reference).toEqual(15);
|
|
|
|
expect(controller.dms.dmsTypeId).toEqual(14);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onFileChange()', () => {
|
2019-07-16 12:12:58 +00:00
|
|
|
it('should set dms hasFileAttached property to true if has any files', () => {
|
2019-06-06 11:59:11 +00:00
|
|
|
const files = [{id: 1, name: 'MyFile'}];
|
|
|
|
controller.onFileChange(files);
|
|
|
|
$scope.$apply();
|
|
|
|
|
2019-07-16 12:12:58 +00:00
|
|
|
expect(controller.dms.hasFileAttached).toBeTruthy();
|
2019-06-06 11:59:11 +00:00
|
|
|
});
|
|
|
|
});
|
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'];
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.when('GET', `ticketDms/allowedContentTypes`).respond(expectedResponse);
|
|
|
|
$httpBackend.expect('GET', `ticketDms/allowedContentTypes`);
|
2019-08-08 06:37:03 +00:00
|
|
|
controller.getAllowedContentTypes();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.allowedContentTypes).toBeDefined();
|
|
|
|
expect(controller.allowedContentTypes).toEqual('image/png, image/jpg');
|
|
|
|
});
|
|
|
|
});
|
2019-06-06 11:59:11 +00:00
|
|
|
});
|
|
|
|
});
|