tests/e2e/run-checks-settings.spec.ts
Rama main · réplica de lectura del repositorio original.
import { enableScopedE2EAuth, scopedPath } from "./helpers/auth";
import { expect, test, fulfillJson } from "./helpers/run-checks-fixtures";
const ENDPOINT = "**/api/settings/decision-checks";
test("Account settings show Run checks on, say what is sent, and save a change", async ({
page,
}) => {
await enableScopedE2EAuth(page);
let enabled = true;
const patchBodies: unknown[] = [];
await page.route(ENDPOINT, async (route) => {
const request = route.request();
if (request.method() === "PATCH") {
const body = request.postDataJSON() as { enabled: boolean };
patchBodies.push(body);
enabled = body.enabled;
}
await fulfillJson(route, { enabled, viewer: { canManage: true } });
});
await page.goto(scopedPath("settings"));
const toggle = page.getByRole("switch", { name: "Run checks" });
await expect(toggle).toBeChecked();
// The copy is the customer's only account of what leaves their workspace.
await expect(
page.getByText(
/summaries of the skills available to it\. Secrets are removed\./
)
).toBeVisible();
await expect(page.getByText(/^Nothing is sent\./)).toBeVisible();
await toggle.click();
await expect(toggle).not.toBeChecked();
expect(patchBodies).toEqual([{ enabled: false }]);
await page.reload();
await expect(
page.getByRole("switch", { name: "Run checks" })
).not.toBeChecked();
});
test("Run checks stays on and says so when the change cannot be saved", async ({
page,
}) => {
await enableScopedE2EAuth(page);
await page.route(ENDPOINT, async (route) => {
if (route.request().method() === "PATCH") {
await fulfillJson(route, { error: "Unable to save run checks" }, 500);
return;
}
await fulfillJson(route, { enabled: true, viewer: { canManage: true } });
});
await page.goto(scopedPath("settings"));
const toggle = page.getByRole("switch", { name: "Run checks" });
await expect(toggle).toBeChecked();
await toggle.click();
await expect(page.getByText("Unable to save run checks")).toBeVisible();
await expect(toggle).toBeChecked();
});
test("Account settings show Run checks before the GitHub section", async ({
page,
}) => {
await enableScopedE2EAuth(page);
await page.route(ENDPOINT, (route) =>
fulfillJson(route, { enabled: true, viewer: { canManage: true } })
);
await page.goto(scopedPath("settings/account"));
const runChecks = page.getByRole("switch", { name: "Run checks" });
const github = page.getByText(
/Mogplex works on repositories in the GitHub accounts/
);
await expect(runChecks).toBeVisible();
await expect(github).toBeVisible();
const [switchBox, githubBox] = await Promise.all([
runChecks.boundingBox(),
github.boundingBox(),
]);
expect(switchBox?.y ?? Infinity).toBeLessThan(githubBox?.y ?? 0);
});