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

43 lines
1.6 KiB
JavaScript
Raw Normal View History

2019-11-22 09:42:05 +00:00
import './index';
import crudModel from 'core/mocks/crud-model';
2019-11-25 08:17:24 +00:00
describe('Worker', () => {
describe('Component vnWorkerDmsIndex', () => {
2019-11-22 09:42:05 +00:00
let $componentController;
let $scope;
2019-11-25 08:17:24 +00:00
let $element;
2019-11-22 09:42:05 +00:00
let $httpBackend;
let controller;
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_) => {
$componentController = _$componentController_;
$httpBackend = _$httpBackend_;
$scope = $rootScope.$new();
2019-11-25 08:17:24 +00:00
$element = angular.element(`<vn-worker-dms-index></vn-worker-dms-index`);
controller = $componentController('vnWorkerDmsIndex', {$element, $scope});
2019-11-22 09:42:05 +00:00
controller.$.model = crudModel;
}));
describe('deleteDms()', () => {
it('should make an HTTP Post query', () => {
2020-03-02 06:57:33 +00:00
const workerDmsId = 1;
2019-11-22 09:42:05 +00:00
const dmsIndex = 0;
2020-02-26 12:22:52 +00:00
jest.spyOn(controller.vnApp, 'showSuccess');
jest.spyOn(controller.$.model, 'remove');
2020-03-02 06:57:33 +00:00
controller.workerDms = [{id: 1, dmsFk: 4}];
2019-11-22 09:42:05 +00:00
controller.dmsIndex = dmsIndex;
2020-03-02 06:57:33 +00:00
$httpBackend.when('POST', `WorkerDms/${workerDmsId}/removeFile`).respond({});
$httpBackend.expect('POST', `WorkerDms/${workerDmsId}/removeFile`);
2019-11-22 09:42:05 +00:00
controller.deleteDms('accept');
$httpBackend.flush();
expect(controller.$.model.remove).toHaveBeenCalledWith(dmsIndex);
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
});
});
});
});