-
-
Notifications
You must be signed in to change notification settings - Fork 735
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: code cleanup: event log filters (#7870)
Adds tests for event log filters (to ensure we show the right filters) and refactors the implementation of eventlogfilters. Primary goal of refactoring: - Make it so that all filters are created in one single list (instead of injected from different variables) - Avoid making a requests for features (and to a lesser extent: projects) if you can't use them for filters - Improve code structure
- Loading branch information
1 parent
dad30a0
commit f59b775
Showing
2 changed files
with
168 additions
and
69 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
frontend/src/component/events/EventLog/EventLogFilters.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { renderHook } from '@testing-library/react'; | ||
import { useEventLogFilters } from './EventLogFilters'; | ||
|
||
const allFilterKeys = ['from', 'to', 'createdBy', 'type', 'project', 'feature']; | ||
|
||
allFilterKeys.sort(); | ||
|
||
test('When you have no projects or flags, you should not get a project or flag filters', () => { | ||
const { result } = renderHook(() => | ||
useEventLogFilters( | ||
() => ({ projects: [] }), | ||
() => ({ features: [] }), | ||
), | ||
); | ||
const filterKeys = result.current.map((filter) => filter.filterKey); | ||
filterKeys.sort(); | ||
|
||
expect(filterKeys).not.toContain('project'); | ||
expect(filterKeys).not.toContain('feature'); | ||
}); | ||
|
||
test('When you have no projects, you should not get a project filter', () => { | ||
const { result } = renderHook(() => | ||
useEventLogFilters( | ||
() => ({ projects: [] }), | ||
// @ts-expect-error: omitting other properties we don't need | ||
() => ({ features: [{ name: 'flag' }] }), | ||
), | ||
); | ||
const filterKeys = result.current.map((filter) => filter.filterKey); | ||
filterKeys.sort(); | ||
|
||
expect(filterKeys).not.toContain('project'); | ||
}); | ||
|
||
test('When you have only one project, you should not get a project filter', () => { | ||
const { result } = renderHook(() => | ||
useEventLogFilters( | ||
// @ts-expect-error: omitting other properties we don't need | ||
() => ({ projects: [{ id: 'a', name: 'A' }] }), | ||
() => ({ features: [] }), | ||
), | ||
); | ||
const filterKeys = result.current.map((filter) => filter.filterKey); | ||
filterKeys.sort(); | ||
|
||
expect(filterKeys).not.toContain('project'); | ||
}); | ||
|
||
test('When you have two one project, you should not get a project filter', () => { | ||
const { result } = renderHook(() => | ||
useEventLogFilters( | ||
() => ({ | ||
projects: [ | ||
// @ts-expect-error: omitting other properties we don't need | ||
{ id: 'a', name: 'A' }, | ||
// @ts-expect-error: omitting other properties we don't need | ||
{ id: 'b', name: 'B' }, | ||
], | ||
}), | ||
() => ({ features: [] }), | ||
), | ||
); | ||
const filterKeys = result.current.map((filter) => filter.filterKey); | ||
filterKeys.sort(); | ||
|
||
expect(filterKeys).toContain('project'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters