-
Notifications
You must be signed in to change notification settings - Fork 136
TRT-2764: Resolved conflicts from #3721 - Fix search bar not completing search #3818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
not-stbenjam
wants to merge
10
commits into
openshift:main
Choose a base branch
from
not-stbenjam:trt-2764-resolved
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
061b4cb
TRT-2764: Fix search bar not completing search until page refresh
45601e8
TRT-2764: Fix double-search stuck loading and repopulate search bar o…
9ca19dd
TRT-2764: Fix double-search stuck loading and search bar repopulation
db0562a
TRT-2764: Only populate quick search from single positive filter
83afc49
Merge remote-tracking branch 'origin/main' into trt-2764
not-stbenjam f754718
Fix lint CI failure and add regression tests for search bar
not-stbenjam 590709c
Revert Makefile audit-level change
not-stbenjam a670578
Merge remote-tracking branch 'origin/main' into trt-2764-resolved
not-stbenjam 57228f0
Address review: fix immutable state update and columnField mismatch
not-stbenjam 412fd3c
Merge remote-tracking branch 'origin/main' into trt-2764-resolved
not-stbenjam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,147 @@ | ||
| import '@testing-library/jest-dom' | ||
| import { createTheme, ThemeProvider } from '@mui/material/styles' | ||
| import { render, screen } from '@testing-library/react' | ||
| import GridToolbar from './GridToolbar' | ||
| import React from 'react' | ||
| import userEvent from '@testing-library/user-event' | ||
|
|
||
| vi.mock('@mui/x-data-grid', () => ({ | ||
| GridToolbarDensitySelector: () => null, | ||
| })) | ||
|
|
||
| vi.mock('./GridToolbarFilterMenu', () => ({ | ||
| default: () => null, | ||
| })) | ||
|
|
||
| const theme = createTheme() | ||
|
|
||
| function renderToolbar(props = {}) { | ||
| const defaults = { | ||
| doSearch: vi.fn(), | ||
| clearSearch: vi.fn(), | ||
| setFilterModel: vi.fn(), | ||
| addFilters: vi.fn(), | ||
| filterModel: { items: [] }, | ||
| } | ||
| return render( | ||
| <ThemeProvider theme={theme}> | ||
| <GridToolbar {...defaults} {...props} /> | ||
| </ThemeProvider> | ||
| ) | ||
| } | ||
|
|
||
| describe('GridToolbar', () => { | ||
| describe('search bar initialization from filter', () => { | ||
| it('populates search from a single positive contains filter', () => { | ||
| renderToolbar({ | ||
| searchField: 'name', | ||
| filterModel: { | ||
| items: [ | ||
| { | ||
| columnField: 'name', | ||
| operatorValue: 'contains', | ||
| value: 'my-job', | ||
| }, | ||
| ], | ||
| }, | ||
| }) | ||
| expect(screen.getByPlaceholderText('Search…')).toHaveValue('my-job') | ||
| }) | ||
|
|
||
| it('does not populate search from a negated contains filter', () => { | ||
| renderToolbar({ | ||
| searchField: 'name', | ||
| filterModel: { | ||
| items: [ | ||
| { | ||
| columnField: 'name', | ||
| operatorValue: 'contains', | ||
| not: true, | ||
| value: 'excluded', | ||
| }, | ||
| ], | ||
| }, | ||
| }) | ||
| expect(screen.getByPlaceholderText('Search…')).toHaveValue('') | ||
| }) | ||
|
|
||
| it('does not populate search when multiple filters exist for the field', () => { | ||
| renderToolbar({ | ||
| searchField: 'name', | ||
| filterModel: { | ||
| items: [ | ||
| { | ||
| columnField: 'name', | ||
| operatorValue: 'contains', | ||
| value: 'a', | ||
| }, | ||
| { | ||
| columnField: 'name', | ||
| operatorValue: 'contains', | ||
| value: 'b', | ||
| }, | ||
| ], | ||
| }, | ||
| }) | ||
| expect(screen.getByPlaceholderText('Search…')).toHaveValue('') | ||
| }) | ||
|
|
||
| it('does not populate search when operator is not contains', () => { | ||
| renderToolbar({ | ||
| searchField: 'name', | ||
| filterModel: { | ||
| items: [ | ||
| { | ||
| columnField: 'name', | ||
| operatorValue: 'equals', | ||
| value: 'exact', | ||
| }, | ||
| ], | ||
| }, | ||
| }) | ||
| expect(screen.getByPlaceholderText('Search…')).toHaveValue('') | ||
| }) | ||
| }) | ||
|
|
||
| describe('search interactions', () => { | ||
| it('triggers search on Enter key', async () => { | ||
| const doSearch = vi.fn() | ||
| renderToolbar({ doSearch }) | ||
|
|
||
| const input = screen.getByPlaceholderText('Search…') | ||
| await userEvent.type(input, 'test-query{enter}') | ||
| expect(doSearch).toHaveBeenCalledWith('test-query') | ||
| }) | ||
|
|
||
| it('triggers search on search button click', async () => { | ||
| const doSearch = vi.fn() | ||
| renderToolbar({ doSearch }) | ||
|
|
||
| const input = screen.getByPlaceholderText('Search…') | ||
| await userEvent.type(input, 'btn-query') | ||
| await userEvent.click(screen.getByTitle('Search')) | ||
| expect(doSearch).toHaveBeenCalledWith('btn-query') | ||
| }) | ||
|
|
||
| it('does not trigger search on blur', async () => { | ||
| const doSearch = vi.fn() | ||
| renderToolbar({ doSearch }) | ||
|
|
||
| const input = screen.getByPlaceholderText('Search…') | ||
| await userEvent.type(input, 'blur-query') | ||
| await userEvent.tab() | ||
| expect(doSearch).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('clears search on clear button click', async () => { | ||
| const clearSearch = vi.fn() | ||
| renderToolbar({ clearSearch }) | ||
|
|
||
| const input = screen.getByPlaceholderText('Search…') | ||
| await userEvent.type(input, 'something') | ||
| await userEvent.click(screen.getByTitle('Clear')) | ||
| expect(clearSearch).toHaveBeenCalled() | ||
| expect(input).toHaveValue('') | ||
| }) | ||
| }) | ||
| }) |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,92 @@ | ||
| import '@testing-library/jest-dom' | ||
|
|
||
| /** | ||
| * The requestSearch pattern used in JobRunsTable (and all other table | ||
| * components) immutably replaces the search-field filter while preserving | ||
| * other filters. We test the pure logic here because the full component | ||
| * requires extensive infrastructure (react-router, query-params, DataGrid, | ||
| * API). | ||
| */ | ||
| function requestSearch(filterModel, searchField, searchValue) { | ||
| const newItems = filterModel.items.filter( | ||
| (f) => f.columnField !== searchField | ||
| ) | ||
| newItems.push({ | ||
| id: 99, | ||
| columnField: searchField, | ||
| operatorValue: 'contains', | ||
| value: searchValue, | ||
| }) | ||
| return { | ||
| ...filterModel, | ||
| items: newItems, | ||
| } | ||
|
not-stbenjam marked this conversation as resolved.
|
||
| } | ||
|
|
||
| describe('JobRunsTable requestSearch logic', () => { | ||
| it('replaces an existing job filter immutably', () => { | ||
| const original = { | ||
| items: [ | ||
| { id: 1, columnField: 'job', operatorValue: 'contains', value: 'old' }, | ||
| ], | ||
| } | ||
| const result = requestSearch(original, 'job', 'new-query') | ||
| expect(result.items).toHaveLength(1) | ||
| expect(result.items[0]).toEqual({ | ||
| id: 99, | ||
| columnField: 'job', | ||
| operatorValue: 'contains', | ||
| value: 'new-query', | ||
| }) | ||
| expect(original.items).toHaveLength(1) | ||
| expect(original.items[0].value).toBe('old') | ||
| }) | ||
|
|
||
| it('preserves filters for other fields', () => { | ||
| const original = { | ||
| items: [ | ||
| { | ||
| id: 1, | ||
| columnField: 'cluster', | ||
| operatorValue: 'contains', | ||
| value: 'build01', | ||
| }, | ||
| { | ||
| id: 2, | ||
| columnField: 'job', | ||
| operatorValue: 'contains', | ||
| value: 'old', | ||
| }, | ||
| ], | ||
| } | ||
| const result = requestSearch(original, 'job', 'new-query') | ||
| expect(result.items).toHaveLength(2) | ||
| expect(result.items[0].columnField).toBe('cluster') | ||
| expect(result.items[0].value).toBe('build01') | ||
| expect(result.items[1].value).toBe('new-query') | ||
| }) | ||
|
|
||
| it('adds a filter when none exists for the field', () => { | ||
| const original = { items: [] } | ||
| const result = requestSearch(original, 'job', 'my-search') | ||
| expect(result.items).toHaveLength(1) | ||
| expect(result.items[0].value).toBe('my-search') | ||
| expect(original.items).toHaveLength(0) | ||
| }) | ||
|
|
||
| it('clears the search by setting an empty value', () => { | ||
| const original = { | ||
| items: [ | ||
| { | ||
| id: 99, | ||
| columnField: 'job', | ||
| operatorValue: 'contains', | ||
| value: 'prev', | ||
| }, | ||
| ], | ||
| } | ||
| const result = requestSearch(original, 'job', '') | ||
| expect(result.items).toHaveLength(1) | ||
| expect(result.items[0].value).toBe('') | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.