Skip to content

Commit b6d732b

Browse files
committed
test: Add tests for ConfigProvider context
1 parent 23d0709 commit b6d732b

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { describe, it, expect } from "vitest";
2+
import { render, act } from "@testing-library/react";
3+
import { ConfigProvider } from "../../../src/context/config-provider";
4+
import { ConfigContext } from "../../../src/context/config-context";
5+
import { map } from "nanostores";
6+
import { useContext } from "react";
7+
import { FUIConfig } from "@firebase-ui/core";
8+
9+
// Mock component to test context value
10+
function TestConsumer() {
11+
const config = useContext(ConfigContext);
12+
return <div data-testid="test-value">{config.language || "no-value"}</div>;
13+
}
14+
15+
describe("ConfigProvider", () => {
16+
it("provides the config value to children", () => {
17+
// Create a mock config store with the correct FUIConfig properties
18+
const mockConfig = map<FUIConfig>({
19+
language: "en",
20+
});
21+
22+
const { getByTestId } = render(
23+
<ConfigProvider config={mockConfig}>
24+
<TestConsumer />
25+
</ConfigProvider>
26+
);
27+
28+
expect(getByTestId("test-value").textContent).toBe("en");
29+
});
30+
31+
it("updates when the config store changes", () => {
32+
// Create a mock config store
33+
const mockConfig = map<FUIConfig>({
34+
language: "en",
35+
});
36+
37+
const { getByTestId } = render(
38+
<ConfigProvider config={mockConfig}>
39+
<TestConsumer />
40+
</ConfigProvider>
41+
);
42+
43+
expect(getByTestId("test-value").textContent).toBe("en");
44+
45+
// Update the config store inside act()
46+
act(() => {
47+
mockConfig.setKey("language", "fr");
48+
});
49+
50+
// Check that the context value was updated
51+
expect(getByTestId("test-value").textContent).toBe("fr");
52+
});
53+
});

0 commit comments

Comments
 (0)