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

41 lines
1.5 KiB
JavaScript

import './index';
import crudModel from 'core/mocks/crud-model';
describe('Worker', () => {
describe('Component vnWorkerDmsIndex', () => {
let $scope;
let $element;
let $httpBackend;
let controller;
beforeEach(ngModule('worker'));
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
$scope = $rootScope.$new();
$element = angular.element(`<vn-worker-dms-index></vn-worker-dms-index`);
controller = $componentController('vnWorkerDmsIndex', {$element, $scope});
controller.$.model = crudModel;
}));
describe('deleteDms()', () => {
it('should make an HTTP Post query', () => {
const workerDmsId = 1;
const dmsIndex = 0;
jest.spyOn(controller.vnApp, 'showSuccess');
jest.spyOn(controller.$.model, 'remove');
controller.workerDms = [{id: 1, dmsFk: 4}];
controller.dmsIndex = dmsIndex;
$httpBackend.when('POST', `WorkerDms/${workerDmsId}/removeFile`).respond({});
$httpBackend.expect('POST', `WorkerDms/${workerDmsId}/removeFile`);
controller.deleteDms('accept');
$httpBackend.flush();
expect(controller.$.model.remove).toHaveBeenCalledWith(dmsIndex);
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
});
});
});
});