From 40a5371d617d226681f83db5840f490fc0c4755c Mon Sep 17 00:00:00 2001 From: sjaanus Date: Wed, 2 Jul 2025 14:08:01 +0300 Subject: [PATCH] Fix --- .../events/EventLog/EventLogFilters.test.tsx | 36 ++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/frontend/src/component/events/EventLog/EventLogFilters.test.tsx b/frontend/src/component/events/EventLog/EventLogFilters.test.tsx index e87c081cfd..dc7ac64905 100644 --- a/frontend/src/component/events/EventLog/EventLogFilters.test.tsx +++ b/frontend/src/component/events/EventLog/EventLogFilters.test.tsx @@ -1,12 +1,23 @@ import { renderHook } from '@testing-library/react'; +import { MemoryRouter } from 'react-router-dom'; import { useEventLogFilters } from './EventLogFilters.tsx'; const allFilterKeys = ['from', 'to', 'createdBy', 'type', 'project', 'feature']; allFilterKeys.sort(); +const renderWithRouter = (callback: () => any, initialEntries = ['/']) => { + return renderHook(callback, { + wrapper: ({ children }) => ( + + {children} + + ), + }); +}; + test('When you have no projects or flags, you should not get a project or flag filters', () => { - const { result } = renderHook(() => useEventLogFilters([], [])); + const { result } = renderWithRouter(() => useEventLogFilters([], [])); const filterKeys = result.current.map((filter) => filter.filterKey); filterKeys.sort(); @@ -15,7 +26,7 @@ test('When you have no projects or flags, you should not get a project or flag f }); test('When you have no projects, you should not get a project filter', () => { - const { result } = renderHook(() => + const { result } = renderWithRouter(() => useEventLogFilters( [], // @ts-expect-error: omitting other properties we don't need @@ -29,7 +40,7 @@ test('When you have no projects, you should not get a project filter', () => { }); test('When you have only one project, you should not get a project filter', () => { - const { result } = renderHook(() => + const { result } = renderWithRouter(() => useEventLogFilters([{ id: 'a', name: 'A' }], []), ); const filterKeys = result.current.map((filter) => filter.filterKey); @@ -39,7 +50,7 @@ test('When you have only one project, you should not get a project filter', () = }); test('When you have two one project, you should not get a project filter', () => { - const { result } = renderHook(() => + const { result } = renderWithRouter(() => useEventLogFilters( [ { id: 'a', name: 'A' }, @@ -53,3 +64,20 @@ test('When you have two one project, you should not get a project filter', () => expect(filterKeys).toContain('project'); }); + +test('When groupId is in URL params, should include groupId filter', () => { + const { result } = renderWithRouter( + () => useEventLogFilters([], []), + ['/?groupId=IS:123'], + ); + const filterKeys = result.current.map((filter) => filter.filterKey); + + expect(filterKeys).toContain('groupId'); +}); + +test('When no groupId in URL params, should not include groupId filter', () => { + const { result } = renderWithRouter(() => useEventLogFilters([], [])); + const filterKeys = result.current.map((filter) => filter.filterKey); + + expect(filterKeys).not.toContain('groupId'); +});