Skip to content

Commit 55beced

Browse files
authored
[CDX-283] Allows Hiding of Groups in the Groups Filter (#192)
* adds both blocklisting interfaces * Update docs * address comments
1 parent 6c7a4e2 commit 55beced

File tree

12 files changed

+497
-322
lines changed

12 files changed

+497
-322
lines changed

spec/components/Groups/Groups.test.jsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,31 @@ describe('Testing Component: Groups', () => {
123123
expect(mockChildren).toHaveBeenCalled();
124124
expect(getByText('Custom Filters')).toBeInTheDocument();
125125
});
126+
127+
it('Should exclude groups excluded by isHiddenGroupFn', () => {
128+
const filtersPropsWithChildren = {
129+
...groupsProps,
130+
isHiddenGroupFn: (group) => ['2', '12'].includes(group.groupId),
131+
};
132+
133+
const { getByText, queryByText } = render(
134+
<CioPlp apiKey={DEMO_API_KEY}>
135+
<Groups {...filtersPropsWithChildren} />
136+
</CioPlp>,
137+
);
138+
expect(queryByText('Souvenirs')).toBeNull();
139+
expect(getByText('Deals')).toBeInTheDocument();
140+
});
141+
142+
it('Should exclude groups excluded by group.data.cio_plp_hidden', () => {
143+
const { getByText, queryByText } = render(
144+
<CioPlp apiKey={DEMO_API_KEY}>
145+
<Groups {...groupsProps} />
146+
</CioPlp>,
147+
);
148+
expect(queryByText('Hidden Group')).toBeNull();
149+
expect(getByText('Deals')).toBeInTheDocument();
150+
});
126151
});
127152

128153
describe(' - Behavior Tests', () => {

spec/hooks/useGroups/useGroups.test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,44 @@ describe('Testing Hook: useGroups', () => {
265265
expect(setOptionsToRender).not.toBeUndefined();
266266
});
267267
});
268+
269+
it('Should not return groups that are meant to be excluded via isHiddenGroupFn', async () => {
270+
const isHiddenGroupFn = (group) => group.groupId === 'W676714';
271+
const { result } = renderHookWithCioPlp(() =>
272+
useGroups({ ...useGroupsProps, isHiddenGroupFn }),
273+
);
274+
275+
await waitFor(() => {
276+
const {
277+
current: { optionsToRender },
278+
} = result;
279+
280+
expect(optionsToRender.filter((group) => !isHiddenGroupFn(group)).length).toBe(
281+
optionsToRender.length,
282+
);
283+
expect(optionsToRender.length).toBeLessThan(useGroupsProps.groups[0].children.length);
284+
const rawOptions = useGroupsProps.groups[0].children;
285+
const excludedGroups = rawOptions.filter((group) =>
286+
optionsToRender.find((option) => option.groupId !== group.groupId),
287+
);
288+
expect(excludedGroups.find((group) => group.groupId === 'W676714')).toBeTruthy();
289+
});
290+
});
291+
292+
it('Should not return groups that are flagged with groups.data.cio_plp_hidden = true', async () => {
293+
const { result } = renderHookWithCioPlp(() => useGroups({ ...useGroupsProps }));
294+
295+
await waitFor(() => {
296+
const {
297+
current: { optionsToRender },
298+
} = result;
299+
300+
expect(optionsToRender.length).toBeLessThan(useGroupsProps.groups[0].children.length);
301+
const rawOptions = useGroupsProps.groups[0].children;
302+
const excludedGroups = rawOptions.filter((group) =>
303+
optionsToRender.find((option) => option.groupId !== group.groupId),
304+
);
305+
expect(excludedGroups.find((group) => group.groupId === 'cio_plp_hidden_group')).toBeTruthy();
306+
});
307+
});
268308
});

spec/local_examples/apiSearchResponse.json

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5998,7 +5998,10 @@
59985998
"count": 23,
59995999
"data": null,
60006000
"children": [],
6001-
"parents": [{ "display_name": "All Products", "group_id": "AP01" }, { "display_name": "Clearance", "group_id": "W676714" }]
6001+
"parents": [
6002+
{ "display_name": "All Products", "group_id": "AP01" },
6003+
{ "display_name": "Clearance", "group_id": "W676714" }
6004+
]
60026005
}
60036006
],
60046007
"parents": [
@@ -6085,6 +6088,21 @@
60856088
"group_id": "AP01"
60866089
}
60876090
]
6091+
},
6092+
{
6093+
"group_id": "cio_plp_hidden_group",
6094+
"display_name": "CIO PLP Hidden Group",
6095+
"count": 85,
6096+
"data": {
6097+
"cio_plp_hidden": true
6098+
},
6099+
"children": [],
6100+
"parents": [
6101+
{
6102+
"display_name": "All Products",
6103+
"group_id": "AP01"
6104+
}
6105+
]
60886106
}
60896107
],
60906108
"parents": []

0 commit comments

Comments
 (0)