salix/client/item/src/descriptor-popover/index.spec.js

86 lines
3.2 KiB
JavaScript
Raw Normal View History

import './index.js';
describe('Item', () => {
describe('Component vnItemDescriptorPopover', () => {
let $componentController;
2018-10-18 09:41:25 +00:00
let $httpBackend;
let $scope;
let controller;
let $element;
2018-10-18 09:41:25 +00:00
let $timeout;
beforeEach(() => {
angular.mock.module('item');
});
2018-10-18 09:41:25 +00:00
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_, _$timeout_) => {
$componentController = _$componentController_;
$httpBackend = _$httpBackend_;
2018-10-18 09:41:25 +00:00
$timeout = _$timeout_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
2018-10-18 09:41:25 +00:00
$element = angular.element(`<div></div>`);
$scope = $rootScope.$new();
2018-10-18 09:41:25 +00:00
$scope.popover = {relocate: () => {}, show: () => {}};
controller = $componentController('vnItemDescriptorPopover', {$scope: $scope, $element: $element});
}));
2018-10-18 09:41:25 +00:00
describe('itemFk()', () => {
it(`should not apply any changes if the received id is the same stored in _itemFk`, () => {
controller.item = 'I exist!';
controller._itemFk = 1;
spyOn(controller, 'getCard');
2018-10-18 09:41:25 +00:00
controller.itemFk = 1;
2018-10-18 09:41:25 +00:00
expect(controller.item).toEqual('I exist!');
expect(controller._itemFk).toEqual(1);
expect(controller.getCard).not.toHaveBeenCalled();
});
2018-10-18 09:41:25 +00:00
it(`should set the received id into _itemFk, set the item to null and then call getCard()`, () => {
controller.item = `Please don't`;
controller._itemFk = 1;
spyOn(controller, 'getCard');
controller.itemFk = 999;
2018-10-18 09:41:25 +00:00
expect(controller.item).toBeNull();
expect(controller._itemFk).toEqual(999);
expect(controller.getCard).toHaveBeenCalledWith();
});
});
2018-10-18 09:41:25 +00:00
describe('item()', () => {
it(`should save the item into _item and then call relocate()`, () => {
spyOn(controller.$.popover, 'relocate');
controller.item = `i'm the item!`;
$timeout.flush();
2018-10-18 09:41:25 +00:00
expect(controller._item).toEqual(`i'm the item!`);
expect(controller.$.popover.relocate).toHaveBeenCalledWith();
});
});
describe('show()', () => {
2018-10-18 09:41:25 +00:00
it(`should call the show()`, () => {
spyOn(controller.$.popover, 'show');
controller.show();
expect(controller.$.popover.show).toHaveBeenCalledWith();
});
});
describe('getCard()', () => {
2018-10-18 09:41:25 +00:00
it(`should perform a get query to store the item data into the controller`, () => {
controller.itemFk = 1;
controller.canceler = null;
let response = {};
$httpBackend.when('GET', `/item/api/Items/${controller._itemFk}/getCard`).respond(response);
$httpBackend.expect('GET', `/item/api/Items/${controller._itemFk}/getCard`);
controller.getCard();
$httpBackend.flush();
2018-10-18 09:41:25 +00:00
expect(controller.item).toEqual(response);
});
});
});
});