Repository Public
1// Téléphone (390 × 844) : navigation de la console, assistant de clé d'API, approbations, boîte unifiée.2// Aucun défilement horizontal, tableaux en fiches, dialogues utilisables au doigt.3import { list, row } from "../helpers"4import { api, apiKey, axe, expect, grantReauth, noOverflow, openAdmin, sendMail, st, test, toastText, waitForMessage } from "./fixtures"56const addressId = async (address: string): Promise<string> => (await api("GET", `/api/v1/addresses/${encodeURIComponent(address)}`)).body.id78test("téléphone : navigation de la console (groupes défilants, sections, pas de débordement)", async ({ page }) => {9 await openAdmin(page, "overview")10 const nav = page.locator(".page-nav")11 await noOverflow(page)12 for (const [label, id] of [["Adresses", "addresses"], ["Clés d'API", "keys"], ["Webhooks", "webhooks"], ["Explorateur", "explorer"], ["Livraison", "metrics"], ["Santé", "health"], ["Stockage", "storage"], ["Messages programmés", "scheduled"]]) {13 const link = nav.getByRole("link", { name: label, exact: true })14 await link.scrollIntoViewIfNeeded()15 await link.click()16 await expect(page).toHaveURL(new RegExp(`/admin/${id}$`))17 await expect(page.getByRole("heading", { level: 2, name: label })).toBeVisible()18 await expect(page.locator("main#main .adm, main#main .spinner").first()).toBeVisible()19 await page.waitForLoadState("networkidle")20 await noOverflow(page)21 }22 await axe(page, "phone-admin-nav")23 await page.getByRole("link", { name: "Courrier" }).click()24 await expect(page.locator("#sidebar")).toBeAttached()25})2627test("téléphone : assistant de clé d'API jusqu'au secret affiché une fois", async ({ page }) => {28 const name = `Tel ${st.run}`29 grantReauth()30 await openAdmin(page, "keys")31 await page.getByTestId("key-new").click()32 const dlg = page.getByRole("dialog", { name: "Nouvelle clé d'API" })33 await dlg.getByLabel("Nom de la clé").fill(name)34 await noOverflow(page)35 await page.getByTestId("key-next").click()36 await dlg.getByRole("radio", { name: /^Lecture seule \(agent\)/ }).check()37 await axe(page, "phone-key-wizard-scopes")38 await page.getByTestId("key-next").click()39 await page.getByTestId("address-picker").getByRole("checkbox", { name: new RegExp(`^${st.addrA.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`) }).check()40 await noOverflow(page)41 await page.getByTestId("key-next").click()42 await page.getByTestId("key-next").click()43 await page.getByTestId("key-next").click()44 await expect(page.getByTestId("key-review")).toContainText(st.addrA)45 await noOverflow(page)46 await page.getByTestId("key-submit").click()47 const secret = page.getByTestId("secret-dialog")48 await expect(secret).toBeVisible()49 const token = await page.getByTestId("secret-value").inputValue()50 expect(token).toMatch(/^spm_/)51 await noOverflow(page)52 await axe(page, "phone-key-secret")53 await expect(secret.getByRole("button", { name: "Fermer" })).toBeDisabled()54 await secret.getByRole("checkbox", { name: /J'ai enregistré ce secret/ }).check()55 await secret.getByRole("button", { name: "Fermer" }).click()56 await expect(secret).toBeHidden()57 // la clé fonctionne, et son secret n'est plus nulle part dans la page58 expect((await apiKey(token, "GET", "/me")).body.name).toBe(name)59 expect(await page.content()).not.toContain(token)60 expect(await page.evaluate(() => JSON.stringify({ ...localStorage }) + JSON.stringify({ ...sessionStorage }))).not.toContain(token.slice(15))61 // la liste devient des fiches62 await expect(page.locator(`tr[data-key-name="${name}"]`)).toBeVisible()63 await noOverflow(page)64})6566test("téléphone : approbations — file d'attente, pastilles, rejet", async ({ page, watch }) => {67 watch.allow.push(/status of 40[39]/)68 grantReauth()69 const key = await api("POST", "/api/admin/api-keys", { name: `Tel approbation ${st.run}`, scopes: ["mail.send"], address_ids: [await addressId(st.addrA)], external_send_policy: "approval" })70 expect(key.status, JSON.stringify(key.body)).toBe(201)71 const subject = `À approuver tel ${st.run}`72 const send = await apiKey(key.body.token, "POST", "/messages/send", { from: st.addrA, to: [{ email: st.addrExt }], subject, text: "En attente." })73 expect(send.status).toBe(202)74 expect(send.body.status).toBe("pending_approval")7576 // pastille discrète dans la barre latérale du courrier77 await page.goto("/")78 await page.getByRole("button", { name: "Ouvrir le menu" }).first().click()79 await expect(page.getByTestId("sidebar-approvals")).toContainText("1")80 await page.getByRole("link", { name: /Administration/ }).click()81 await page.locator(".page-nav").getByRole("link", { name: /Approbations/ }).click()82 await expect(page.getByTestId("nav-badge-approvals")).toHaveText("1")83 const card = page.locator(`[data-testid="approval-card"][data-outbound-id="${send.body.id}"]`)84 await expect(card).toBeVisible()85 await expect(card).toContainText(st.addrExt)86 await noOverflow(page)87 await axe(page, "phone-approvals")88 await card.getByRole("button", { name: `Rejeter l'envoi « ${subject} »` }).click()89 await page.getByRole("alertdialog", { name: "Rejeter cet envoi ?" }).getByRole("button", { name: "Rejeter l'envoi", exact: true }).click()90 await expect(card).toHaveCount(0)91 await expect(page.getByTestId("nav-badge-approvals")).toHaveCount(0)92 expect((await apiKey(key.body.token, "GET", `/messages/outbound/${send.body.id}`)).body.status).toBe("cancelled")93})9495test("téléphone : boîte unifiée — liste, pastille d'adresse, lecture, retour", async ({ page }) => {96 const subject = `Unifié tel ${st.run}`97 await sendMail(st.addrA, st.addrB, subject)98 await waitForMessage(st.addrB, subject)99 await page.goto("/")100 await page.getByRole("button", { name: "Ouvrir le menu" }).first().click()101 await page.getByRole("link", { name: "Toutes les boîtes" }).click()102 await expect(page).toHaveURL(/\/u\/inbox$/)103 await expect(page.locator(".sidebar")).toBeHidden()104 const r = row(page, new RegExp(subject))105 await expect(r).toBeVisible()106 await expect(r.locator(".addr-chip")).toHaveAttribute("data-address", st.addrB)107 await expect(r.locator(".addr-chip")).toBeVisible()108 await noOverflow(page)109 await axe(page, "phone-unified")110 await r.click()111 await expect(page.locator("main#main").getByRole("heading", { name: subject })).toBeVisible()112 await expect(list(page)).toBeHidden()113 await noOverflow(page)114 await page.goBack()115 await expect(row(page, new RegExp(subject))).toBeVisible()116 // choix des boîtes : le dialogue tient dans l'écran117 await page.getByTestId("subset-button").click()118 await expect(page.getByRole("dialog", { name: "Boîtes à afficher" })).toBeVisible()119 await noOverflow(page)120 await page.keyboard.press("Escape")121 await expect(toastText(page, /./)).toHaveCount(0)122})123