Repository navigation
Expand file tree
/
Copy pathExperimentalFeatures.test.tsx
More file actions
52 lines (49 loc) · 1.61 KB
/
Copy pathExperimentalFeatures.test.tsx
File metadata and controls
52 lines (49 loc) · 1.61 KB
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
52
import { fireEvent, render, screen, cleanup } from "@testing-library/react";
import { afterEach, expect, test, vi } from "vitest";
import ExperimentalFeatures, { FeatureContext } from "./ExperimentalFeatures";
import AccountSelection from "./AccountSelection";
afterEach(cleanup);
const t = (_zh: string, en: string) => en;
test("enabling requires acknowledging the selected feature, not just opening settings", () => {
const mutate = vi.fn().mockResolvedValue(true);
render(
<ExperimentalFeatures features={{}} mutate={mutate} busy={false} t={t} />,
);
const enable = screen.getAllByRole("button", {
name: "Enable",
hidden: true,
})[0];
expect((enable as HTMLButtonElement).disabled).toBe(true);
fireEvent.click(screen.getAllByRole("checkbox", { hidden: true })[0]);
fireEvent.click(enable);
expect(mutate).toHaveBeenCalledWith("/api/features", {
name: "automatic_failover",
enabled: true,
acknowledged: true,
});
});
test("automatic failover is unavailable when the server disables it", () => {
render(
<FeatureContext.Provider value={{ automatic_failover: false }}>
<AccountSelection
provider="codex"
environment="local"
accounts={[]}
value={{ account_policy: "manual" }}
onChange={() => {}}
t={t}
/>
</FeatureContext.Provider>,
);
expect(
(
screen.getByRole("option", {
name: "Switch on quota or sign-in failure",
}) as HTMLOptionElement
).disabled,
).toBe(true);
expect(
(screen.getByRole("option", { name: "Fixed account" }) as HTMLOptionElement)
.disabled,
).toBe(false);
});