salix/modules/account/front/alias/users/index.spec.js

43 lines
1.3 KiB
JavaScript

import './index';
describe('component vnAliasUsers', () => {
let controller;
let $httpBackend;
beforeEach(ngModule('account'));
beforeEach(inject(($componentController, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
controller = $componentController('vnAliasUsers', {$element: null});
controller.$params.id = 1;
}));
describe('$onInit()', () => {
it('should delete entity and go to index', () => {
$httpBackend.expectGET('MailAliases/1/accounts').respond('foo');
controller.$onInit();
$httpBackend.flush();
expect(controller.$.data).toBe('foo');
});
});
describe('onRemove()', () => {
it('should call backend method to change role', () => {
jest.spyOn(controller.vnApp, 'showSuccess');
controller.$.data = [
{id: 1, alias: 'foo'},
{id: 2, alias: 'bar'}
];
$httpBackend.expectDELETE('MailAliases/1/accounts/1').respond();
controller.onRemove(controller.$.data[0]);
$httpBackend.flush();
expect(controller.$.data).toEqual([{id: 2, alias: 'bar'}]);
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
});
});
});