salix/modules/account/front/role/subroles/index.spec.js

54 lines
1.6 KiB
JavaScript

import './index';
describe('component vnRoleSubroles', () => {
let controller;
let $httpBackend;
beforeEach(ngModule('account'));
beforeEach(inject(($componentController, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
controller = $componentController('vnRoleSubroles', {$element: null});
jest.spyOn(controller.vnApp, 'showSuccess');
}));
describe('refresh()', () => {
it('should delete entity and go to index', () => {
$httpBackend.expectGET('RoleInherits').respond('foo');
controller.refresh();
$httpBackend.flush();
expect(controller.$.data).toBe('foo');
});
});
describe('onAddSave()', () => {
it('should add a subrole', () => {
controller.addData = {role: 'foo'};
$httpBackend.expectPOST('RoleInherits', {role: 'foo'}).respond();
$httpBackend.expectGET('RoleInherits').respond();
controller.onAddSave();
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
});
});
describe('onRemove()', () => {
it('should remove a subrole', () => {
controller.$.data = [
{id: 1, name: 'foo'},
{id: 2, name: 'bar'}
];
$httpBackend.expectDELETE('RoleInherits/1').respond();
controller.onRemove(controller.$.data[0]);
$httpBackend.flush();
expect(controller.$.data).toEqual([{id: 2, name: 'bar'}]);
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
});
});
});