mirror of
https://github.com/kremalicious/portfolio.git
synced 2024-12-22 17:23:22 +01:00
rewrite ThemeSwitch tests
This commit is contained in:
parent
730174f34c
commit
66350829ee
@ -1,21 +1,32 @@
|
||||
import { cleanup, fireEvent, render, waitFor } from '@testing-library/react'
|
||||
import ThemeSwitch from '.'
|
||||
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
|
||||
import ThemeSwitch, { getIconName } from '.'
|
||||
|
||||
describe('ThemeSwitch', () => {
|
||||
afterEach(cleanup)
|
||||
|
||||
it('renders correctly', async () => {
|
||||
const { container } = render(<ThemeSwitch />)
|
||||
await waitFor(() => container.querySelector('aside'))
|
||||
expect(container.querySelector('aside')).toBeInTheDocument()
|
||||
render(<ThemeSwitch />)
|
||||
const button = await screen.findByRole('combobox')
|
||||
expect(button).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('checkbox can be changed', async () => {
|
||||
const { container } = render(<ThemeSwitch />)
|
||||
it('button can be clicked', async () => {
|
||||
render(<ThemeSwitch />)
|
||||
const button = await screen.findByRole('combobox')
|
||||
fireEvent.click(button)
|
||||
})
|
||||
|
||||
const toggle = container.querySelector('input')
|
||||
const label = container.querySelector('label')
|
||||
fireEvent.click(label)
|
||||
fireEvent.change(toggle, { target: { checked: true } })
|
||||
it('getIconName', () => {
|
||||
let theme = 'light'
|
||||
const icon = getIconName(theme)
|
||||
expect(icon).toBe('Sun')
|
||||
|
||||
theme = 'dark'
|
||||
const icon2 = getIconName(theme)
|
||||
expect(icon2).toBe('Moon')
|
||||
|
||||
theme = 'system'
|
||||
const icon3 = getIconName(theme)
|
||||
expect(icon3).toBe('Monitor')
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user