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-11 11:22:54 +00:00
|
|
|
controller.$params = {id: 1};
|
2020-03-09 08:00:03 +00:00
|
|
|
|
2023-07-11 11:22:54 +00:00
|
|
|
$httpBackend.expectPOST('VnUsers/1/addAlias').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-11 11:22:54 +00:00
|
|
|
controller.$params = {id: 1};
|
2020-03-09 08:00:03 +00:00
|
|
|
|
2023-07-11 11:22:54 +00:00
|
|
|
$httpBackend.expectPOST('VnUsers/1/removeAlias').respond();
|
|
|
|
$httpBackend.expectGET('MailAliasAccounts').respond(controller.$.data[1]);
|
2020-03-09 08:00:03 +00:00
|
|
|
controller.onRemove(controller.$.data[0]);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
2023-07-11 11:22:54 +00:00
|
|
|
expect(controller.$.data).toEqual({id: 2, alias: 'bar'});
|
2020-03-09 08:00:03 +00:00
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|