SPB Git

Repository Public

unified.part.ts 11.4 KB 207 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : SP Mail8 * File             : tests/e2e/next-prod/unified.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 « unified » : « Toutes les boîtes » — épingle et pastille de libellé dans les lignes,44// sélection sur deux boîtes et actions groupées (archiver, libeller, mettre en veille), gestes au téléphone.45import { expect, test, type Page } from "@playwright/test"46import { toastText } from "../helpers"47import type { Harness, Part } from "./harness"4849const ulist = (p: Page) => p.getByRole("listbox", { name: /Toutes les boîtes/ })50const urow = (p: Page, subject: string) => ulist(p).getByRole("option", { name: new RegExp(subject) })51const folderRoles = async (h: Harness, address: string, id: string): Promise<(string | null)[]> => {52  const r = await h.jmap(h.page, address, [["Email/get", { ids: [id], properties: ["mailboxIds"] }, "g"], ["Mailbox/get", { properties: ["role"] }, "m"]])53  const boxes = r[1][1].list as { id: string; role: string | null }[]54  return Object.keys(r[0][1].list[0]?.mailboxIds ?? {}).map((b) => boxes.find((x) => x.id === b)?.role ?? null)55}56const 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)5758export const unifiedPart: Part = (h) => {59  let p1: string[] = []60  let p2: string[] = []61  let keyword = ""62  const subj = (x: string) => `Uni ${x} ${h().run}`6364  test("unified : épingle et libellé dans les lignes, sélection sur deux boîtes, archiver / libeller / mettre en veille en lot", async () => {65    const { page } = h()66    const labels = (await h().api<{ data: { name: string; keyword: string }[] }>(page, "GET", "/api/next/labels")).data67    keyword = labels.find((l) => l.name === "Unifié")?.keyword ?? (await h().api<{ keyword: string }>(page, "POST", "/api/next/labels", { name: "Unifié", color: "#7a3fa0" })).keyword68    p1 = await h().seed(page, h().P1, [69      { subject: subj("A"), from: ["Prod Deux", h().P2], preview: "Épinglé dans la première boîte.", keywords: ["$pinned", "$seen"], minutesAgo: 9 },70      { subject: subj("B"), from: ["Prod Deux", h().P2], preview: "À archiver, première boîte.", minutesAgo: 8 },71      { subject: subj("E"), from: ["Prod Deux", h().P2], preview: "À mettre en veille, première boîte.", minutesAgo: 7 },72      { subject: subj("G"), from: ["Prod Deux", h().P2], preview: "Pour le lot, première boîte.", minutesAgo: 3 },73    ])74    p2 = await h().seed(page, h().P2, [75      { subject: subj("C"), from: ["Prod Un", h().P1], preview: "Libellé dans la seconde boîte.", keywords: [keyword], minutesAgo: 6 },76      { subject: subj("D"), from: ["Prod Un", h().P1], preview: "À archiver, seconde boîte.", minutesAgo: 5 },77      { subject: subj("F"), from: ["Prod Un", h().P1], preview: "À mettre en veille, seconde boîte.", minutesAgo: 4 },78      { subject: subj("H"), from: ["Prod Un", h().P1], preview: "Pour le lot, seconde boîte.", minutesAgo: 2 },79    ])80    await page.goto("/u/inbox")81    const [a, b, c, d, e, f] = ["A", "B", "C", "D", "E", "F"].map((x) => urow(page, subj(x)))82    await expect(a).toBeVisible()83    await expect(f).toBeVisible()84    // ---- épingle (mot-clé $pinned, lu par JMAP : /api/v1 ne le rend pas) et pastille de libellé85    await expect(a.locator(".icon.pin")).toBeVisible()86    await expect(a).toHaveAccessibleName(/épinglé/)87    await expect(b.locator(".icon.pin")).toHaveCount(0)88    await expect(c.locator('.label-dot[title="Unifié"]')).toBeVisible()89    await expect(c).toHaveAccessibleName(/Unifié/)90    // ---- sélection sur deux boîtes → archiver : les deux messages quittent leur boîte de réception91    await b.click({ modifiers: ["ControlOrMeta"] })92    await d.click({ modifiers: ["ControlOrMeta"] })93    const bar = page.getByRole("toolbar", { name: "Actions sur la liste" })94    await expect(bar).toContainText("2 sélectionnées")95    await h().axeThemes(page, "unified-selection")96    await h().shotThemes(page, "unified-selection")97    await bar.getByRole("button", { name: "Archiver" }).click()98    await expect(b).toHaveCount(0)99    await expect(d).toHaveCount(0)100    await expect(toastText(page, /archivée/)).toBeVisible()101    await expect.poll(() => folderRoles(h(), h().P1, p1[1])).toEqual(["archive"])102    await expect.poll(() => folderRoles(h(), h().P2, p2[1])).toEqual(["archive"])103    // ---- libeller en lot, sur deux boîtes : état partiel (C le porte déjà), puis appliqué aux deux104    await a.click({ modifiers: ["ControlOrMeta"] })105    await c.click({ modifiers: ["ControlOrMeta"] })106    await page.keyboard.press("l")107    const picker = page.getByRole("dialog", { name: "Libellés" })108    await expect(picker).toContainText("2 conversations")109    const box = picker.getByRole("checkbox", { name: "Unifié" })110    expect(await box.evaluate((el) => (el as HTMLInputElement).indeterminate)).toBe(true)111    await box.click()112    await expect(box).toBeChecked()113    await picker.getByRole("button", { name: "Terminé" }).click()114    await expect(a.locator('.label-dot[title="Unifié"]')).toBeVisible()115    await expect(a.locator(".icon.pin")).toBeVisible()116    await expect.poll(() => keywordsOf(h(), h().P1, p1[0])).toContain(keyword)117    expect(await keywordsOf(h(), h().P2, p2[0])).toContain(keyword)118    await page.keyboard.press("Escape")119    await h().shot(page, "unified-rows-light")120    // ---- mettre en veille en lot (menu « Autres actions ») : les lignes partent, une mise en veille par boîte121    await e.click({ modifiers: ["ControlOrMeta"] })122    await f.click({ modifiers: ["ControlOrMeta"] })123    await bar.getByRole("button", { name: "Autres actions sur la sélection" }).click()124    await page.getByRole("menuitem", { name: "Mettre en veille" }).click()125    const when = page.getByRole("dialog", { name: "Mettre en veille" })126    await expect(when).toContainText("2 conversations")127    await when.getByRole("button", { name: /Demain matin/ }).click()128    await expect(e).toHaveCount(0)129    await expect(f).toHaveCount(0)130    await expect(toastText(page, /^En veille jusqu'à /)).toBeVisible()131    const active = (await h().api<{ data: { id: string; email_id: string }[] }>(page, "GET", "/api/next/snoozes?status=active")).data.filter((s) => [p1[2], p2[2]].includes(s.email_id))132    expect(active).toHaveLength(2)133    // « Annuler » de la notification les réveille : les deux lignes reviennent134    await toastText(page, /^En veille jusqu'à /).getByRole("button", { name: "Annuler" }).click()135    await expect(toastText(page, "Mise en veille annulée.")).toBeVisible()136    await expect(e).toBeVisible({ timeout: 20_000 })137    await expect(f).toBeVisible()138    // ---- lu / non lu en lot (appels bornés à quatre de front)139    let flying = 0140    let peak = 0141    await page.route("**/api/v1/messages/*", async (route) => {142      if (route.request().method() !== "PATCH") return route.continue()143      flying++144      peak = Math.max(peak, flying)145      await new Promise((r) => setTimeout(r, 150))146      await route.continue()147      flying--148    })149    await page.getByRole("checkbox", { name: "Tout sélectionner" }).check()150    const n = await ulist(page).getByRole("option", { selected: true }).count()151    expect(n).toBeGreaterThanOrEqual(6)152    await bar.getByRole("button", { name: "Marquer comme lu" }).click()153    await expect(ulist(page).locator(".mrow.unread")).toHaveCount(0)154    await expect.poll(() => flying).toBe(0)155    await page.unroute("**/api/v1/messages/*")156    expect(peak).toBe(4) // six lignes au moins : quatre appels de front, jamais plus157    await page.keyboard.press("Escape")158  })159160  test("unified : téléphone — gestes de glissement (lu / non lu, archiver), épingle et libellé visibles", async () => {161    const { page } = h()162    const { ctx, p } = await h().fromStorage({ width: 390, height: 844 }, true)163    await p.goto("/u/inbox")164    const a = urow(p, subj("A"))165    const e = urow(p, subj("E"))166    await expect(a).toBeVisible()167    await expect(a.locator(".icon.pin")).toBeVisible()168    await expect(a.locator('.label-dot[title="Unifié"]')).toBeVisible()169    const swipe = async (target: typeof a, fromRight: boolean, dx: number) => {170      // dans le parcours complet, d'autres boîtes ajoutent des lignes : la cible est amenée dans la fenêtre avant le geste171      await target.evaluate((el) => el.scrollIntoView({ block: "center" }))172      await p.waitForTimeout(250)173      const box = (await target.boundingBox())!174      const cdp = await ctx.newCDPSession(p)175      const x = fromRight ? box.x + box.width * 0.75 : box.x + 60176      const y = box.y + box.height / 2177      await cdp.send("Input.dispatchTouchEvent", { type: "touchStart", touchPoints: [{ x, y }] })178      for (let i = 1; i <= 8; i++) {179        await cdp.send("Input.dispatchTouchEvent", { type: "touchMove", touchPoints: [{ x: x + (dx * i) / 8, y }] })180        await p.waitForTimeout(16)181      }182      const stage = await p.locator(".mrow.swiping").getAttribute("data-swipe")183      if (stage === "trail-armed") await h().shot(p, "unified-swipe-phone")184      await cdp.send("Input.dispatchTouchEvent", { type: "touchEnd", touchPoints: [] })185      await cdp.detach()186      return stage187    }188    // ---- vers la droite : non lu (le message était lu), puis lu189    await expect(a).not.toHaveClass(/unread/)190    expect(await swipe(a, false, 130)).toBe("lead-armed")191    await expect(a).toHaveClass(/unread/)192    expect(await swipe(a, false, 130)).toBe("lead-armed")193    await expect(a).not.toHaveClass(/unread/)194    // ---- vers la gauche : archiver (annulable)195    expect(await swipe(e, true, -130)).toBe("trail-armed")196    await expect(e).toHaveCount(0)197    await expect.poll(() => folderRoles(h(), h().P1, p1[2])).toEqual(["archive"])198    await toastText(p, /archivée/).getByRole("button", { name: "Annuler" }).tap()199    await expect(e).toBeVisible()200    await h().axe(p, "unified-phone")201    await h().shot(p, "unified-phone")202    await ctx.close()203    await page.goto("/")204    await h().openBox(page, h().P1)205  })206}207
Files main
Menu

Theme