Updated unit tests
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
538c217b59
commit
1f1b09d456
|
@ -1056,7 +1056,7 @@ INSERT INTO `vn`.`itemTag`(`id`,`itemFk`,`tagFk`,`value`,`priority`)
|
||||||
(10, 2, 27, '15cm', 3),
|
(10, 2, 27, '15cm', 3),
|
||||||
(11, 2, 36, 'Stark Industries', 4),
|
(11, 2, 36, 'Stark Industries', 4),
|
||||||
(12, 2, 1, 'Silver', 5),
|
(12, 2, 1, 'Silver', 5),
|
||||||
(13, 2, 67, 'concussion', 6),
|
(13, 2, 67, 'Concussion', 6),
|
||||||
(14, 2, 23, '1', 7),
|
(14, 2, 23, '1', 7),
|
||||||
(15, 3, 56, 'Ranged weapon', 1),
|
(15, 3, 56, 'Ranged weapon', 1),
|
||||||
(16, 3, 58, 'sniper rifle', 2),
|
(16, 3, 58, 'sniper rifle', 2),
|
||||||
|
@ -1105,7 +1105,7 @@ INSERT INTO `vn`.`itemTag`(`id`,`itemFk`,`tagFk`,`value`,`priority`)
|
||||||
(59, 9, 27, '15cm', 3),
|
(59, 9, 27, '15cm', 3),
|
||||||
(60, 9, 36, 'Stark Industries', 4),
|
(60, 9, 36, 'Stark Industries', 4),
|
||||||
(61, 9, 1, 'Silver', 5),
|
(61, 9, 1, 'Silver', 5),
|
||||||
(62, 9, 67, 'concussion', 6),
|
(62, 9, 67, 'Concussion', 6),
|
||||||
(63, 9, 23, '1', 7),
|
(63, 9, 23, '1', 7),
|
||||||
(64, 10, 56, 'Ranged Reinforced weapon', 1),
|
(64, 10, 56, 'Ranged Reinforced weapon', 1),
|
||||||
(65, 10, 58, 'sniper rifle', 2),
|
(65, 10, 58, 'sniper rifle', 2),
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
const app = require('vn-loopback/server/server');
|
const app = require('vn-loopback/server/server');
|
||||||
|
|
||||||
describe('order catalogFilter()', () => {
|
describe('order catalogFilter()', () => {
|
||||||
|
const colorTagId = 1;
|
||||||
|
const categoryTagId = 67;
|
||||||
|
|
||||||
it('should return an array of items', async() => {
|
it('should return an array of items', async() => {
|
||||||
let filter = {
|
let filter = {
|
||||||
where: {
|
where: {
|
||||||
|
@ -19,21 +22,30 @@ describe('order catalogFilter()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should now return an array of items based on tag filter', async() => {
|
it('should now return an array of items based on tag filter', async() => {
|
||||||
let filter = {
|
const filter = {
|
||||||
where: {
|
where: {
|
||||||
categoryFk: 1,
|
categoryFk: 1,
|
||||||
typeFk: 2
|
typeFk: 2
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let tags = [{tagFk: 56, value: 'Melee Reinforced weapon'}];
|
const tagGroups = [
|
||||||
let orderFk = 11;
|
{tagFk: colorTagId, values: [{value: 'Silver'}, {value: 'Brown'}]},
|
||||||
let orderBy = {field: 'relevancy DESC, name', way: 'DESC'};
|
{tagFk: categoryTagId, values: [{value: 'Concussion'}]}
|
||||||
let result = await app.models.Order.catalogFilter(orderFk, orderBy, filter, tags);
|
];
|
||||||
|
const orderFk = 11;
|
||||||
|
const orderBy = {field: 'relevancy DESC, name', way: 'DESC'};
|
||||||
|
const result = await app.models.Order.catalogFilter(orderFk, orderBy, filter, tagGroups);
|
||||||
|
|
||||||
let firstItemId = result[0].id;
|
const randomIndex = Math.round(Math.random());
|
||||||
|
const item = result[randomIndex];
|
||||||
|
const itemTags = item.tags;
|
||||||
|
|
||||||
expect(result.length).toEqual(1);
|
const colorTag = itemTags.find(tag => tag.tagFk == colorTagId);
|
||||||
expect(firstItemId).toEqual(9);
|
const categoryTag = itemTags.find(tag => tag.tagFk == categoryTagId);
|
||||||
|
|
||||||
|
expect(result.length).toEqual(2);
|
||||||
|
expect(colorTag.value).toEqual('Silver');
|
||||||
|
expect(categoryTag.value).toEqual('Concussion');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
<mg-ajax path="Tags" options="mgIndex as tags"></mg-ajax>
|
<mg-ajax path="Tags" options="mgIndex as tags"></mg-ajax>
|
||||||
<div class="vn-pa-lg" style="min-width: 18em">
|
<div class="vn-pa-lg" style="min-width: 18em">
|
||||||
<form name="form" ng-submit="$ctrl.onSearch()">
|
<form name="form" ng-submit="$ctrl.onSearch()">
|
||||||
<vn-horizontal class="vn-pt-sm">
|
|
||||||
<vn-one class="text-subtitle1" translate>
|
|
||||||
Tags
|
|
||||||
</vn-one>
|
|
||||||
</vn-horizontal>
|
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
<vn-autocomplete
|
<vn-autocomplete
|
||||||
vn-id="tag"
|
vn-id="tag"
|
||||||
|
|
|
@ -6,7 +6,6 @@ class Controller extends Section {
|
||||||
constructor($element, $) {
|
constructor($element, $) {
|
||||||
super($element, $);
|
super($element, $);
|
||||||
this.itemTypes = [];
|
this.itemTypes = [];
|
||||||
// this._tags = [];
|
|
||||||
this._tagGroups = [];
|
this._tagGroups = [];
|
||||||
|
|
||||||
// Static autocomplete data
|
// Static autocomplete data
|
||||||
|
@ -84,8 +83,8 @@ class Controller extends Section {
|
||||||
|
|
||||||
this.updateStateParams();
|
this.updateStateParams();
|
||||||
|
|
||||||
/* if (this.tags.length > 0)
|
if (this.tagGroups.length > 0)
|
||||||
this.applyFilters(); */
|
this.applyFilters();
|
||||||
|
|
||||||
if (value)
|
if (value)
|
||||||
this.updateItemTypes();
|
this.updateItemTypes();
|
||||||
|
@ -105,9 +104,7 @@ class Controller extends Section {
|
||||||
|
|
||||||
this.updateStateParams();
|
this.updateStateParams();
|
||||||
|
|
||||||
/* if (value || this.tags.length > 0)
|
if (value || this.tagGroups.length > 0)
|
||||||
this.applyFilters(); */
|
|
||||||
if (value)
|
|
||||||
this.applyFilters();
|
this.applyFilters();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,19 +121,6 @@ class Controller extends Section {
|
||||||
this.applyFilters();
|
this.applyFilters();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get tags() {
|
|
||||||
return this._tags;
|
|
||||||
}
|
|
||||||
|
|
||||||
set tags(value) {
|
|
||||||
this._tags = value;
|
|
||||||
|
|
||||||
this.updateStateParams();
|
|
||||||
|
|
||||||
if (value.length)
|
|
||||||
this.applyFilters();
|
|
||||||
} */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get order way ASC/DESC
|
* Get order way ASC/DESC
|
||||||
*/
|
*/
|
||||||
|
@ -166,9 +150,7 @@ class Controller extends Section {
|
||||||
* Apply order to model
|
* Apply order to model
|
||||||
*/
|
*/
|
||||||
applyOrder() {
|
applyOrder() {
|
||||||
/* if (this.typeId || this.tags.length > 0)
|
if (this.typeId || this.tagGroups.length > 0)
|
||||||
this.$.model.addFilter(null, {orderBy: this.getOrderBy()}); */
|
|
||||||
if (this.typeId)
|
|
||||||
this.$.model.addFilter(null, {orderBy: this.getOrderBy()});
|
this.$.model.addFilter(null, {orderBy: this.getOrderBy()});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,32 +271,35 @@ class Controller extends Section {
|
||||||
params.typeId = this.typeId;
|
params.typeId = this.typeId;
|
||||||
|
|
||||||
params.tagGroups = undefined;
|
params.tagGroups = undefined;
|
||||||
if (this.tagGroups && this.tagGroups.length) {
|
if (this.tagGroups && this.tagGroups.length)
|
||||||
const tagGroups = [];
|
params.tagGroups = JSON.stringify(this.sanitizedTagGroupParam());
|
||||||
for (let tagGroup of this.tagGroups) {
|
|
||||||
const tagParam = {values: []};
|
|
||||||
|
|
||||||
for (let tagValue of tagGroup.values)
|
|
||||||
tagParam.values.push({value: tagValue.value});
|
|
||||||
|
|
||||||
if (tagGroup.tagFk)
|
|
||||||
tagParam.tagFk = tagGroup.tagFk;
|
|
||||||
|
|
||||||
if (tagGroup.tagSelection) {
|
|
||||||
tagParam.tagSelection = {
|
|
||||||
name: tagGroup.tagSelection.name
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
tagGroups.push(tagParam);
|
|
||||||
}
|
|
||||||
|
|
||||||
params.tagGroups = JSON.stringify(tagGroups);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.$state.go(this.$state.current.name, params);
|
this.$state.go(this.$state.current.name, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sanitizedTagGroupParam() {
|
||||||
|
const tagGroups = [];
|
||||||
|
for (let tagGroup of this.tagGroups) {
|
||||||
|
const tagParam = {values: []};
|
||||||
|
|
||||||
|
for (let tagValue of tagGroup.values)
|
||||||
|
tagParam.values.push({value: tagValue.value});
|
||||||
|
|
||||||
|
if (tagGroup.tagFk)
|
||||||
|
tagParam.tagFk = tagGroup.tagFk;
|
||||||
|
|
||||||
|
if (tagGroup.tagSelection) {
|
||||||
|
tagParam.tagSelection = {
|
||||||
|
name: tagGroup.tagSelection.name
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
tagGroups.push(tagParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
return tagGroups;
|
||||||
|
}
|
||||||
|
|
||||||
buildTagsFilter(items) {
|
buildTagsFilter(items) {
|
||||||
const tagValues = [];
|
const tagValues = [];
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
|
|
|
@ -115,12 +115,12 @@ describe('Order', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('tags() setter', () => {
|
describe('tagGroups() setter', () => {
|
||||||
it(`should set tags property and then call updateStateParams() and applyFilters() methods`, () => {
|
it(`should set tagGroups property and then call updateStateParams() and applyFilters() methods`, () => {
|
||||||
jest.spyOn(controller, 'updateStateParams');
|
jest.spyOn(controller, 'updateStateParams');
|
||||||
jest.spyOn(controller, 'applyFilters');
|
jest.spyOn(controller, 'applyFilters');
|
||||||
|
|
||||||
controller.tags = [{tagFk: 11, value: 'Brown'}];
|
controller.tagGroups = [{tagFk: 11, values: [{value: 'Brown'}]}];
|
||||||
|
|
||||||
expect(controller.updateStateParams).toHaveBeenCalledWith();
|
expect(controller.updateStateParams).toHaveBeenCalledWith();
|
||||||
expect(controller.applyFilters).toHaveBeenCalledWith();
|
expect(controller.applyFilters).toHaveBeenCalledWith();
|
||||||
|
@ -184,7 +184,7 @@ describe('Order', () => {
|
||||||
|
|
||||||
expect(controller.$.model.applyFilter).toHaveBeenCalledWith(
|
expect(controller.$.model.applyFilter).toHaveBeenCalledWith(
|
||||||
{where: {categoryFk: 2, typeFk: 4}},
|
{where: {categoryFk: 2, typeFk: 4}},
|
||||||
{orderFk: 4, orderBy: controller.getOrderBy(), tags: []});
|
{orderFk: 4, orderBy: controller.getOrderBy(), tagGroups: []});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -192,11 +192,16 @@ describe('Order', () => {
|
||||||
it(`should remove a tag from tags property`, () => {
|
it(`should remove a tag from tags property`, () => {
|
||||||
jest.spyOn(controller, 'applyFilters');
|
jest.spyOn(controller, 'applyFilters');
|
||||||
|
|
||||||
controller.tags = [{tagFk: 1, value: 'Blue'}, {tagFk: 2, value: '70'}];
|
controller.tagGroups = [
|
||||||
|
{tagFk: 1, values: [{value: 'Brown'}]},
|
||||||
|
{tagFk: 67, values: [{value: 'Concussion'}]}
|
||||||
|
];
|
||||||
controller.remove(0);
|
controller.remove(0);
|
||||||
|
|
||||||
expect(controller.tags.length).toEqual(1);
|
const firstTag = controller.tagGroups[0];
|
||||||
expect(controller.tags[0].tagFk).toEqual(2);
|
|
||||||
|
expect(controller.tagGroups.length).toEqual(1);
|
||||||
|
expect(firstTag.tagFk).toEqual(67);
|
||||||
expect(controller.applyFilters).toHaveBeenCalledWith();
|
expect(controller.applyFilters).toHaveBeenCalledWith();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -205,10 +210,10 @@ describe('Order', () => {
|
||||||
|
|
||||||
controller._categoryId = 1;
|
controller._categoryId = 1;
|
||||||
controller._typeId = 1;
|
controller._typeId = 1;
|
||||||
controller.tags = [{tagFk: 1, value: 'Blue'}];
|
controller.tagGroups = [{tagFk: 1, values: [{value: 'Blue'}]}];
|
||||||
controller.remove(0);
|
controller.remove(0);
|
||||||
|
|
||||||
expect(controller.tags.length).toEqual(0);
|
expect(controller.tagGroups.length).toEqual(0);
|
||||||
expect(controller.applyFilters).toHaveBeenCalledWith();
|
expect(controller.applyFilters).toHaveBeenCalledWith();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -219,17 +224,16 @@ describe('Order', () => {
|
||||||
|
|
||||||
controller._categoryId = 2;
|
controller._categoryId = 2;
|
||||||
controller._typeId = 4;
|
controller._typeId = 4;
|
||||||
controller._tags = [
|
controller._tagGroups = [
|
||||||
{tagFk: 11, value: 'Precission', tagSelection: {name: 'Category'}}
|
{tagFk: 67, values: [{value: 'Concussion'}], tagSelection: {name: 'Category'}}
|
||||||
];
|
];
|
||||||
const tags = JSON.stringify([{
|
const tagGroups = JSON.stringify([
|
||||||
value: 'Precission',
|
{values: [{value: 'Concussion'}], tagFk: 67, tagSelection: {name: 'Category'}}
|
||||||
tagFk: 11, tagSelection: {name: 'Category'}}
|
|
||||||
]);
|
]);
|
||||||
let result = {categoryId: 2, typeId: 4, tags: tags};
|
const expectedResult = {categoryId: 2, typeId: 4, tagGroups: tagGroups};
|
||||||
controller.updateStateParams();
|
controller.updateStateParams();
|
||||||
|
|
||||||
expect(controller.$state.go).toHaveBeenCalledWith('my.current.state', result);
|
expect(controller.$state.go).toHaveBeenCalledWith('my.current.state', expectedResult);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -307,6 +311,58 @@ describe('Order', () => {
|
||||||
expect(controller.orderFields.length).toEqual(7);
|
expect(controller.orderFields.length).toEqual(7);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('formatTooltip()', () => {
|
||||||
|
it(`should return a formatted text with the tag name and values`, () => {
|
||||||
|
const tagGroup = {
|
||||||
|
values: [{value: 'Silver'}, {value: 'Brown'}],
|
||||||
|
tagFk: 1,
|
||||||
|
tagSelection: {
|
||||||
|
name: 'Color'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = controller.formatTooltip(tagGroup);
|
||||||
|
|
||||||
|
expect(result).toEqual(`Color: "Silver", "Brown"`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`should return a formatted text with the tag value`, () => {
|
||||||
|
const tagGroup = {
|
||||||
|
values: [{value: 'Silver'}]
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = controller.formatTooltip(tagGroup);
|
||||||
|
|
||||||
|
expect(result).toEqual(`"Silver"`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('sanitizedTagGroupParam()', () => {
|
||||||
|
it(`should return an array of tags`, () => {
|
||||||
|
const dirtyTagGroups = [{
|
||||||
|
values: [{value: 'Silver'}, {value: 'Brown'}],
|
||||||
|
tagFk: 1,
|
||||||
|
tagSelection: {
|
||||||
|
name: 'Color',
|
||||||
|
$orgRow: {name: 'Color'}
|
||||||
|
},
|
||||||
|
$orgIndex: 1
|
||||||
|
}];
|
||||||
|
controller.tagGroups = dirtyTagGroups;
|
||||||
|
|
||||||
|
const expectedResult = [{
|
||||||
|
values: [{value: 'Silver'}, {value: 'Brown'}],
|
||||||
|
tagFk: 1,
|
||||||
|
tagSelection: {
|
||||||
|
name: 'Color'
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
const result = controller.sanitizedTagGroupParam();
|
||||||
|
|
||||||
|
expect(result).toMatchObject(expectedResult);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue