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

89 lines
3.1 KiB
JavaScript
Raw Normal View History

import './index.js';
describe('Item', () => {
describe('Component vnItemDescriptorPopover', () => {
let $componentController;
let $scope;
let controller;
let $httpBackend;
let $element;
beforeEach(() => {
angular.mock.module('item');
});
beforeEach(angular.mock.inject((_$componentController_, $rootScope, _$httpBackend_) => {
$componentController = _$componentController_;
$element = angular.element('<vn-item-descriptor-popover></vn-item-descriptor-popover>');
$httpBackend = _$httpBackend_;
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
$scope = $rootScope.$new();
controller = $componentController('vnItemDescriptorPopover', {$scope, $element, $httpBackend});
controller.itemFk = 1;
controller.parent = 'mariano';
controller.$.popover = {show: () => {}};
}));
describe('itemFk setter', () => {
it(`should set _itemFk to a given value and call getCard if the given value is not null`, () => {
spyOn(controller, 'getCard');
controller.itemFk = 5;
expect(controller.getCard).toHaveBeenCalledWith();
expect(controller._itemFk).toEqual(5);
});
it(`shoud call clear if the given values is null`, () => {
spyOn(controller, 'clear');
controller.itemFk = null;
expect(controller.clear).toHaveBeenCalledWith();
expect(controller._itemFk).toEqual(null);
});
});
describe('quicklinks setter', () => {
it(`shoud set _quicklinks to a given value`, () => {
2018-08-09 10:47:22 +00:00
controller.quicklinks = 3;
expect(controller._quicklinks).toEqual(3);
});
});
describe('clear()', () => {
it(`should set item and itemTags null, and tags {}`, () => {
controller.item = '1';
controller.itemTags = '1';
controller.tags = '1';
controller.clear();
expect(controller.item).toEqual(null);
expect(controller.itemTags).toEqual(null);
expect(controller.tags).toEqual({});
});
});
describe('show()', () => {
it(`should set $.popover.parent and call $.popover.show`, () => {
spyOn(controller.$.popover, 'show');
controller.show();
expect(controller.$.popover.show).toHaveBeenCalledWith();
expect(controller.$.popover.parent).toEqual('mariano');
});
});
describe('getCard()', () => {
it(`should make a query and set this.item`, () => {
$httpBackend.whenGET(`/item/api/Items/1/getCard`).respond(true);
$httpBackend.expectGET(`/item/api/Items/1/getCard`);
controller.getCard();
$httpBackend.flush();
expect(controller.item).toEqual(true);
});
});
});
});