Updated unit tests

This commit is contained in:
Joan Sanchez 2021-11-22 15:49:32 +01:00
parent a940d14256
commit 90ab78d26d
4 changed files with 70 additions and 40 deletions

View File

@ -57,7 +57,7 @@ class Controller extends SearchPanel {
removeField(index, field) { removeField(index, field) {
this.fieldFilters.splice(index, 1); this.fieldFilters.splice(index, 1);
this.$.filter[field] = undefined; delete this.$.filter[field];
} }
} }

View File

@ -12,33 +12,48 @@ describe('Entry', () => {
controller = $componentController('vnLatestBuysSearchPanel', {$element}); controller = $componentController('vnLatestBuysSearchPanel', {$element});
})); }));
describe('getSourceTable()', () => { describe('filter() setter', () => {
it(`should return null if there's no selection`, () => { it(`should set the tags property to the scope filter with an empty array`, () => {
let selection = null; const expectedFilter = {
let result = controller.getSourceTable(selection); tags: [{}]
};
controller.filter = null;
expect(result).toBeNull(); expect(controller.filter).toEqual(expectedFilter);
}); });
it(`should return null if there's a selection but its isFree property is truthy`, () => { it(`should set the tags property to the scope filter with an array of tags`, () => {
let selection = {isFree: true}; const expectedFilter = {
let result = controller.getSourceTable(selection); description: 'My item',
tags: [{}]
};
const expectedFieldFilter = [{
info: {
label: 'description',
name: 'description',
type: null
},
name: 'description',
value: 'My item'
}];
controller.filter = {
description: 'My item'
};
expect(result).toBeNull(); expect(controller.filter).toEqual(expectedFilter);
expect(controller.fieldFilters).toEqual(expectedFieldFilter);
}); });
});
it(`should return the formated sourceTable concatenated to a path`, () => { describe('removeField()', () => {
let selection = {sourceTable: 'hello guy'}; it(`should remove the description property from the fieldFilters and from the scope filter`, () => {
let result = controller.getSourceTable(selection); const expectedFilter = {tags: [{}]};
controller.filter = {description: 'My item'};
expect(result).toEqual('Hello guys'); controller.removeField(0, 'description');
});
it(`should return a path if there's no sourceTable and the selection has an id`, () => { expect(controller.filter).toEqual(expectedFilter);
let selection = {id: 99}; expect(controller.fieldFilters).toEqual([]);
let result = controller.getSourceTable(selection);
expect(result).toEqual(`ItemTags/filterItemTags/${selection.id}`);
}); });
}); });
}); });

View File

@ -57,7 +57,7 @@ class Controller extends SearchPanel {
removeField(index, field) { removeField(index, field) {
this.fieldFilters.splice(index, 1); this.fieldFilters.splice(index, 1);
this.$.filter[field] = undefined; delete this.$.filter[field];
} }
} }

View File

@ -12,33 +12,48 @@ describe('Item', () => {
controller = $componentController('vnItemSearchPanel', {$element}); controller = $componentController('vnItemSearchPanel', {$element});
})); }));
describe('getSourceTable()', () => { describe('filter() setter', () => {
it(`should return null if there's no selection`, () => { it(`should set the tags property to the scope filter with an empty array`, () => {
let selection = null; const expectedFilter = {
let result = controller.getSourceTable(selection); tags: [{}]
};
controller.filter = null;
expect(result).toBeNull(); expect(controller.filter).toEqual(expectedFilter);
}); });
it(`should return null if there's a selection but its isFree property is truthy`, () => { it(`should set the tags property to the scope filter with an array of tags`, () => {
let selection = {isFree: true}; const expectedFilter = {
let result = controller.getSourceTable(selection); description: 'My item',
tags: [{}]
};
const expectedFieldFilter = [{
info: {
label: 'description',
name: 'description',
type: null
},
name: 'description',
value: 'My item'
}];
controller.filter = {
description: 'My item'
};
expect(result).toBeNull(); expect(controller.filter).toEqual(expectedFilter);
expect(controller.fieldFilters).toEqual(expectedFieldFilter);
}); });
});
it(`should return the formated sourceTable concatenated to a path`, () => { describe('removeField()', () => {
let selection = {sourceTable: 'hello guy'}; it(`should remove the description property from the fieldFilters and from the scope filter`, () => {
let result = controller.getSourceTable(selection); const expectedFilter = {tags: [{}]};
controller.filter = {description: 'My item'};
expect(result).toEqual('Hello guys'); controller.removeField(0, 'description');
});
it(`should return a path if there's no sourceTable and the selection has an id`, () => { expect(controller.filter).toEqual(expectedFilter);
let selection = {id: 99}; expect(controller.fieldFilters).toEqual([]);
let result = controller.getSourceTable(selection);
expect(result).toEqual(`ItemTags/filterItemTags/${selection.id}`);
}); });
}); });
}); });