2018-08-14 07:12:28 +00:00
|
|
|
import './index';
|
|
|
|
|
|
|
|
describe('Client', () => {
|
|
|
|
describe('Component vnClientDescriptorPopover', () => {
|
|
|
|
let $httpBackend;
|
|
|
|
let $scope;
|
|
|
|
let controller;
|
|
|
|
let $element;
|
2018-10-18 09:41:25 +00:00
|
|
|
let $timeout;
|
2018-08-14 07:12:28 +00:00
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('client'));
|
2018-08-14 07:12:28 +00:00
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$timeout_) => {
|
2018-08-14 07:12:28 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
2018-10-18 09:41:25 +00:00
|
|
|
$timeout = _$timeout_;
|
2018-08-14 07:12:28 +00:00
|
|
|
$element = angular.element(`<div></div>`);
|
|
|
|
$scope = $rootScope.$new();
|
2018-10-18 09:41:25 +00:00
|
|
|
$scope.popover = {relocate: () => {}, show: () => {}};
|
2018-12-22 10:59:26 +00:00
|
|
|
controller = $componentController('vnClientDescriptorPopover', {$scope, $element});
|
2018-08-14 07:12:28 +00:00
|
|
|
}));
|
|
|
|
|
2018-10-18 09:41:25 +00:00
|
|
|
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;
|
|
|
|
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;
|
|
|
|
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()`, () => {
|
|
|
|
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()`, () => {
|
|
|
|
spyOn(controller.$.popover, 'show');
|
|
|
|
controller.show();
|
|
|
|
|
|
|
|
expect(controller.$.popover.show).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-09-14 11:43:51 +00:00
|
|
|
describe('getCard()', () => {
|
2018-08-14 07:12:28 +00:00
|
|
|
it(`should perform a get query to store the client data into the controller`, () => {
|
2018-10-18 09:41:25 +00:00
|
|
|
controller.clientFk = 1;
|
|
|
|
controller.canceler = null;
|
|
|
|
let response = {};
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.when('GET', `Clients/${controller._clientFk}/getCard`).respond(response);
|
|
|
|
$httpBackend.expect('GET', `Clients/${controller._clientFk}/getCard`);
|
2018-10-18 09:41:25 +00:00
|
|
|
controller.getCard();
|
2018-08-14 07:12:28 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.client).toEqual(response);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|