-
Notifications
You must be signed in to change notification settings - Fork 12
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
9917115
commit e1eb6c3
Showing
3 changed files
with
52 additions
and
5 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
49 changes: 49 additions & 0 deletions
49
frontend/src/components/ThemedButtons/DetailElement.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,49 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { ReactNode } from 'react'; | ||
import { describe, expect, test } from 'vitest'; | ||
|
||
import DetailElement from './DetailElement'; | ||
|
||
const renderComponent = (content: ReactNode, buttonText?: string) => { | ||
const user = userEvent.setup(); | ||
render( | ||
<DetailElement useIcon={true} buttonText={buttonText}> | ||
{content} | ||
</DetailElement> | ||
); | ||
|
||
return { user }; | ||
}; | ||
|
||
const detailButton = (name: string = 'Details') => screen.getByRole('button', { name }); | ||
Check failure on line 19 in frontend/src/components/ThemedButtons/DetailElement.test.tsx
|
||
|
||
describe('DetailElement component tests', () => { | ||
test('Renders collapsed initially with Details button by default', () => { | ||
const textContent = 'Well hello there'; | ||
renderComponent(<>{textContent}</>); | ||
|
||
const button = detailButton(); | ||
expect(button).toBeInTheDocument(); | ||
expect(button).toHaveAttribute('aria-expanded', 'false'); | ||
expect(screen.getByText(textContent)).not.toBeVisible(); | ||
}); | ||
|
||
test('Expands on clicking Details button', async () => { | ||
const textContent = 'Well hello there'; | ||
const { user } = renderComponent(<>{textContent}</>); | ||
|
||
const button = detailButton(); | ||
await user.click(button); | ||
|
||
expect(button).toHaveAttribute('aria-expanded', 'true'); | ||
expect(screen.getByText(textContent)).toBeVisible(); | ||
}); | ||
|
||
test('Button can have a custom name', () => { | ||
const buttonText = 'This is my button, there are many others like it but this one is mine'; | ||
renderComponent(<>without my button i am nothing</>, buttonText); | ||
|
||
expect(detailButton(buttonText)).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