-
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.
- Loading branch information
1 parent
b92fe9a
commit 2afe302
Showing
12 changed files
with
204 additions
and
7 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
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
34 changes: 34 additions & 0 deletions
34
client/src/components/TestSuite/TestSuiteDetails/__tests__/TestSuiteDetailsPanel.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,34 @@ | ||
import React from 'react'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { SnackbarProvider } from 'notistack'; | ||
import ThemeProvider from 'components/ThemeProvider'; | ||
import TestSuiteDetailsPanel from '~/components/TestSuite//TestSuiteDetails/TestSuiteDetailsPanel'; | ||
import { mockedTestSuite } from '~/components/_common/__mocked_data__/mockData'; | ||
import { mockedRunTests } from '~/components/TestSuite/TestRunButton/__mocked_data__/mockData'; | ||
import { mockedRequestFunctions } from '~/components/RequestDetailModal/__mocked_data__/mockData'; | ||
|
||
test('renders TestSuiteDetailsPanel for test suite', () => { | ||
render( | ||
<MemoryRouter> | ||
<ThemeProvider> | ||
<SnackbarProvider> | ||
<TestSuiteDetailsPanel | ||
runnable={mockedTestSuite} | ||
runTests={mockedRunTests} | ||
updateRequest={mockedRequestFunctions.updateRequest} | ||
/> | ||
</SnackbarProvider> | ||
</ThemeProvider> | ||
</MemoryRouter> | ||
); | ||
|
||
const suiteTitleElement = screen.getByText(mockedTestSuite.title); | ||
expect(suiteTitleElement).toBeInTheDocument(); | ||
|
||
const groupTitles = mockedTestSuite.test_groups?.map((group) => group.title) || []; | ||
groupTitles.forEach((groupTitle) => { | ||
const groupTitleElement = screen.getByText(groupTitle); | ||
expect(groupTitleElement).toBeInTheDocument(); | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
client/src/components/TestSuite/TestSuiteDetails/__tests__/TestSuiteReport.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,22 @@ | ||
import React from 'react'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { SnackbarProvider } from 'notistack'; | ||
import ThemeProvider from 'components/ThemeProvider'; | ||
import TestSuiteReport from '../TestSuiteReport'; | ||
import { mockedTestSuite } from '~/components/_common/__mocked_data__/mockData'; | ||
|
||
test('renders TestSuiteReport', () => { | ||
render( | ||
<MemoryRouter> | ||
<ThemeProvider> | ||
<SnackbarProvider> | ||
<TestSuiteReport testSuite={mockedTestSuite} /> | ||
</SnackbarProvider> | ||
</ThemeProvider> | ||
</MemoryRouter> | ||
); | ||
|
||
const reportTitleElement = screen.getByText(`${mockedTestSuite.title} Report`); | ||
expect(reportTitleElement).toBeInTheDocument(); | ||
}); |
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
45 changes: 45 additions & 0 deletions
45
client/src/components/_common/SelectionPanel/__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,45 @@ | ||
/* eslint-disable @typescript-eslint/no-empty-function */ | ||
import { | ||
ListOption, | ||
ListOptionSelection, | ||
RadioOption, | ||
RadioOptionSelection, | ||
} from '~/models/selectionModels'; | ||
|
||
export const mockedListOptions: ListOption[] = [ | ||
{ id: 'one', title: 'One' }, | ||
{ id: 'two', title: 'Two' }, | ||
]; | ||
|
||
export const mockedRadioOptions: RadioOption[] = [ | ||
{ | ||
id: 'one', | ||
title: 'One', | ||
description: 'Option One Description', | ||
list_options: [ | ||
{ label: 'Choice A', id: 'choice-a', value: 'a' }, | ||
{ label: 'Choice B', id: 'choice-b', value: 'b' }, | ||
], | ||
}, | ||
{ | ||
id: 'two', | ||
title: 'Two', | ||
description: 'Option Two Description', | ||
list_options: [ | ||
{ label: 'Choice C', id: 'choice-c', value: 'c' }, | ||
{ label: 'Choice D', id: 'choice-d', value: 'd' }, | ||
], | ||
}, | ||
]; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
export const mockedSetSelected = (selected: ListOptionSelection | RadioOptionSelection[]) => {}; | ||
|
||
export const mockedSubmit = () => {}; | ||
|
||
export const mockedSelectionPanelData = { | ||
listOptions: mockedListOptions, | ||
radioOptions: mockedRadioOptions, | ||
setSelected: mockedSetSelected, | ||
submitAction: mockedSubmit, | ||
}; |
81 changes: 81 additions & 0 deletions
81
client/src/components/_common/SelectionPanel/__tests__/SelectionPanel.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,81 @@ | ||
import React from 'react'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import ThemeProvider from 'components/ThemeProvider'; | ||
import { mockedSelectionPanelData } from '../__mocked_data__/mockData'; | ||
import SelectionPanel from '../SelectionPanel'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { vi } from 'vitest'; | ||
|
||
describe('SelectionPanel component', () => { | ||
test('renders SelectionPanel for list options', () => { | ||
render( | ||
<BrowserRouter> | ||
<ThemeProvider> | ||
<SelectionPanel | ||
title="Selection Title" | ||
options={mockedSelectionPanelData.listOptions} | ||
setSelection={mockedSelectionPanelData.setSelected} | ||
submitAction={mockedSelectionPanelData.submitAction} | ||
submitText="Submit" | ||
/> | ||
</ThemeProvider> | ||
</BrowserRouter> | ||
); | ||
|
||
const options = screen.getAllByTestId('list-option'); | ||
expect(options.length).toEqual(mockedSelectionPanelData.listOptions.length); | ||
}); | ||
|
||
test('renders SelectionPanel for radio options', () => { | ||
render( | ||
<BrowserRouter> | ||
<ThemeProvider> | ||
<SelectionPanel | ||
title="Selection Title" | ||
options={mockedSelectionPanelData.radioOptions} | ||
setSelection={mockedSelectionPanelData.setSelected} | ||
submitAction={mockedSelectionPanelData.submitAction} | ||
submitText="Submit" | ||
/> | ||
</ThemeProvider> | ||
</BrowserRouter> | ||
); | ||
|
||
const options = screen.getAllByTestId('radio-option-group'); | ||
expect(options.length).toEqual(mockedSelectionPanelData.radioOptions.length); | ||
|
||
const radioButtonCount = mockedSelectionPanelData.radioOptions | ||
.map((option) => option.list_options) | ||
.flat().length; | ||
const buttons = screen.getAllByTestId('radio-option-button'); | ||
expect(buttons.length).toEqual(radioButtonCount); | ||
}); | ||
|
||
test('clicking submit calls submitAction', async () => { | ||
const submitAction = vi.spyOn(mockedSelectionPanelData, 'submitAction'); | ||
|
||
render( | ||
<BrowserRouter> | ||
<ThemeProvider> | ||
<SelectionPanel | ||
title="Selection Title" | ||
options={mockedSelectionPanelData.listOptions} | ||
setSelection={mockedSelectionPanelData.setSelected} | ||
submitAction={mockedSelectionPanelData.submitAction} | ||
submitText="Submit" | ||
/> | ||
</ThemeProvider> | ||
</BrowserRouter> | ||
); | ||
|
||
const submitButton = screen.getByText('Submit'); | ||
userEvent.click(submitButton); | ||
expect(submitAction).toBeCalledTimes(0); // should be disabled with no selection | ||
|
||
const options = screen.getAllByTestId('list-option'); | ||
userEvent.click(options[0]); // select first option | ||
userEvent.click(submitButton); | ||
await waitFor(() => expect(submitAction).toBeCalled()); | ||
}); | ||
}); |
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