salix/modules/client/front/descriptor-popover/index.spec.js

81 lines
3.1 KiB
JavaScript
Raw Normal View History

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;
beforeEach(ngModule('client'));
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$timeout_) => {
$httpBackend = _$httpBackend_;
2018-10-18 09:41:25 +00:00
$timeout = _$timeout_;
$element = angular.element(`<div></div>`);
$scope = $rootScope.$new();
2018-10-18 09:41:25 +00:00
$scope.popover = {relocate: () => {}, show: () => {}};
controller = $componentController('vnClientDescriptorPopover', {$scope, $element});
}));
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;
2020-02-26 12:22:52 +00:00
jest.spyOn(controller, 'getCard');
2018-10-18 09:41:25 +00:00
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;
2020-02-26 12:22:52 +00:00
jest.spyOn(controller, 'getCard');
2018-10-18 09:41:25 +00:00
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()`, () => {
2020-02-26 12:22:52 +00:00
jest.spyOn(controller.$.popover, 'relocate');
2018-10-18 09:41:25 +00:00
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()`, () => {
2020-02-26 12:22:52 +00:00
jest.spyOn(controller.$.popover, 'show');
2018-10-18 09:41:25 +00:00
controller.show();
expect(controller.$.popover.show).toHaveBeenCalledWith();
});
});
describe('getCard()', () => {
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 = {};
$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();
$httpBackend.flush();
expect(controller.client).toEqual(response);
});
});
});
});