78 lines
3.2 KiB
JavaScript
78 lines
3.2 KiB
JavaScript
import './index';
|
|
|
|
describe('Client', () => {
|
|
describe('Component vnWorkerDmsCreate', () => {
|
|
let $element;
|
|
let controller;
|
|
let $scope;
|
|
let $httpBackend;
|
|
let $httpParamSerializer;
|
|
|
|
beforeEach(ngModule('worker'));
|
|
|
|
beforeEach(angular.mock.inject(($compile, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
|
|
$scope = $rootScope.$new();
|
|
$httpBackend = _$httpBackend_;
|
|
$httpParamSerializer = _$httpParamSerializer_;
|
|
$element = $compile(`<vn-worker-dms-create></vn-worker-dms-create>`)($rootScope);
|
|
controller = $element.controller('vnWorkerDmsCreate');
|
|
controller._worker = {id: 101, name: 'Bruce wayne'};
|
|
}));
|
|
|
|
describe('worker() setter', () => {
|
|
it('should set the worker data and then call setDefaultParams() and getAllowedContentTypes()', () => {
|
|
jest.spyOn(controller, 'setDefaultParams');
|
|
jest.spyOn(controller, 'getAllowedContentTypes');
|
|
controller.worker = {
|
|
id: 15,
|
|
name: 'Bruce wayne'
|
|
};
|
|
|
|
expect(controller.worker).toBeDefined();
|
|
expect(controller.setDefaultParams).toHaveBeenCalledWith();
|
|
expect(controller.getAllowedContentTypes).toHaveBeenCalledWith();
|
|
});
|
|
});
|
|
|
|
describe('setDefaultParams()', () => {
|
|
it('should perform a GET query and define the dms property on controller', () => {
|
|
$httpBackend.whenRoute('GET', `DmsTypes`).respond({id: 12, code: 'hhrrData'});
|
|
const params = {filter: {
|
|
where: {code: 'hhrrData'}
|
|
}};
|
|
let serializedParams = $httpParamSerializer(params);
|
|
$httpBackend.when('GET', `DmsTypes/findOne?${serializedParams}`).respond({id: 12, code: 'hhrrData'});
|
|
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.onFileChange(files);
|
|
$scope.$apply();
|
|
|
|
expect(controller.dms.hasFileAttached).toBeTruthy();
|
|
});
|
|
});
|
|
|
|
describe('getAllowedContentTypes()', () => {
|
|
it('should make an HTTP GET request to get the allowed content types', () => {
|
|
const expectedResponse = ['image/png', 'image/jpg'];
|
|
$httpBackend.when('GET', `workerDms/allowedContentTypes`).respond(expectedResponse);
|
|
$httpBackend.expect('GET', `workerDms/allowedContentTypes`);
|
|
controller.getAllowedContentTypes();
|
|
$httpBackend.flush();
|
|
|
|
expect(controller.allowedContentTypes).toBeDefined();
|
|
expect(controller.allowedContentTypes).toEqual('image/png, image/jpg');
|
|
});
|
|
});
|
|
});
|
|
});
|