This repository has been archived by the owner on Oct 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: additional unit tests for multi-project tokens - (#863)
* refactor: add theme to test renderer * feat: add tests to token list * projects list for multi-project tokens * refactor: api token form available projects map * update variable name * fix: restore selected project on token type change * fix: select project input code formatting * fix: improve code formatting after review
- Loading branch information
Showing
7 changed files
with
98 additions
and
24 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
62 changes: 62 additions & 0 deletions
62
src/component/admin/apiToken/ApiTokenForm/SelectProjectInput/SelectProjectInput.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,62 @@ | ||
import React from 'react'; | ||
import { screen, within } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { render } from 'utils/testRenderer'; | ||
import { | ||
ISelectProjectInputProps, | ||
SelectProjectInput, | ||
} from './SelectProjectInput'; | ||
|
||
const onChange = jest.fn(); | ||
const onFocus = jest.fn(); | ||
|
||
const mockProps: ISelectProjectInputProps = { | ||
options: [ | ||
{ label: 'Project1', value: 'project1' }, | ||
{ label: 'Project2', value: 'project2' }, | ||
], | ||
defaultValue: ['*'], | ||
onChange, | ||
onFocus, | ||
}; | ||
|
||
describe('SelectProjectInput', () => { | ||
beforeEach(() => { | ||
onChange.mockClear(); | ||
onFocus.mockClear(); | ||
}); | ||
|
||
it('renders with default state', () => { | ||
render(<SelectProjectInput {...mockProps} />); | ||
|
||
const checkbox = screen.getByLabelText( | ||
/all current and future projects/i | ||
); | ||
expect(checkbox).toBeChecked(); | ||
|
||
const selectInputContainer = screen.getByTestId('select-input'); | ||
const input = within(selectInputContainer).getByRole('textbox'); | ||
expect(input).toBeDisabled(); | ||
}); | ||
|
||
it('can toggle "ALL" checkbox', async () => { | ||
const user = userEvent.setup(); | ||
render(<SelectProjectInput {...mockProps} />); | ||
|
||
await user.click(screen.getByTestId('select-all-projects')); | ||
|
||
expect( | ||
screen.getByLabelText(/all current and future projects/i) | ||
).not.toBeChecked(); | ||
|
||
expect(screen.getByLabelText('Projects')).toBeEnabled(); | ||
|
||
await user.click(screen.getByTestId('select-all-projects')); | ||
|
||
expect( | ||
screen.getByLabelText(/all current and future projects/i) | ||
).toBeChecked(); | ||
|
||
expect(screen.getByLabelText('Projects')).toBeDisabled(); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React, { FC } from 'react'; | ||
import { CssBaseline, StylesProvider, ThemeProvider } from '@material-ui/core'; | ||
import mainTheme from './mainTheme'; | ||
|
||
export const MainThemeProvider: FC = ({ children }) => ( | ||
<ThemeProvider theme={mainTheme}> | ||
<StylesProvider injectFirst> | ||
<CssBaseline /> | ||
{children} | ||
</StylesProvider> | ||
</ThemeProvider> | ||
); |
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