SPB Git

Repository Public

labels.part.ts 17.9 KB 290 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : SP Mail8 * File             : tests/e2e/next-prod/labels.part.ts9 * Module           : tests10 * Repository       : https://git.spboucher.ai/sp-mail11 * Project Website  : https://mail.spboucher.ai12 * Created          : 2026-11-2013 * Last Modified    : 2026-11-2014 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: support@spboucher.ai23 * Development      : dev@spboucher.ai24 * Support          : support@spboucher.ai25 * Security/Admin   : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License          : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243// SP Mail Next — essais de la zone « labels » : cycle de vie (créer, renommer, recolorer, ordonner, supprimer), application44// par glisser-déposer, au clavier (« l ») et par le menu contextuel, pastilles des lignes et du lecteur, recherche `label:`.45import { expect, test, type Page } from "@playwright/test"46import { row, toastText } from "../helpers"47import { THEMES, type Harness, type Part } from "./harness"4849/** Un état d'écran passé à axe dans les trois thèmes, puis capturé en clair et en minuit (le dialogue est rouvert à chaque thème). */50export async function themed(h: Harness, p: Page, name: string, open: () => Promise<void>, close: () => Promise<void>) {51  for (const [theme, label] of THEMES) {52    await h.setTheme(p, label, theme)53    await open()54    await h.axe(p, `${name}-${theme}`)55    if (theme !== "dark") await h.shot(p, `${name}-${theme}`)56    await close()57  }58  await h.setTheme(p, "Clair", "light")59}60export const toInbox = async (p: Page) => {61  await p.locator("#sidebar").getByRole("link", { name: /^Boîte de réception/ }).first().click()62  await expect(p.getByRole("heading", { level: 1, name: "Boîte de réception" })).toBeVisible()63}64const labelsNav = (p: Page) => p.locator('#sidebar [data-slot="labels"]')65const labelLink = (p: Page, name: string) => labelsNav(p).getByRole("link", { name, exact: true })66const labelNames = (p: Page) => labelsNav(p).locator(".nav-label").allTextContents()67const apiLabels = (h: Harness) => h.api<{ data: { id: string; name: string; color: string; keyword: string; position: number }[] }>(h.page, "GET", "/api/next/labels")68const keywordsOf = async (h: Harness, address: string, id: string) => Object.keys((await h.jmap(h.page, address, [["Email/get", { ids: [id], properties: ["keywords"] }, "g"]]))[0][1].list[0].keywords)69const entryMenu = async (p: Page, name: string, item: string) => {70  await labelLink(p, name).hover()71  await labelsNav(p).getByRole("button", { name: `Actions pour le dossier ${name}` }).click()72  await p.getByRole("menuitem", { name: item }).click()73}7475export const labelsPart: Part = (h) => {76  let ids: string[] = []77  const subj = (x: string) => `Libellé ${x} ${h().run}`7879  test("labels : créer, renommer, recolorer, ordonner (menu et dialogue de gestion, au clavier)", async () => {80    const { page } = h()81    ids = await h().seed(page, h().P1, [82      { subject: subj("A"), from: ["Prod Deux", h().P2], preview: "Premier message à libeller.", minutesAgo: 30 },83      { subject: subj("B"), from: ["Prod Deux", h().P2], preview: "Deuxième message à libeller.", minutesAgo: 20 },84      { subject: subj("C"), from: ["Prod Deux", h().P2], preview: "Troisième message à libeller.", minutesAgo: 10 },85    ])86    await h().openBox(page, h().P1)87    await expect(row(page, new RegExp(subj("A")))).toBeVisible()88    // ---- la section « Libellés » existe même vide, avec son bouton « + »89    const create = async (name: string, colour: string) => {90      await page.locator("#sidebar").getByRole("button", { name: "Nouveau libellé" }).click()91      const dlg = page.getByRole("dialog", { name: "Nouveau libellé" })92      await dlg.getByLabel("Nom").fill(name)93      await dlg.getByTitle(colour, { exact: true }).click()94      await dlg.getByRole("button", { name: "Créer" }).click()95      await expect(dlg).toHaveCount(0)96      await expect(labelLink(page, name)).toBeVisible()97    }98    await create("Clients", "Bleu")99    await create("À suivre", "Rouge")100    let api = (await apiLabels(h())).data101    expect(api.map((l) => [l.name, l.color, l.position])).toEqual([["Clients", "#1d5fa8", 0], ["À suivre", "#b3261e", 1]])102    expect(api.every((l) => /^lbl_[0-9a-f]{8}$/.test(l.keyword))).toBe(true)103    // ---- nom déjà pris : erreur dans le dialogue, rien n'est créé104    await page.locator("#sidebar").getByRole("button", { name: "Nouveau libellé" }).click()105    const dup = page.getByRole("dialog", { name: "Nouveau libellé" })106    await dup.getByLabel("Nom").fill("clients")107    await dup.getByRole("button", { name: "Créer" }).click()108    await expect(dup.getByRole("alert")).toHaveText("Un libellé porte déjà ce nom.")109    await page.keyboard.press("Escape")110    await expect(dup).toHaveCount(0)111    // ---- renommer et recolorer depuis le menu de l'entrée112    await entryMenu(page, "Clients", "Renommer ou changer la couleur")113    const edit = page.getByRole("dialog", { name: "Modifier le libellé" })114    await expect(edit.getByRole("radio", { name: "Bleu" })).toBeChecked()115    await edit.getByLabel("Nom").fill("Clients VIP")116    await edit.getByTitle("Vert", { exact: true }).click()117    await edit.getByRole("button", { name: "Enregistrer" }).click()118    await expect(edit).toHaveCount(0)119    await expect(labelLink(page, "Clients VIP")).toBeVisible()120    api = (await apiLabels(h())).data121    expect(api.find((l) => l.name === "Clients VIP")?.color).toBe("#2e6b2e")122    expect(await labelLink(page, "Clients VIP").locator(".label-dot").evaluate((el) => (el as HTMLElement).style.background)).toBe("var(--label-4)")123    // ---- ordre : « Monter » dans le menu de l'entrée124    await entryMenu(page, "À suivre", "Monter")125    await expect.poll(() => labelNames(page)).toEqual(["À suivre", "Clients VIP"])126    // l'ordre est appliqué à l'écran avant la réponse du serveur : on attend qu'il y soit aussi127    await expect.poll(async () => (await apiLabels(h())).data.map((l) => l.name)).toEqual(["À suivre", "Clients VIP"])128    // ---- dialogue de gestion : descendre au clavier (le focus reste sur le bouton), annonce pour les lecteurs d'écran129    await h().palette(page, ">gérer les lib", "Gérer les libellés")130    const manage = page.getByRole("dialog", { name: "Gérer les libellés" })131    const down = manage.getByRole("button", { name: "Descendre « À suivre »" })132    await down.focus()133    await page.keyboard.press("Enter")134    await expect(manage.getByRole("status")).toHaveText("« À suivre » déplacé en position 2.")135    await expect(down).toBeFocused()136    await expect(down).toHaveAttribute("aria-disabled", "true")137    await expect.poll(() => manage.locator("li[data-label]").evaluateAll((els) => els.map((e) => e.getAttribute("data-label")))).toEqual(["Clients VIP", "À suivre"])138    await h().axe(page, "labels-manage-light")139    await h().shot(page, "labels-manage-light")140    await manage.getByRole("button", { name: "Terminé" }).click()141    await expect.poll(() => labelNames(page)).toEqual(["Clients VIP", "À suivre"])142    expect((await apiLabels(h())).data.map((l) => [l.name, l.position])).toEqual([["Clients VIP", 0], ["À suivre", 1]])143  })144145  test("labels : appliquer par glisser-déposer, au clavier (l) et par le menu contextuel ; pastilles des lignes", async () => {146    const { page } = h()147    const api = (await apiLabels(h())).data148    const vip = api.find((l) => l.name === "Clients VIP")!149    const follow = api.find((l) => l.name === "À suivre")!150    const a = row(page, new RegExp(subj("A")))151    const b = row(page, new RegExp(subj("B")))152    const c = row(page, new RegExp(subj("C")))153    // ---- glisser une ligne sur le libellé de la barre latérale154    await a.dragTo(labelLink(page, "Clients VIP"))155    await expect(toastText(page, "Libellé « Clients VIP » appliqué.")).toBeVisible()156    await expect(a.locator('.label-dot[title="Clients VIP"]')).toBeVisible()157    await expect(a).toHaveAccessibleName(/Clients VIP/)158    await expect.poll(() => keywordsOf(h(), h().P1, ids[0])).toContain(vip.keyword)159    // ---- au clavier : sélection, « l », filtre, Entrée ; création à la volée dans le même sélecteur160    await b.click({ modifiers: ["ControlOrMeta"] })161    await page.keyboard.press("l")162    const picker = page.getByRole("dialog", { name: "Libellés" })163    await expect(picker).toContainText("1 conversation")164    await expect(picker.getByLabel("Filtrer ou créer un libellé")).toBeFocused()165    await page.keyboard.type("suivre")166    await expect(picker.getByRole("checkbox")).toHaveCount(1)167    await page.keyboard.press("Enter")168    await expect(picker.getByRole("checkbox", { name: "À suivre" })).toBeChecked()169    await picker.getByLabel("Filtrer ou créer un libellé").fill("Factures")170    await expect(picker.getByRole("button", { name: "Créer « Factures »" })).toBeVisible()171    await page.keyboard.press("Enter")172    await expect(picker.getByRole("checkbox", { name: "Factures" })).toBeChecked()173    await page.keyboard.press("Escape")174    await expect(picker).toHaveCount(0)175    await expect(b.locator('.label-dot[title="À suivre"]')).toBeVisible()176    await expect(b.locator('.label-dot[title="Factures"]')).toBeVisible()177    await expect(labelLink(page, "Factures")).toBeVisible()178    await expect.poll(() => keywordsOf(h(), h().P1, ids[1])).toContain(follow.keyword)179    await page.keyboard.press("Escape") // fin de la sélection180    // ---- menu contextuel d'une ligne (clic droit) : menu accessible, flèches, « Libellés… »181    await c.click({ button: "right" })182    const menu = page.getByRole("menu", { name: "Actions sur la conversation" })183    await expect(menu.getByRole("menuitem").first()).toBeFocused()184    await expect(menu.getByRole("menuitem", { name: "Archiver" })).toBeVisible()185    await h().axe(page, "labels-rowmenu-light")186    await h().shot(page, "labels-rowmenu-light")187    await page.keyboard.press("End")188    await page.keyboard.press("Escape")189    await expect(menu).toHaveCount(0)190    await c.click({ button: "right" })191    await menu.getByRole("menuitem", { name: "Libellés…" }).click()192    await picker.getByRole("checkbox", { name: "Clients VIP" }).check()193    await picker.getByRole("button", { name: "Terminé" }).click()194    await expect(c.locator('.label-dot[title="Clients VIP"]')).toBeVisible()195    // ---- sélection de deux lignes : état partiel d'un libellé, puis retrait pour toutes196    await b.click({ modifiers: ["ControlOrMeta"] })197    await c.click({ modifiers: ["ControlOrMeta"] })198    await page.getByRole("toolbar", { name: "Actions sur la liste" }).getByRole("button", { name: "Autres actions sur la sélection" }).click()199    await page.getByRole("menuitem", { name: "Libellés" }).click()200    await expect(picker).toContainText("2 conversations")201    const mixed = picker.getByRole("checkbox", { name: "Clients VIP" })202    expect(await mixed.evaluate((el) => (el as HTMLInputElement).indeterminate)).toBe(true)203    await mixed.click() // partiel → appliqué à toutes204    await expect(mixed).toBeChecked()205    await expect(b.locator('.label-dot[title="Clients VIP"]')).toBeVisible()206    await mixed.click() // → retiré de toutes207    await expect(b.locator('.label-dot[title="Clients VIP"]')).toHaveCount(0)208    await expect(c.locator('.label-dot[title="Clients VIP"]')).toHaveCount(0)209    // cocher puis décocher coup sur coup : les deux écritures arrivent au serveur dans l'ordre (le libellé n'y reste pas)210    await expect.poll(() => keywordsOf(h(), h().P1, ids[1])).not.toContain(vip.keyword)211    await expect.poll(() => keywordsOf(h(), h().P1, ids[2])).not.toContain(vip.keyword)212    // ---- barre latérale avec libellés + sélecteur : axe dans les trois thèmes, captures213    await page.keyboard.press("Escape")214    await expect(picker).toHaveCount(0)215    await themed(h(), page, "labels-picker", async () => {216      if (!(await page.getByRole("toolbar", { name: "Actions sur la liste" }).getByText(/sélectionnée/).count())) await b.click({ modifiers: ["ControlOrMeta"] })217      await page.keyboard.press("l")218      await expect(picker).toBeVisible()219    }, async () => {220      await page.keyboard.press("Escape")221      await expect(picker).toHaveCount(0)222    })223    await page.keyboard.press("Escape")224  })225226  test("labels : pastille du lecteur (cliquable, retirable), recherche label:, palette #, suppression", async () => {227    const { page } = h()228    const vip = (await apiLabels(h())).data.find((l) => l.name === "Clients VIP")!229    const a = row(page, new RegExp(subj("A")))230    await a.click()231    const chips = page.getByRole("list", { name: "Libellés de la conversation" })232    await expect(chips.getByRole("link", { name: /Clients VIP/ })).toBeVisible()233    // ---- le lecteur a son action « Libellés » : ajouter un second libellé au fil ouvert234    await page.getByRole("toolbar", { name: "Actions sur la conversation" }).getByRole("button", { name: "Libellés" }).click()235    const picker = page.getByRole("dialog", { name: "Libellés" })236    await expect(picker.getByRole("checkbox", { name: "Clients VIP" })).toBeChecked()237    await picker.getByRole("checkbox", { name: "À suivre" }).check()238    await picker.getByRole("button", { name: "Terminé" }).click()239    await expect(chips.getByRole("listitem")).toHaveCount(2)240    await h().axeThemes(page, "labels-reader")241    await h().shotThemes(page, "labels-reader")242    // ---- retirer une pastille : le mot-clé part du message, la pastille de la ligne aussi243    await chips.getByRole("button", { name: "Retirer le libellé « À suivre »" }).click()244    await expect(chips.getByRole("listitem")).toHaveCount(1)245    await expect(a.locator('.label-dot[title="À suivre"]')).toHaveCount(0)246    // ---- cliquer la pastille ouvre la recherche `label:` (tolérant : écran de recherche du serveur ou vue d'origine)247    await chips.getByRole("link", { name: /Clients VIP/ }).click()248    await expect(page).toHaveURL(/\/search\?q=label(%3A|:)(%22|")Clients(%20|\+)VIP(%22|")/)249    const found = page.getByRole("option", { name: new RegExp(subj("A")) })250    const serverSearch = await found.waitFor({ timeout: 8000 }).then(() => true, () => false)251    console.log(`[labels] recherche label: — ${serverSearch ? "résultats du serveur affichés" : "écran de résultats du serveur absent ou sans ligne « option » : adresse seule vérifiée"}`)252    test.info().annotations.push({ type: "label-search", description: serverSearch ? "résultats du serveur présents : la conversation libellée est listée" : "écran de recherche du serveur absent : seule l'adresse est vérifiée" })253    if (serverSearch) await expect(page.getByRole("option", { name: new RegExp(subj("B")) })).toHaveCount(0)254    // le serveur, lui, résout bien `label:` par le nom (quelle que soit l'interface de recherche affichée)255    const hits = await h().api<{ data: { email_id: string }[] }>(page, "GET", `/api/next/search?q=${encodeURIComponent('label:"Clients VIP"')}`)256    expect(hits.data.map((m) => m.email_id)).toContain(ids[0])257    expect(hits.data.map((m) => m.email_id)).not.toContain(ids[1])258    // l'entrée de la barre latérale est marquée courante259    await expect(labelLink(page, "Clients VIP")).toHaveAttribute("aria-current", "page")260    // ---- palette « # » : les libellés, filtrés sans accents261    await toInbox(page)262    await h().palette(page, "#a sui", /À suivre/)263    await expect(page).toHaveURL(/\/search\?q=label(%3A|:)/)264    await toInbox(page)265    // ---- suppression : l'entrée disparaît, la pastille aussi ; le mot-clé reste sur le message (inconnu, donc ignoré)266    await entryMenu(page, "Clients VIP", "Supprimer")267    await page.getByRole("alertdialog").or(page.getByRole("dialog", { name: /Supprimer le libellé/ })).getByRole("button", { name: "Supprimer" }).click()268    await expect(toastText(page, "Libellé « Clients VIP » supprimé.")).toBeVisible()269    await expect(labelLink(page, "Clients VIP")).toHaveCount(0)270    await expect(a.locator(".label-dot")).toHaveCount(0)271    expect(await keywordsOf(h(), h().P1, ids[0])).toContain(vip.keyword)272    expect((await apiLabels(h())).data.map((l) => l.name)).toEqual(["À suivre", "Factures"])273    // ---- téléphone : le sélecteur est une feuille du bas, pleine largeur274    const { ctx, p } = await h().fromStorage({ width: 390, height: 844 }, true)275    await p.goto("/")276    await h().openBox(p, h().P1).catch(() => {})277    await expect(row(p, new RegExp(subj("B")))).toBeVisible()278    await row(p, new RegExp(subj("B"))).locator(".mrow-check").tap()279    await p.getByRole("toolbar", { name: "Actions sur la liste" }).getByRole("button", { name: "Autres actions sur la sélection" }).tap()280    await p.getByRole("menuitem", { name: "Libellés" }).tap()281    const sheet = p.getByTestId("label-picker")282    await expect(sheet).toBeVisible()283    // la feuille glisse en place : la géométrie est lue une fois l'animation d'entrée terminée284    await expect.poll(async () => { const b = (await sheet.boundingBox())!; return [Math.round(b.width), Math.round(b.y + b.height)] }).toEqual([390, 844])285    await h().axe(p, "labels-picker-phone")286    await h().shot(p, "labels-picker-phone")287    await ctx.close()288  })289}290
Files main
Menu

Theme