salix/modules/worker/front/dms/create/index.spec.js

77 lines
3.1 KiB
JavaScript
Raw Normal View History

2019-11-22 09:42:05 +00:00
import './index';
describe('Client', () => {
2019-11-22 13:34:20 +00:00
describe('Component vnWorkerDmsCreate', () => {
let $element;
2019-11-22 09:42:05 +00:00
let controller;
let $scope;
let $httpBackend;
let $httpParamSerializer;
2019-11-22 13:34:20 +00:00
beforeEach(ngModule('worker'));
2019-11-22 09:42:05 +00:00
2020-07-23 14:46:16 +00:00
beforeEach(inject(($compile, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
2019-11-22 09:42:05 +00:00
$scope = $rootScope.$new();
$httpBackend = _$httpBackend_;
$httpParamSerializer = _$httpParamSerializer_;
2019-11-22 13:34:20 +00:00
$element = $compile(`<vn-worker-dms-create></vn-worker-dms-create>`)($rootScope);
controller = $element.controller('vnWorkerDmsCreate');
controller._worker = {id: 101, name: 'Bruce wayne'};
2019-11-22 09:42:05 +00:00
}));
2019-11-22 13:34:20 +00:00
describe('worker() setter', () => {
it('should set the worker data and then call setDefaultParams() and getAllowedContentTypes()', () => {
2020-02-26 12:22:52 +00:00
jest.spyOn(controller, 'setDefaultParams');
jest.spyOn(controller, 'getAllowedContentTypes');
2019-11-22 13:34:20 +00:00
controller.worker = {
2019-11-22 09:42:05 +00:00
id: 15,
name: 'Bruce wayne'
};
2019-11-22 13:34:20 +00:00
expect(controller.worker).toBeDefined();
2019-11-22 09:42:05 +00:00
expect(controller.setDefaultParams).toHaveBeenCalledWith();
expect(controller.getAllowedContentTypes).toHaveBeenCalledWith();
});
});
describe('setDefaultParams()', () => {
it('should perform a GET query and define the dms property on controller', () => {
2019-11-22 13:34:20 +00:00
$httpBackend.whenRoute('GET', `DmsTypes`).respond({id: 12, code: 'hhrrData'});
2019-11-22 09:42:05 +00:00
const params = {filter: {
2019-11-22 13:34:20 +00:00
where: {code: 'hhrrData'}
2019-11-22 09:42:05 +00:00
}};
let serializedParams = $httpParamSerializer(params);
2019-11-22 13:34:20 +00:00
$httpBackend.when('GET', `DmsTypes/findOne?${serializedParams}`).respond({id: 12, code: 'hhrrData'});
2019-11-22 09:42:05 +00:00
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.expect('GET', `workerDms/allowedContentTypes`).respond(expectedResponse);
2019-11-22 09:42:05 +00:00
controller.getAllowedContentTypes();
$httpBackend.flush();
expect(controller.allowedContentTypes).toBeDefined();
expect(controller.allowedContentTypes).toEqual('image/png, image/jpg');
});
});
});
});