salix/modules/account/front/aliases/index.spec.js

54 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

import './index';
describe('component vnUserAliases', () => {
let controller;
let $httpBackend;
beforeEach(ngModule('account'));
beforeEach(inject(($componentController, _$httpBackend_) => {
$httpBackend = _$httpBackend_;
controller = $componentController('vnUserAliases', {$element: null});
jest.spyOn(controller.vnApp, 'showSuccess');
}));
describe('refresh()', () => {
it('should refresh the controller data', () => {
$httpBackend.expectGET('MailAliasAccounts').respond('foo');
controller.refresh();
$httpBackend.flush();
expect(controller.$.data).toBe('foo');
});
});
describe('onAddSave()', () => {
it('should add the new row', () => {
controller.addData = {account: 1};
2023-07-12 13:07:06 +00:00
$httpBackend.expectPOST('MailAliasAccounts').respond();
$httpBackend.expectGET('MailAliasAccounts').respond('foo');
controller.onAddSave();
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
});
});
describe('onRemove()', () => {
it('shoud remove the passed row remote and locally', () => {
controller.$.data = [
{id: 1, alias: 'foo'},
{id: 2, alias: 'bar'}
];
2023-07-12 13:07:06 +00:00
$httpBackend.expectDELETE('MailAliasAccounts/1').respond();
controller.onRemove(controller.$.data[0]);
$httpBackend.flush();
2023-07-12 13:07:06 +00:00
expect(controller.$.data).toEqual([{id: 2, alias: 'bar'}]);
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
});
});
});