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

83 lines
3.2 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;
2019-09-13 14:09:14 +00:00
beforeEach(angular.mock.module('client', $translateProvider => {
$translateProvider.translations('en', {});
}));
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;
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();
});
});
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', `/client/api/Clients/${controller._clientFk}/getCard`).respond(response);
$httpBackend.expect('GET', `/client/api/Clients/${controller._clientFk}/getCard`);
controller.getCard();
$httpBackend.flush();
expect(controller.client).toEqual(response);
});
});
});
});