2019-07-15 09:40:11 +00:00
|
|
|
import './index';
|
|
|
|
|
|
|
|
describe('Client', () => {
|
2019-08-08 06:37:03 +00:00
|
|
|
describe('Component vnClientDmsEdit', () => {
|
2019-07-15 09:40:11 +00:00
|
|
|
let controller;
|
|
|
|
let $scope;
|
|
|
|
let $httpBackend;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('client'));
|
2019-07-15 09:40:11 +00:00
|
|
|
|
2020-07-23 14:46:16 +00:00
|
|
|
beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => {
|
2019-07-15 09:40:11 +00:00
|
|
|
$scope = $rootScope.$new();
|
|
|
|
$httpBackend = _$httpBackend_;
|
2020-03-17 10:17:50 +00:00
|
|
|
const $element = angular.element('<vn-client-dms-edit></vn-client-dms-edit>');
|
|
|
|
controller = $componentController('vnClientDmsEdit', {$element, $scope});
|
2019-08-08 06:37:03 +00:00
|
|
|
controller._client = {id: 1};
|
2020-03-17 10:17:50 +00:00
|
|
|
controller.$params = {dmsId: 1};
|
2019-07-15 09:40:11 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
describe('client() setter', () => {
|
2019-08-08 06:37:03 +00:00
|
|
|
it('should set the client data and then call setDefaultParams() and getAllowedContentTypes()', () => {
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(controller, 'setDefaultParams');
|
|
|
|
jest.spyOn(controller, 'getAllowedContentTypes');
|
2019-08-08 06:37:03 +00:00
|
|
|
controller._client = undefined;
|
2019-07-15 09:40:11 +00:00
|
|
|
controller.client = {
|
2019-08-08 06:37:03 +00:00
|
|
|
id: 15
|
2019-07-15 09:40:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
expect(controller.setDefaultParams).toHaveBeenCalledWith();
|
2019-08-08 06:37:03 +00:00
|
|
|
expect(controller.client).toBeDefined();
|
|
|
|
expect(controller.getAllowedContentTypes).toHaveBeenCalledWith();
|
2019-07-15 09:40:11 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setDefaultParams()', () => {
|
|
|
|
it('should perform a GET query and define the dms property on controller', () => {
|
2019-08-08 06:37:03 +00:00
|
|
|
const dmsId = 1;
|
|
|
|
const expectedResponse = {
|
2021-06-23 11:24:23 +00:00
|
|
|
reference: 1101,
|
2019-08-08 06:37:03 +00:00
|
|
|
warehouseFk: 1,
|
|
|
|
companyFk: 442,
|
|
|
|
dmsTypeFk: 12,
|
|
|
|
description: 'Test',
|
|
|
|
hasFile: false,
|
|
|
|
hasFileAttached: false
|
|
|
|
};
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.expect('GET', `Dms/${dmsId}`).respond(expectedResponse);
|
2019-07-15 09:40:11 +00:00
|
|
|
controller.setDefaultParams();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.dms).toBeDefined();
|
2021-06-23 11:24:23 +00:00
|
|
|
expect(controller.dms.reference).toEqual(1101);
|
2019-07-15 09:40:11 +00:00
|
|
|
expect(controller.dms.dmsTypeId).toEqual(12);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onFileChange()', () => {
|
2019-07-16 12:12:58 +00:00
|
|
|
it('should set dms hasFileAttached property to true if has any files', () => {
|
2019-07-15 09:40:11 +00:00
|
|
|
const files = [{id: 1, name: 'MyFile'}];
|
2019-08-08 06:37:03 +00:00
|
|
|
controller.dms = {hasFileAttached: false};
|
2019-07-15 09:40:11 +00:00
|
|
|
controller.onFileChange(files);
|
|
|
|
$scope.$apply();
|
|
|
|
|
2019-07-16 12:12:58 +00:00
|
|
|
expect(controller.dms.hasFileAttached).toBeTruthy();
|
2019-07-15 09:40: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'];
|
2020-12-18 17:02:41 +00:00
|
|
|
$httpBackend.expect('GET', `DmsContainers/allowedContentTypes`).respond(expectedResponse);
|
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-07-15 09:40:11 +00:00
|
|
|
});
|
|
|
|
});
|