-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
3095703
commit d159f14
Showing
4 changed files
with
156 additions
and
99 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,138 @@ | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import UIProvider, { DefaultTheme } from 'hew/Theme'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
|
||
import { ThemeProvider } from 'components/ThemeProvider'; | ||
import { Project } from 'types'; | ||
|
||
import Searches from './Searches'; | ||
import { defaultProjectSettings } from './Searches.settings'; | ||
|
||
const projectMock: Project = { | ||
archived: false, | ||
description: '', | ||
id: 1849, | ||
immutable: false, | ||
lastExperimentStartedAt: '2024-06-03T19:33:38.731220Z', | ||
name: 'test', | ||
notes: [], | ||
numActiveExperiments: 1, | ||
numExperiments: 16, | ||
state: 'UNSPECIFIED', | ||
userId: 1354, | ||
workspaceId: 1684, | ||
workspaceName: '', | ||
}; | ||
|
||
const expectedFilterString = JSON.stringify({ | ||
filterGroup: { | ||
children: [ | ||
{ children: [], conjunction: 'and', kind: 'group' }, | ||
{ | ||
columnName: 'searcherType', | ||
kind: 'field', | ||
location: 'LOCATION_TYPE_EXPERIMENT', | ||
operator: '!=', | ||
type: 'COLUMN_TYPE_TEXT', | ||
value: 'single', | ||
}, | ||
], | ||
conjunction: 'and', | ||
kind: 'group', | ||
}, | ||
showArchived: false, | ||
}); | ||
|
||
const searchExperiments = vi.hoisted(() => vi.fn()); | ||
|
||
vi.mock('services/api', () => ({ | ||
getProjectColumns: vi.fn().mockReturnValue([]), | ||
getWorkspaces: vi.fn().mockResolvedValue({ workspaces: [] }), | ||
resetUserSetting: () => Promise.resolve(), | ||
searchExperiments, | ||
})); | ||
|
||
vi.mock('stores/userSettings', async (importOriginal) => { | ||
const userSettings = await import('stores/userSettings'); | ||
const store = new userSettings.UserSettingsStore(); | ||
|
||
store.clear(); | ||
|
||
return { | ||
...(await importOriginal<typeof import('stores/userSettings')>()), | ||
default: store, | ||
}; | ||
}); | ||
|
||
vi.mock('hooks/useMobile', async (importOriginal) => { | ||
return { | ||
...(await importOriginal<typeof import('hooks/useMobile')>()), | ||
default: () => false, | ||
}; | ||
}); | ||
|
||
const user = userEvent.setup(); | ||
|
||
const setup = (numExperiments?: number) => { | ||
searchExperiments.mockImplementation(() => { | ||
return Promise.resolve({ | ||
experiments: [], | ||
pagination: { total: numExperiments ?? 0 }, | ||
}); | ||
}); | ||
|
||
render( | ||
<UIProvider theme={DefaultTheme.Light}> | ||
<ThemeProvider> | ||
<BrowserRouter> | ||
<Searches project={projectMock} /> | ||
</BrowserRouter> | ||
</ThemeProvider> | ||
</UIProvider>, | ||
); | ||
}; | ||
|
||
describe('Searches', () => { | ||
it('should display count', async () => { | ||
setup(2); | ||
expect(screen.getByText('Loading searches...')).toBeInTheDocument(); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText('2 searches')).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('should display empty state', async () => { | ||
setup(); | ||
expect(screen.getByText('Loading searches...')).toBeInTheDocument(); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText('0 searches')).toBeInTheDocument(); | ||
expect(screen.getByText('No Searches')).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('should display column picker menu without tab selection', async () => { | ||
setup(); | ||
|
||
await user.click(screen.getByTestId('columns-menu-button')); | ||
expect(screen.queryByRole('tab')).not.toBeInTheDocument(); | ||
expect(screen.getByTestId('column-picker-tab')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should have hidden filter to exclude single-trial experiments', () => { | ||
setup(); | ||
|
||
expect(vi.mocked(searchExperiments)).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
filter: expectedFilterString, | ||
limit: defaultProjectSettings.pageLimit, | ||
offset: 0, | ||
projectId: projectMock.id, | ||
sort: defaultProjectSettings.sortString, | ||
}), | ||
{ signal: expect.any(AbortSignal) }, | ||
); | ||
}); | ||
}); |
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