2020-03-09 08:00:03 +00:00
|
|
|
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();
|
2020-03-09 08:00:03 +00:00
|
|
|
$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();
|
2020-03-09 08:00:03 +00:00
|
|
|
controller.onRemove(controller.$.data[0]);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
2023-07-12 13:07:06 +00:00
|
|
|
expect(controller.$.data).toEqual([{id: 2, alias: 'bar'}]);
|
2020-03-09 08:00:03 +00:00
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|