diff --git a/modules/entry/front/latest-buys-search-panel/index.js b/modules/entry/front/latest-buys-search-panel/index.js index ce9eddcca6..83dc88724e 100644 --- a/modules/entry/front/latest-buys-search-panel/index.js +++ b/modules/entry/front/latest-buys-search-panel/index.js @@ -57,7 +57,7 @@ class Controller extends SearchPanel { removeField(index, field) { this.fieldFilters.splice(index, 1); - this.$.filter[field] = undefined; + delete this.$.filter[field]; } } diff --git a/modules/entry/front/latest-buys-search-panel/index.spec.js b/modules/entry/front/latest-buys-search-panel/index.spec.js index 6d403b9fbd..9e187a25a4 100644 --- a/modules/entry/front/latest-buys-search-panel/index.spec.js +++ b/modules/entry/front/latest-buys-search-panel/index.spec.js @@ -12,33 +12,48 @@ describe('Entry', () => { controller = $componentController('vnLatestBuysSearchPanel', {$element}); })); - describe('getSourceTable()', () => { - it(`should return null if there's no selection`, () => { - let selection = null; - let result = controller.getSourceTable(selection); + describe('filter() setter', () => { + it(`should set the tags property to the scope filter with an empty array`, () => { + const expectedFilter = { + 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`, () => { - let selection = {isFree: true}; - let result = controller.getSourceTable(selection); + it(`should set the tags property to the scope filter with an array of tags`, () => { + const expectedFilter = { + 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`, () => { - let selection = {sourceTable: 'hello guy'}; - let result = controller.getSourceTable(selection); + describe('removeField()', () => { + it(`should remove the description property from the fieldFilters and from the scope filter`, () => { + 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`, () => { - let selection = {id: 99}; - let result = controller.getSourceTable(selection); - - expect(result).toEqual(`ItemTags/filterItemTags/${selection.id}`); + expect(controller.filter).toEqual(expectedFilter); + expect(controller.fieldFilters).toEqual([]); }); }); }); diff --git a/modules/item/front/search-panel/index.js b/modules/item/front/search-panel/index.js index 6a0f358ebd..2448728be0 100644 --- a/modules/item/front/search-panel/index.js +++ b/modules/item/front/search-panel/index.js @@ -57,7 +57,7 @@ class Controller extends SearchPanel { removeField(index, field) { this.fieldFilters.splice(index, 1); - this.$.filter[field] = undefined; + delete this.$.filter[field]; } } diff --git a/modules/item/front/search-panel/index.spec.js b/modules/item/front/search-panel/index.spec.js index 0e2b7f848d..39b5b7aa5b 100644 --- a/modules/item/front/search-panel/index.spec.js +++ b/modules/item/front/search-panel/index.spec.js @@ -12,33 +12,48 @@ describe('Item', () => { controller = $componentController('vnItemSearchPanel', {$element}); })); - describe('getSourceTable()', () => { - it(`should return null if there's no selection`, () => { - let selection = null; - let result = controller.getSourceTable(selection); + describe('filter() setter', () => { + it(`should set the tags property to the scope filter with an empty array`, () => { + const expectedFilter = { + 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`, () => { - let selection = {isFree: true}; - let result = controller.getSourceTable(selection); + it(`should set the tags property to the scope filter with an array of tags`, () => { + const expectedFilter = { + 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`, () => { - let selection = {sourceTable: 'hello guy'}; - let result = controller.getSourceTable(selection); + describe('removeField()', () => { + it(`should remove the description property from the fieldFilters and from the scope filter`, () => { + 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`, () => { - let selection = {id: 99}; - let result = controller.getSourceTable(selection); - - expect(result).toEqual(`ItemTags/filterItemTags/${selection.id}`); + expect(controller.filter).toEqual(expectedFilter); + expect(controller.fieldFilters).toEqual([]); }); }); });