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

40 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-07-30 06:51:38 +00:00
import './index';
import crudModel from 'core/mocks/crud-model';
describe('Client', () => {
describe('Component vnClientDmsIndex', () => {
let $scope;
let $httpBackend;
let controller;
beforeEach(ngModule('client'));
2019-07-30 06:51:38 +00:00
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => {
2019-07-30 06:51:38 +00:00
$httpBackend = _$httpBackend_;
$scope = $rootScope.$new();
2020-03-17 10:17:50 +00:00
const $element = angular.element('<vn-client-dms-index></vn-client-dms-index>');
controller = $componentController('vnClientDmsIndex', {$element, $scope});
2019-07-30 06:51:38 +00:00
controller.$.model = crudModel;
}));
describe('deleteDms()', () => {
it('should make an HTTP Post query', () => {
const dmsId = 1;
const dmsIndex = 0;
2020-02-26 12:22:52 +00:00
jest.spyOn(controller.vnApp, 'showSuccess');
jest.spyOn(controller.$.model, 'remove');
2019-07-30 06:51:38 +00:00
controller.clientDms = [{dmsFk: 1}];
controller.dmsIndex = dmsIndex;
$httpBackend.when('POST', `clientDms/${dmsId}/removeFile`).respond({});
$httpBackend.expect('POST', `clientDms/${dmsId}/removeFile`);
2019-10-30 15:57:14 +00:00
controller.deleteDms('accept');
2019-07-30 06:51:38 +00:00
$httpBackend.flush();
expect(controller.$.model.remove).toHaveBeenCalledWith(dmsIndex);
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
});
});
});
});