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

85 lines
3.3 KiB
JavaScript
Raw Normal View History

2019-11-22 09:42:05 +00:00
import './index';
2019-11-25 08:17:24 +00:00
describe('Worker', () => {
2019-11-22 09:42:05 +00:00
describe('Component vnClientDmsEdit', () => {
let controller;
let $scope;
2019-11-25 08:17:24 +00:00
let $element;
2019-11-22 09:42:05 +00:00
let $httpBackend;
2019-11-25 08:17:24 +00:00
beforeEach(ngModule('worker'));
2019-11-22 09:42:05 +00:00
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => {
$scope = $rootScope.$new();
$httpBackend = _$httpBackend_;
2019-11-25 08:17:24 +00:00
$element = angular.element(`<vn-worker-dms-edit></vn-worker-dms-edit`);
controller = $componentController('vnWorkerDmsEdit', {$element, $scope});
controller._worker = {id: 106};
controller.$params = {dmsId: 4};
2019-11-22 09:42:05 +00:00
}));
2019-11-25 08:17:24 +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-25 08:17:24 +00:00
controller._worker = undefined;
controller.worker = {
id: 106
2019-11-22 09:42:05 +00:00
};
expect(controller.setDefaultParams).toHaveBeenCalledWith();
2019-11-25 08:17:24 +00:00
expect(controller.worker).toBeDefined();
2019-11-22 09:42:05 +00:00
expect(controller.getAllowedContentTypes).toHaveBeenCalledWith();
});
});
describe('setDefaultParams()', () => {
it('should perform a GET query and define the dms property on controller', () => {
2019-11-25 08:17:24 +00:00
const dmsId = 4;
2019-11-22 09:42:05 +00:00
const expectedResponse = {
reference: 101,
warehouseFk: 1,
companyFk: 442,
2019-11-25 08:17:24 +00:00
dmsTypeFk: 3,
2019-11-22 09:42:05 +00:00
description: 'Test',
hasFile: false,
hasFileAttached: false
};
$httpBackend.when('GET', `Dms/${dmsId}`).respond(expectedResponse);
$httpBackend.expect('GET', `Dms/${dmsId}`).respond(expectedResponse);
controller.setDefaultParams();
$httpBackend.flush();
expect(controller.dms).toBeDefined();
expect(controller.dms.reference).toEqual(101);
2019-11-25 08:17:24 +00:00
expect(controller.dms.dmsTypeId).toEqual(3);
2019-11-22 09:42:05 +00:00
});
});
describe('onFileChange()', () => {
it('should set dms hasFileAttached property to true if has any files', () => {
const files = [{id: 1, name: 'MyFile'}];
controller.dms = {hasFileAttached: false};
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'];
2019-11-25 08:17:24 +00:00
$httpBackend.when('GET', `WorkerDms/allowedContentTypes`).respond(expectedResponse);
$httpBackend.expect('GET', `WorkerDms/allowedContentTypes`);
2019-11-22 09:42:05 +00:00
controller.getAllowedContentTypes();
$httpBackend.flush();
expect(controller.allowedContentTypes).toBeDefined();
expect(controller.allowedContentTypes).toEqual('image/png, image/jpg');
});
});
});
});