IKHSAN
ENID Baca dalam Bahasa Indonesia

opendesk

Public
Branch
main
Latest commit
08d9f3328 October 2026

settings.ts

Open raw
import { expect, type Page } from "@playwright/test";
import type { Api } from "./api";

/** Open the settings modal from the user menu and switch to a tab. */
export async function openSettings(page: Page, tab: string | RegExp) {
  await page.getByRole("button", { name: /^Opendesk / }).click();
  await page.getByRole("menuitem", { name: "Settings" }).click();
  const dialog = page.getByRole("dialog");
  await dialog.getByRole("button", { name: tab, exact: true }).click();
  await expect(dialog.getByRole("heading", { level: 1 }).nth(1)).toBeVisible();
  return dialog;
}

/** Snapshot OD Settings fields so a test can put them back afterwards. */
export async function snapshotSettings(api: Api, fields: string[]) {
  const settings = await api.get("OD Settings", "OD Settings");
  // REST updates skip nulls, so an empty field is restored as "".
  const saved = Object.fromEntries(fields.map((field) => [field, settings[field] ?? ""]));
  return () => api.update("OD Settings", "OD Settings", saved);
}

/** Create an active agent nobody else uses, safe to disable or delete. */
export async function createThrowawayAgent(api: Api, email: string, password?: string) {
  await api.insert("User", {
    email,
    first_name: email.split("@")[0],
    send_welcome_email: 0,
    roles: [{ role: "Agent" }],
    ...(password && { new_password: password }),
  });
  return api.insert("OD Agent", { user: email, agent_name: email.split("@")[0], is_active: 1 });
}
bytes
1,465
lines
33
Type
ts
Latest commit
28 October 2026