-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #135 from andrewnguonly/1.0.11
PR for app version `1.0.11`
- Loading branch information
Showing
17 changed files
with
953 additions
and
486 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import { render, act } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import "@testing-library/jest-dom"; | ||
import { | ||
ThemeProvider, | ||
useThemeContext, | ||
} from "../../src/contexts/ThemeContext"; | ||
|
||
const MockComponent = () => { | ||
const { theme, toggleDarkMode } = useThemeContext(); | ||
return ( | ||
<div> | ||
<span>Current Theme: {theme.palette.mode}</span> | ||
<button onClick={toggleDarkMode}>Toggle Theme</button> | ||
</div> | ||
); | ||
}; | ||
|
||
describe("ThemeProvider", () => { | ||
it("toggles the theme from light to dark and back", async () => { | ||
const mockGet = jest.fn().mockResolvedValue({ darkModeEnabled: false }); | ||
const mockSet = jest.fn(); | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
global.chrome = { | ||
storage: { | ||
local: { | ||
get: mockGet, | ||
set: mockSet, | ||
}, | ||
}, | ||
} as any; | ||
/* eslint-enable @typescript-eslint/no-explicit-any */ | ||
|
||
const { findByText } = render( | ||
<ThemeProvider> | ||
<MockComponent /> | ||
</ThemeProvider>, | ||
); | ||
|
||
expect(await findByText(/Current Theme: light/i)).toBeInTheDocument(); | ||
|
||
const toggleButton = await findByText("Toggle Theme"); | ||
await act(async () => userEvent.click(toggleButton)); | ||
|
||
expect(await findByText(/Current Theme: dark/i)).toBeInTheDocument(); | ||
|
||
await act(async () => userEvent.click(toggleButton)); | ||
|
||
expect(await findByText(/Current Theme: light/i)).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
Oops, something went wrong.