Merge branch 'dev' of https://git.verdnatura.es/salix into dev
This commit is contained in:
commit
262835041f
|
@ -3,9 +3,7 @@
|
|||
<vn-auto class="left-block">
|
||||
<vn-item-descriptor
|
||||
margin-medium-v
|
||||
item="$ctrl.item"
|
||||
item-tags="$ctrl.itemTags"
|
||||
tags="$ctrl.tags">
|
||||
item="$ctrl.item">
|
||||
</vn-item-descriptor>
|
||||
<vn-left-menu></vn-left-menu>
|
||||
</vn-auto>
|
||||
|
|
|
@ -1,73 +1,24 @@
|
|||
import ngModule from '../module';
|
||||
|
||||
class Controller {
|
||||
constructor($http, $state, $timeout) {
|
||||
constructor($http, $state) {
|
||||
this.$http = $http;
|
||||
this.$state = $state;
|
||||
this.$timeout = $timeout;
|
||||
|
||||
this.item = null;
|
||||
this.tags = {};
|
||||
this.itemTags = null;
|
||||
}
|
||||
|
||||
_getItemTags() {
|
||||
let filter = {
|
||||
where: {itemFk: this.$state.params.id},
|
||||
order: "priority ASC",
|
||||
include: {relation: "tag"}
|
||||
};
|
||||
this.$http.get(`/item/api/ItemTags?filter=${JSON.stringify(filter)}`).then(response => {
|
||||
this.itemTags = response.data;
|
||||
_getCard() {
|
||||
this.$http.get(`/item/api/Items/${this.$state.params.id}/getCard`).then(response => {
|
||||
this.item = response.data;
|
||||
});
|
||||
}
|
||||
|
||||
_getTags() {
|
||||
this.$http.get(`/item/api/Tags`).then(response => {
|
||||
response.data.forEach(tag => {
|
||||
this.tags[tag.id] = Object.assign({}, tag);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
_getItem() {
|
||||
let filter = {
|
||||
include: [
|
||||
{relation: "itemType",
|
||||
scope: {
|
||||
fields: ['name', 'workerFk', 'warehouseFk'],
|
||||
include: {
|
||||
relation: 'worker',
|
||||
fields: ['firstName', 'name']
|
||||
}
|
||||
}
|
||||
},
|
||||
{relation: "origin"},
|
||||
{relation: "ink"},
|
||||
{relation: "producer"},
|
||||
{relation: "intrastat"},
|
||||
{relation: "expence"}
|
||||
]
|
||||
};
|
||||
this.$http.get(`/item/api/Items/${this.$state.params.id}?filter=${JSON.stringify(filter)}`)
|
||||
.then(res => {
|
||||
if (res.data && res.data.id) {
|
||||
this.$timeout(() => {
|
||||
this.item = res.data;
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
$onInit() {
|
||||
this._getItem();
|
||||
this._getTags();
|
||||
this._getItemTags();
|
||||
this._getCard();
|
||||
}
|
||||
}
|
||||
|
||||
Controller.$inject = ['$http', '$state', '$timeout'];
|
||||
Controller.$inject = ['$http', '$state'];
|
||||
|
||||
ngModule.component('vnItemCard', {
|
||||
template: require('./index.html'),
|
||||
|
|
|
@ -23,36 +23,10 @@ describe('Item', () => {
|
|||
controller = $componentController('vnItemCard', {$state: $state});
|
||||
}));
|
||||
|
||||
describe('_getItemTags()', () => {
|
||||
it('should request to get the ItemTags', () => {
|
||||
$httpBackend.whenGET('/item/api/ItemTags?filter={"where":{"itemFk":123},"order":"priority ASC","include":{"relation":"tag"}}').respond({data: 'data'});
|
||||
$httpBackend.expectGET('/item/api/ItemTags?filter={"where":{"itemFk":123},"order":"priority ASC","include":{"relation":"tag"}}');
|
||||
controller._getItemTags();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
});
|
||||
|
||||
describe('_getTags()', () => {
|
||||
it('should request to get the Tags and store them in the controller using id as keys', () => {
|
||||
let response = [{id: 5, name: "Diámetro", isFree: true, sourceTable: null, unit: "mm"}];
|
||||
let result = {5: {id: 5, name: "Diámetro", isFree: true, sourceTable: null, unit: "mm"}};
|
||||
|
||||
expect(controller.tags).toEqual({});
|
||||
|
||||
$httpBackend.whenGET('/item/api/Tags').respond(response);
|
||||
$httpBackend.expectGET('/item/api/Tags');
|
||||
controller._getTags();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.tags).toEqual(result);
|
||||
});
|
||||
});
|
||||
|
||||
describe('_getItem()', () => {
|
||||
it('should request to get the item', () => {
|
||||
$httpBackend.whenGET('/item/api/Items/123?filter={"include":[{"relation":"itemType","scope":{"fields":["name","workerFk","warehouseFk"],"include":{"relation":"worker","fields":["firstName","name"]}}},{"relation":"origin"},{"relation":"ink"},{"relation":"producer"},{"relation":"intrastat"},{"relation":"expence"}]}').respond({data: 'item'});
|
||||
$httpBackend.expectGET('/item/api/Items/123?filter={"include":[{"relation":"itemType","scope":{"fields":["name","workerFk","warehouseFk"],"include":{"relation":"worker","fields":["firstName","name"]}}},{"relation":"origin"},{"relation":"ink"},{"relation":"producer"},{"relation":"intrastat"},{"relation":"expence"}]}');
|
||||
controller._getItem();
|
||||
describe('_getCard()', () => {
|
||||
it('should request to get the card', () => {
|
||||
$httpBackend.expectGET('/item/api/Items/123/getCard').respond();
|
||||
controller._getCard();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
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(`shoud set _itemFk to a given value and call _getItem if the given value is not null`, () => {
|
||||
spyOn(controller, '_getItem');
|
||||
controller.itemFk = 5;
|
||||
|
||||
expect(controller._getItem).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`, () => {
|
||||
controller.quicklinks = 'mariano';
|
||||
|
||||
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('_getItem()', () => {
|
||||
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._getItem();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.item).toEqual(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue