-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FI-2000: Improve frontend testing coverage (#369)
* add footer and presets tests * add testsession and configmessages tests * add test run button tests * add test run mock data * add test suite tests * add progress bar tests * rename requests test file * update test list item tests * add selection panel tests * remove extra package lock * add testsession and actionmodal tests * fix selection type errors * update types * resolve semver vulnerability * convert test session to vitest * remove page test while actions are incorrectly mocking document title * locally define globals * add button tests for request list --------- Co-authored-by: Alyssa Wang <[email protected]>
- Loading branch information
1 parent
87b7a5c
commit 03e55f0
Showing
42 changed files
with
1,129 additions
and
387 deletions.
There are no files selected for viewing
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,28 @@ | ||
import React from 'react'; | ||
import { RouterProvider, createMemoryRouter } from 'react-router-dom'; | ||
import { render /* , waitFor */ } from '@testing-library/react'; | ||
import { testSuites } from '~/components/App/__mocked_data__/mockData'; | ||
import Page from '../Page'; | ||
|
||
describe('The Page Component', () => { | ||
test('sets page title on render', /* async */ () => { | ||
const pageTitle = 'Inferno Test Suites'; | ||
const routes = [ | ||
{ | ||
path: '/', | ||
element: ( | ||
<Page title={pageTitle}> | ||
<div>child component</div> | ||
</Page> | ||
), | ||
loader: () => testSuites, | ||
}, | ||
]; | ||
|
||
const router = createMemoryRouter(routes, { initialEntries: ['/'] }); | ||
render(<RouterProvider router={router} />); | ||
|
||
// TODO: comment out until Github actions can mock document title | ||
// await waitFor(() => expect(document.title).toEqual(pageTitle)); | ||
}); | ||
}); |
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
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
12 changes: 12 additions & 0 deletions
12
client/src/components/PresetsSelector/__mocked_data__/mockData.ts
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,12 @@ | ||
import { PresetSummary } from 'models/testSuiteModels'; | ||
|
||
export const presets: PresetSummary[] = [ | ||
{ | ||
id: 'one', | ||
title: 'Preset One', | ||
}, | ||
{ | ||
id: 'two', | ||
title: 'Preset Two', | ||
}, | ||
]; |
60 changes: 60 additions & 0 deletions
60
client/src/components/PresetsSelector/__tests__/PresetsSelector.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,60 @@ | ||
import React from 'react'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
import { SnackbarProvider } from 'notistack'; | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import ThemeProvider from '~/components/ThemeProvider'; | ||
import PresetsSelector from '../PresetsSelector'; | ||
import { presets } from '../__mocked_data__/mockData'; | ||
|
||
describe('The PresetsSelector Component', () => { | ||
test('renders empty PresetsSelector', () => { | ||
render( | ||
<BrowserRouter> | ||
<ThemeProvider> | ||
<SnackbarProvider> | ||
<PresetsSelector presets={[]} testSessionId="test-id" getSessionData={() => {}} /> | ||
</SnackbarProvider> | ||
</ThemeProvider> | ||
</BrowserRouter> | ||
); | ||
|
||
const selectionElement = screen.getByRole('button'); | ||
expect(selectionElement).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders PresetsSelector with options', () => { | ||
render( | ||
<BrowserRouter> | ||
<ThemeProvider> | ||
<SnackbarProvider> | ||
<PresetsSelector presets={presets} testSessionId="test-id" getSessionData={() => {}} /> | ||
</SnackbarProvider> | ||
</ThemeProvider> | ||
</BrowserRouter> | ||
); | ||
|
||
const selectionElement = screen.getByRole('button'); | ||
expect(selectionElement).toBeInTheDocument(); | ||
}); | ||
|
||
test('selects a preset', () => { | ||
render( | ||
<BrowserRouter> | ||
<ThemeProvider> | ||
<SnackbarProvider> | ||
<PresetsSelector presets={presets} testSessionId="test-id" getSessionData={() => {}} /> | ||
</SnackbarProvider> | ||
</ThemeProvider> | ||
</BrowserRouter> | ||
); | ||
|
||
const selectionElement = screen.getByRole('button'); | ||
userEvent.click(selectionElement); | ||
|
||
const presetChoice = screen.getByText('Preset One'); | ||
userEvent.click(presetChoice); | ||
|
||
expect(selectionElement.textContent).toEqual('Preset One'); | ||
}); | ||
}); |
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
26 changes: 26 additions & 0 deletions
26
.../components/TestSuite/ConfigMessagesDetails/__tests__/ConfigMessagesDetailsPanel.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,26 @@ | ||
import React from 'react'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { SnackbarProvider } from 'notistack'; | ||
import ThemeProvider from 'components/ThemeProvider'; | ||
import { testSuites } from '~/components/App/__mocked_data__/mockData'; | ||
import ConfigMessagesDetailsPanel from '../ConfigMessagesDetailsPanel'; | ||
|
||
test('renders ConfigMessagesDetailsPanel', () => { | ||
render( | ||
<BrowserRouter> | ||
<ThemeProvider> | ||
<SnackbarProvider> | ||
<ConfigMessagesDetailsPanel testSuite={testSuites[0]} /> | ||
</SnackbarProvider> | ||
</ThemeProvider> | ||
</BrowserRouter> | ||
); | ||
|
||
const tabsList = screen.getAllByRole('tab'); | ||
expect(tabsList.length).toEqual(3); | ||
|
||
expect(screen.getByLabelText('Errors')).toBeInTheDocument(); | ||
expect(screen.getByLabelText('Warnings')).toBeInTheDocument(); | ||
expect(screen.getByLabelText('Info')).toBeInTheDocument(); | ||
}); |
18 changes: 18 additions & 0 deletions
18
client/src/components/TestSuite/TestRunButton/__mocked_data__/mockData.ts
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,18 @@ | ||
import { | ||
mockedTest, | ||
mockedTestGroup, | ||
mockedTestSuite, | ||
} from '~/components/_common/__mocked_data__/mockData'; | ||
import { RunnableType } from '~/models/testSuiteModels'; | ||
|
||
export const mockedRunTests = (runnableType: RunnableType, runnableId: string) => { | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const data = [runnableType, runnableId]; | ||
}; | ||
|
||
export const mockedTestRunButtonData = { | ||
test: mockedTest, | ||
testGroup: mockedTestGroup, | ||
testSuite: mockedTestSuite, | ||
runTests: mockedRunTests, | ||
}; |
Oops, something went wrong.