1import type { Page } from "@playwright/test";
2import type { Api } from "../helpers/api";
3import { expect, test, uid } from "../helpers/fixtures";
4
5const ANSWERS = [
6 "Spreadsheets",
7 "Email",
8 "Via email",
9 "Finding past conversations",
10 "GitHub",
11 "Create my first ticket",
12];
13
14test.describe.configure({ mode: "serial" });
15
16test.describe("onboarding persona form", () => {
17 let brandName: string;
18 let appName: string;
19
20 // Finishing the form renames the brand, so put the old names back.
21 test.beforeEach(async ({ api }) => {
22 brandName = (await api.get("OD Settings", "OD Settings")).brand_name || "";
23 appName = (await api.get("Website Settings", "Website Settings")).app_name || "";
24 await setPersonaCaptured(api, 0);
25 });
26
27 test.afterEach(async ({ api }) => {
28 await api.update("OD Settings", "OD Settings", {
29 persona_captured: 1,
30 brand_name: brandName,
31 });
32 await api.update("Website Settings", "Website Settings", { app_name: appName });
33 });
34
35 test("an uncaptured admin fills the questionnaire once", async ({ api, pageAs }) => {
36 const page = await pageAs("admin");
37 const company = `E2E Org ${uid()}`;
38 await page.goto("/opendesk/onboarding");
39
40 await page.getByPlaceholder("e.g. Acme Inc.").fill(company);
41 await page.getByRole("button", { name: "Next", exact: true }).click();
42 for (const answer of ANSWERS) {
43 await page.getByRole("button", { name: answer, exact: true }).click();
44 const last = answer === ANSWERS.at(-1);
45 await page.getByRole("button", { name: last ? "Finish" : "Next", exact: true }).click();
46 }
47
48 await expect(page).toHaveURL(/\/opendesk\/tickets\/new/);
49 const settings = await api.get("OD Settings", "OD Settings");
50 expect(settings.persona_captured).toBe(1);
51 expect(settings.brand_name).toBe(company);
52
53 await expectBlocked(page);
54 });
55
56 test("agents, managers and customers never see it", async ({ pageAs }) => {
57 for (const persona of ["agent", "manager", "customer"] as const) {
58 await expectBlocked(await pageAs(persona));
59 }
60 });
61
62 test("a captured admin cannot reopen it", async ({ api, pageAs }) => {
63 await setPersonaCaptured(api, 1);
64 await expectBlocked(await pageAs("admin"));
65 });
66
67 test("an admin is interrupted only while telemetry is on", async ({ pageAs }) => {
68 const withTelemetry = await pageAs("admin");
69 await forceTelemetry(withTelemetry);
70 await withTelemetry.goto("/opendesk/tickets");
71 await expect(withTelemetry).toHaveURL(/\/opendesk\/onboarding$/);
72
73 const withoutTelemetry = await pageAs("admin");
74 await withoutTelemetry.goto("/opendesk/tickets");
75 await expect(withoutTelemetry.getByRole("button", { name: "Filter", exact: true })).toBeVisible();
76 await expect(withoutTelemetry).toHaveURL(/\/opendesk\/tickets$/);
77 });
78});
79
80async function setPersonaCaptured(api: Api, value: 0 | 1) {
81 await api.update("OD Settings", "OD Settings", { persona_captured: value });
82}
83
84async function expectBlocked(page: Page) {
85 await page.goto("/opendesk/onboarding");
86 await expect(page).not.toHaveURL(/\/onboarding/);
87 await expect(page.getByPlaceholder("e.g. Acme Inc.")).toHaveCount(0);
88}
89
90// The boot script assigns window.telemetry; pin it on and swallow the write.
91async function forceTelemetry(page: Page) {
92 await page.addInitScript(() => {
93 Object.defineProperty(window, "telemetry", {
94 get: () => ({ enabled: true }),
95 set: () => {},
96 configurable: true,
97 });
98 });
99}
100