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