2018-08-08 12:38:50 +00:00
|
|
|
import './index.js';
|
|
|
|
|
|
|
|
describe('Item', () => {
|
|
|
|
describe('Component vnItemDescriptorPopover', () => {
|
2018-10-18 09:41:25 +00:00
|
|
|
let $httpBackend;
|
2018-08-08 12:38:50 +00:00
|
|
|
let $scope;
|
|
|
|
let controller;
|
|
|
|
let $element;
|
2018-10-18 09:41:25 +00:00
|
|
|
let $timeout;
|
2018-08-08 12:38:50 +00:00
|
|
|
|
2019-09-13 14:09:14 +00:00
|
|
|
beforeEach(angular.mock.module('item', $translateProvider => {
|
|
|
|
$translateProvider.translations('en', {});
|
|
|
|
}));
|
2018-08-08 12:38:50 +00:00
|
|
|
|
2018-12-22 10:59:26 +00:00
|
|
|
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$timeout_) => {
|
2018-08-08 12:38:50 +00:00
|
|
|
$httpBackend = _$httpBackend_;
|
2018-10-18 09:41:25 +00:00
|
|
|
$timeout = _$timeout_;
|
|
|
|
$element = angular.element(`<div></div>`);
|
2018-08-08 12:38:50 +00:00
|
|
|
$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('vnItemDescriptorPopover', {$scope, $element});
|
2018-08-08 12:38:50 +00:00
|
|
|
}));
|
|
|
|
|
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;
|
2018-09-14 11:43:51 +00:00
|
|
|
spyOn(controller, 'getCard');
|
2018-10-18 09:41:25 +00:00
|
|
|
controller.itemFk = 1;
|
2018-08-08 12:38:50 +00:00
|
|
|
|
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-08-08 12:38:50 +00:00
|
|
|
});
|
|
|
|
|
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-08-08 12:38:50 +00:00
|
|
|
|
2018-10-18 09:41:25 +00:00
|
|
|
expect(controller.item).toBeNull();
|
|
|
|
expect(controller._itemFk).toEqual(999);
|
|
|
|
expect(controller.getCard).toHaveBeenCalledWith();
|
2018-08-08 12:38:50 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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-08-08 12:38:50 +00:00
|
|
|
|
2018-10-18 09:41:25 +00:00
|
|
|
expect(controller._item).toEqual(`i'm the item!`);
|
|
|
|
expect(controller.$.popover.relocate).toHaveBeenCalledWith();
|
2018-08-08 12:38:50 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('show()', () => {
|
2018-10-18 09:41:25 +00:00
|
|
|
it(`should call the show()`, () => {
|
2018-08-08 12:38:50 +00:00
|
|
|
spyOn(controller.$.popover, 'show');
|
|
|
|
controller.show();
|
|
|
|
|
|
|
|
expect(controller.$.popover.show).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-09-14 11:43:51 +00:00
|
|
|
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`);
|
2018-09-14 11:43:51 +00:00
|
|
|
controller.getCard();
|
2018-08-08 12:38:50 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
2018-10-18 09:41:25 +00:00
|
|
|
expect(controller.item).toEqual(response);
|
2018-08-08 12:38:50 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|