import './index'; describe('Client', () => { describe('Component vnClientDescriptorPopover', () => { let $httpBackend; let $scope; let controller; let $element; let $timeout; beforeEach(ngModule('client')); beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$timeout_) => { $httpBackend = _$httpBackend_; $timeout = _$timeout_; $element = angular.element(`
`); $scope = $rootScope.$new(); $scope.popover = {relocate: () => {}, show: () => {}}; controller = $componentController('vnClientDescriptorPopover', {$scope, $element}); })); describe('clientFk()', () => { it(`should not apply any changes if the received id is the same stored in _clientFk`, () => { controller.client = 'I exist!'; controller._clientFk = 1; jest.spyOn(controller, 'getCard'); controller.clientFk = 1; expect(controller.client).toEqual('I exist!'); expect(controller._clientFk).toEqual(1); expect(controller.getCard).not.toHaveBeenCalled(); }); it(`should set the received id into _clientFk, set the client to null and then call getCard()`, () => { controller.client = `Please don't`; controller._clientFk = 1; jest.spyOn(controller, 'getCard'); controller.clientFk = 999; expect(controller.client).toBeNull(); expect(controller._clientFk).toEqual(999); expect(controller.getCard).toHaveBeenCalledWith(); }); }); describe('client()', () => { it(`should save the client into _client and then call relocate()`, () => { jest.spyOn(controller.$.popover, 'relocate'); controller.client = `i'm the client!`; $timeout.flush(); expect(controller._client).toEqual(`i'm the client!`); expect(controller.$.popover.relocate).toHaveBeenCalledWith(); }); }); describe('show()', () => { it(`should call the show()`, () => { jest.spyOn(controller.$.popover, 'show'); controller.show(); expect(controller.$.popover.show).toHaveBeenCalledWith(); }); }); describe('getCard()', () => { it(`should perform a get query to store the client data into the controller`, () => { controller.clientFk = 1; controller.canceler = null; let response = {}; $httpBackend.when('GET', `Clients/${controller._clientFk}/getCard`).respond(response); $httpBackend.expect('GET', `Clients/${controller._clientFk}/getCard`); controller.getCard(); $httpBackend.flush(); expect(controller.client).toEqual(response); }); }); }); });