2018-08-08 12:38:50 +00:00
|
|
|
import './index.js';
|
|
|
|
|
|
|
|
describe('Item', () => {
|
|
|
|
describe('Component vnItemDescriptorPopover', () => {
|
|
|
|
let $componentController;
|
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
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
angular.mock.module('item');
|
|
|
|
});
|
|
|
|
|
2018-10-18 09:41:25 +00:00
|
|
|
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_, _$timeout_) => {
|
2018-08-08 12:38:50 +00:00
|
|
|
$componentController = _$componentController_;
|
|
|
|
$httpBackend = _$httpBackend_;
|
2018-10-18 09:41:25 +00:00
|
|
|
$timeout = _$timeout_;
|
2018-08-08 12:38:50 +00:00
|
|
|
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
|
2018-10-18 09:41:25 +00:00
|
|
|
$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: () => {}};
|
|
|
|
controller = $componentController('vnItemDescriptorPopover', {$scope: $scope, $element: $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
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|