Skip to content

Commit

Permalink
Ticket #3209. Adds check by include_in_menu attribute before appendin… (
Browse files Browse the repository at this point in the history
#3210)

* Ticket #3209. Adds check by include_in_menu attribute before appending children categories to the returned array.
* Add test.
* fixup test falsy case

Signed-off-by: sirugh <rugh@adobe.com>

Co-authored-by: sirugh <rugh@adobe.com>
Co-authored-by: Andy Terranova <13182778+supernova-at@users.noreply.github.com>
Co-authored-by: Tommy Wiebell <twiebell@adobe.com>
  • Loading branch information
4 people authored Jun 14, 2021
1 parent d0f3d08 commit e186e1c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,38 @@ 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 falsy', () => {
const categoryId = 5;
useLazyQuery.mockImplementation(() => {
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'
}
]
}
}
}
])();
});

createTestInstance(<Component {...props} />);

const { childCategories } = log.mock.calls[0][0];
expect(childCategories.get(categoryId)).toBeUndefined();
});
});
7 changes: 4 additions & 3 deletions packages/peregrine/lib/talons/CategoryTree/useCategoryTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e186e1c

Please sign in to comment.