From e9efb5665b03f0f4037796613d11c159e1e482b3 Mon Sep 17 00:00:00 2001 From: Adolfo Agasi Date: Wed, 2 Jun 2021 16:12:26 -0300 Subject: [PATCH 1/3] Ticket #3209. Adds check by include_in_menu attribute before appending children categories to the returned array. --- .../peregrine/lib/talons/CategoryTree/useCategoryTree.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/peregrine/lib/talons/CategoryTree/useCategoryTree.js b/packages/peregrine/lib/talons/CategoryTree/useCategoryTree.js index 6b8a917532..3ed581601b 100644 --- a/packages/peregrine/lib/talons/CategoryTree/useCategoryTree.js +++ b/packages/peregrine/lib/talons/CategoryTree/useCategoryTree.js @@ -70,9 +70,10 @@ export const useCategoryTree = props => { } children.map(category => { - const isLeaf = !parseInt(category.children_count); - - childCategories.set(category.id, { category, isLeaf }); + if (category.include_in_menu) { + const isLeaf = !parseInt(category.children_count); + childCategories.set(category.id, { category, isLeaf }); + } }); return childCategories; From 5c23fc13486e5dbfda259b8dca30a5f6fc4d7b5d Mon Sep 17 00:00:00 2001 From: Adolfo Agasi Date: Fri, 4 Jun 2021 17:09:52 -0300 Subject: [PATCH 2/3] Add test. --- .../__tests__/useCategoryTree.spec.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/peregrine/lib/talons/CategoryTree/__tests__/useCategoryTree.spec.js b/packages/peregrine/lib/talons/CategoryTree/__tests__/useCategoryTree.spec.js index 83fc27b76d..5b6acccc86 100644 --- a/packages/peregrine/lib/talons/CategoryTree/__tests__/useCategoryTree.spec.js +++ b/packages/peregrine/lib/talons/CategoryTree/__tests__/useCategoryTree.spec.js @@ -266,4 +266,22 @@ describe('child categories', () => { const { childCategories } = log.mock.calls[0][0]; expect(childCategories.has(1)).toEqual(false); }); + + test('Does not include child category when include_in_menu is not true', () => { + // Arrange. + useLazyQuery.mockImplementation(() => { + return getNavigationMenuQueryResult(); + }); + // There's nothing to arrange here, the default values for props + // and categories are already arranged for this test to succeed. + + // Act. + createTestInstance(); + + // Assert. + const { childCategories } = log.mock.calls[0][0]; + for (const childCategory of childCategories) { + expect(childCategory[1].category.include_in_menu).toBe(1); + } + }); }); From b1d8974f60e13daa59e67922b289e7e5b98c3aa4 Mon Sep 17 00:00:00 2001 From: sirugh Date: Mon, 7 Jun 2021 09:42:07 -0500 Subject: [PATCH 3/3] fixup test falsy case Signed-off-by: sirugh --- .../__tests__/useCategoryTree.spec.js | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/packages/peregrine/lib/talons/CategoryTree/__tests__/useCategoryTree.spec.js b/packages/peregrine/lib/talons/CategoryTree/__tests__/useCategoryTree.spec.js index 5b6acccc86..6992797860 100644 --- a/packages/peregrine/lib/talons/CategoryTree/__tests__/useCategoryTree.spec.js +++ b/packages/peregrine/lib/talons/CategoryTree/__tests__/useCategoryTree.spec.js @@ -267,21 +267,37 @@ describe('child categories', () => { expect(childCategories.has(1)).toEqual(false); }); - test('Does not include child category when include_in_menu is not true', () => { - // Arrange. + test('Does not include child category when include_in_menu is falsy', () => { + const categoryId = 5; useLazyQuery.mockImplementation(() => { - return getNavigationMenuQueryResult(); + return jest.fn().mockReturnValue([ + getNavigationMenu, + { + data: { + category: { + ...result.data.category, + children: [ + ...result.data.category.children, + { + id: categoryId, + include_in_menu: 0, + children_count: 0, + name: 'Five', + parentId: 1, + position: 0, + url_suffix: '.html', + url_path: '1/5' + } + ] + } + } + } + ])(); }); - // There's nothing to arrange here, the default values for props - // and categories are already arranged for this test to succeed. - // Act. createTestInstance(); - // Assert. const { childCategories } = log.mock.calls[0][0]; - for (const childCategory of childCategories) { - expect(childCategory[1].category.include_in_menu).toBe(1); - } + expect(childCategories.get(categoryId)).toBeUndefined(); }); });