Skip to content

Commit

Permalink
fix: skip collections' events by ids query when no ids are given
Browse files Browse the repository at this point in the history
HCRC-89.
Skip events by ids query and render an empty collection when no event ids are given.
  • Loading branch information
nikomakela committed Dec 29, 2023
1 parent c1cbf45 commit 745a5a3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/core/collection/Collection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ export function EventSelectionCollection({
client: eventsApolloClient !== 'disabled' && eventsApolloClient,
ssr: false,
notifyOnNetworkStatusChange: true,
skip: collection.events.length === 0,
variables: {
ids: collection.events,
pageSize,
Expand Down
13 changes: 13 additions & 0 deletions src/core/collection/__tests__/Collection.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ describe('event selection module', () => {
// so the amount of the links should be the amounts of events.
expect(screen.getAllByRole('link').length).toBe(activeEvents.length);
});

it('renders an empty collection when no event ids was given', async () => {
const collection = { events: [] } as EventSelectionCollectionType;
const { container } = render(
<EventSelectionCollection collection={collection} type="carousel" />,
undefined,
{ ...getApolloConfig(CmsEndpoint.events) },
);
await waitFor(() => {
expect(screen.queryByText(/Page is loading/)).not.toBeInTheDocument();
});
expect(container.getElementsByTagName('ul')[0].children).toHaveLength(0);
});
});

describe('event search module', () => {
Expand Down

0 comments on commit 745a5a3

Please sign in to comment.