-
Notifications
You must be signed in to change notification settings - Fork 0
/
ThemeExample.test.tsx
51 lines (50 loc) · 2.01 KB
/
ThemeExample.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { render, screen } from "../test-utils"
import { Theme } from "../ThemeContext"
import ThemeExample from "./ThemeExample"
import userEvent from "@testing-library/user-event"
describe("Theme example", () => {
it("displays dark mode is off in light theme", () => {
render(<ThemeExample />, {
theme: { theme: Theme.LIGHT, setTheme: vi.fn() },
})
const text = screen.getByText("Dark mode: Off")
expect(text).toBeInTheDocument()
})
it("displays dark mode is on in dark theme", () => {
render(<ThemeExample />, {
theme: { theme: Theme.DARK, setTheme: vi.fn() },
})
const text = screen.getByText("Dark mode: On")
expect(text).toBeInTheDocument()
})
it("calls setTheme() when change theme button is clicked", async () => {
const spy = vi.fn()
const user = userEvent.setup()
render(<ThemeExample />, {
theme: { theme: Theme.LIGHT, setTheme: spy },
})
const button = screen.getByRole("button", { name: "Change Theme" })
await user.click(button)
expect(spy).toHaveBeenCalled()
})
it("calls setTheme() with the LIGHT enum when change theme button is clicked in dark mode", async () => {
const spy = vi.fn()
const user = userEvent.setup()
render(<ThemeExample />, {
theme: { theme: Theme.DARK, setTheme: spy },
})
const button = screen.getByRole("button", { name: "Change Theme" })
await user.click(button)
expect(spy).toHaveBeenCalledWith(Theme.LIGHT)
})
it("calls setTheme() with the DARK enum when change theme button is clicked in light mode", async () => {
const spy = vi.fn()
const user = userEvent.setup()
render(<ThemeExample />, {
theme: { theme: Theme.LIGHT, setTheme: spy },
})
const button = screen.getByRole("button", { name: "Change Theme" })
await user.click(button)
expect(spy).toHaveBeenCalledWith(Theme.DARK)
})
})