SPB Git

Repository Public

snooze.part.ts 20.3 KB 328 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : SP Mail8 * File             : tests/e2e/next-prod/snooze.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 « snooze » : mise en veille optimiste (retrait immédiat, retour en cas d'échec), réveil par44// le travailleur du serveur (la ligne revient non lue sans rechargement), « En veille » (réveiller, replanifier), rappels de45// suivi (« Me le rappeler », « Suivis », glyphe $followup), hors ligne, téléphone.46import { expect, test, type Page } from "@playwright/test"47import { row, toastText } from "../helpers"48import type { Harness, Part } from "./harness"49import { themed, toInbox } from "./labels.part"5051const smart = (p: Page) => p.locator('#sidebar [data-slot="smart"]')52const snoozes = (h: Harness) => h.api<{ data: { id: string; email_id: string; mailbox_id: string; until: string; subject: string }[] }>(h.page, "GET", "/api/next/snoozes?status=active")53const reminders = (h: Harness, status: string) => h.api<{ data: { id: string; email_id: string; note: string | null; only_if_no_reply: boolean; due_at: string; status: string }[] }>(h.page, "GET", `/api/next/reminders?status=${status}`)54const soon = (ms: number) => new Date(Date.now() + ms).toISOString()5556export const snoozePart: Part = (h) => {57  let ids: string[] = []58  const subj = (x: string) => `Veille ${x} ${h().run}`5960  test("snooze : sélecteur, retrait optimiste, retour en cas d'échec, réveil par le serveur sans rechargement", async () => {61    const { page } = h()62    ids = await h().seed(page, h().P1, [63      { subject: subj("un"), from: ["Prod Deux", h().P2], preview: "À revoir plus tard.", keywords: ["$seen"], minutesAgo: 40 },64      { subject: subj("deux"), from: ["Prod Deux", h().P2], preview: "À replanifier.", keywords: ["$seen"], minutesAgo: 30 },65      { subject: subj("rappel"), from: ["Prod Deux", h().P2], preview: "Attend une réponse.", keywords: ["$seen"], minutesAgo: 20 },66      { subject: subj("liste"), from: ["Prod Deux", h().P2], preview: "Rappel depuis la liste.", keywords: ["$seen"], minutesAgo: 10 },67    ])68    await h().openBox(page, h().P1)69    const un = row(page, new RegExp(subj("un")))70    await expect(un).toBeVisible()71    await expect(un).not.toHaveClass(/unread/)72    const picker = page.getByRole("dialog", { name: "Mettre en veille" })73    const openPicker = async () => {74      if (!(await page.getByRole("toolbar", { name: "Actions sur la liste" }).getByText(/sélectionnée/).count())) await un.click({ modifiers: ["ControlOrMeta"] })75      await page.keyboard.press("b")76      await expect(picker).toBeVisible()77    }78    // ---- le sélecteur : échéances proposées, date et heure libres ; axe et captures dans les thèmes79    await themed(h(), page, "snooze-picker", openPicker, async () => {80      await page.keyboard.press("Escape")81      await expect(picker).toHaveCount(0)82    })83    await openPicker()84    await expect(picker).toContainText("1 conversation")85    await expect(picker.getByRole("button", { name: /Demain matin/ })).toBeVisible()86    await expect(picker.getByRole("button", { name: /La semaine prochaine|Le week-end prochain|Ce week-end/ }).first()).toBeVisible()87    // une date passée est refusée sur place88    await picker.getByLabel("Date", { exact: true }).fill("2020-01-01")89    await picker.getByRole("button", { name: "Mettre en veille" }).click()90    await expect(picker.getByRole("alert")).toHaveText("Choisissez un moment à venir.")91    // ---- échec du serveur : la ligne part tout de suite, puis revient, avec une erreur précise92    await page.route("**/api/next/snoozes", (route) => (route.request().method() === "POST" ? route.fulfill({ status: 503, contentType: "application/json", body: JSON.stringify({ error: "mail_server_error", message: "down" }) }) : route.continue()))93    await picker.getByRole("button", { name: /Demain matin/ }).click()94    await expect(picker).toHaveCount(0)95    await expect(toastText(page, "Service momentanément indisponible.")).toBeVisible()96    await expect(un).toBeVisible()97    await page.unroute("**/api/next/snoozes")98    expect((await snoozes(h())).data.filter((s) => s.email_id === ids[0])).toHaveLength(0)99    // ---- succès : la ligne quitte la liste AVANT la réponse du serveur (retenue ici 1,5 s)100    let released = false101    await page.route("**/api/next/snoozes", async (route) => {102      if (route.request().method() === "POST") {103        await new Promise((r) => setTimeout(r, 1500))104        released = true105      }106      await route.continue()107    })108    await openPicker()109    await picker.getByRole("button", { name: /Demain matin/ }).click()110    await expect(un).toHaveCount(0, { timeout: 1000 })111    expect(released).toBe(false)112    await expect(toastText(page, /^En veille jusqu'à /)).toBeVisible()113    await page.unroute("**/api/next/snoozes")114    await expect(un).toHaveCount(0)115    const mine = (await snoozes(h())).data.find((s) => s.email_id === ids[0])!116    expect(mine.subject).toBe(subj("un"))117    // ---- « En veille » dans la barre latérale, avec son compteur ; l'écran liste la conversation118    const entry = smart(page).getByRole("link", { name: /En veille/ })119    await expect(entry).toContainText("1")120    await page.keyboard.press("g")121    await page.keyboard.press("z")122    await expect(page).toHaveURL(/\/snoozed$/)123    await expect(entry).toHaveAttribute("aria-current", "page")124    const item = page.getByTestId("snoozed-item").filter({ hasText: subj("un") })125    await expect(item).toBeVisible()126    await expect(item).toContainText("Jusqu'à")127    // le lien mène à la conversation, dans le dossier de veille de sa boîte128    await item.getByRole("link").click()129    await expect(page.getByRole("heading", { level: 1, name: new RegExp(subj("un")) })).toBeVisible()130    await page.keyboard.press("u")131    // ---- le TRAVAILLEUR DU SERVEUR réveille le message : échéance ramenée à quelques secondes, puis attente sans rechargement132    await toInbox(page)133    await expect(un).toHaveCount(0)134    await h().api(page, "PATCH", `/api/next/snoozes/${mine.id}`, { until: soon(3000) })135    await expect(un).toBeVisible({ timeout: 40_000 })136    await expect(un).toHaveClass(/unread/)137    await expect(un.locator(".mrow-glyph-snoozed")).toHaveCount(0)138    await expect.poll(async () => (await snoozes(h())).data.some((s) => s.id === mine.id), { timeout: 15_000 }).toBe(false)139    await expect(entry).not.toContainText("1")140  })141142  test("snooze : « En veille » — replanifier, réveiller maintenant ; hors ligne expliqué", async () => {143    const { page, context } = h()144    const deux = row(page, new RegExp(subj("deux")))145    const picker = page.getByRole("dialog", { name: "Mettre en veille" })146    // ---- le menu contextuel de la ligne ouvre le même sélecteur147    await deux.click({ button: "right" })148    await page.getByRole("menu").getByRole("menuitem", { name: "Mettre en veille…" }).click()149    await expect(picker).toBeVisible()150    await page.keyboard.press("Escape")151    // ---- depuis le lecteur : le fil se ferme et sa ligne quitte la liste152    await deux.click()153    await expect(page.getByRole("heading", { level: 1, name: new RegExp(subj("deux")) })).toBeVisible()154    await page.getByRole("toolbar", { name: "Actions sur la conversation" }).getByRole("button", { name: "Mettre en veille" }).click()155    await picker.getByRole("button", { name: /Demain matin/ }).click()156    await expect(page.getByRole("heading", { level: 1, name: new RegExp(subj("deux")) })).toHaveCount(0)157    await expect(deux).toHaveCount(0)158    await expect(toastText(page, /^En veille jusqu'à /)).toBeVisible()159    await h().palette(page, ">aller à « en veille", /En veille/)160    const item = page.getByTestId("snoozed-item").filter({ hasText: subj("deux") })161    await expect(item).toBeVisible()162    await h().axeThemes(page, "snoozed")163    await h().shotThemes(page, "snoozed")164    // ---- replanifier : date et heure libres, dans le fuseau de l'appareil (America/Toronto)165    await item.getByRole("button", { name: /^Replanifier/ }).click()166    const again = page.getByRole("dialog", { name: "Replanifier le retour" })167    await expect(again).toContainText(subj("deux"))168    await again.getByLabel("Date", { exact: true }).fill("2031-07-15")169    await again.getByLabel("Heure", { exact: true }).fill("09:30")170    await again.getByRole("button", { name: "Replanifier" }).click()171    await expect(toastText(page, /^Retour replanifié/)).toBeVisible()172    await expect(item).toContainText("2031")173    const s = (await snoozes(h())).data.find((x) => x.email_id === ids[1])!174    expect(s.until).toBe("2031-07-15T13:30:00.000Z") // 9 h 30 HAE175    // ---- hors ligne : les actions sont désactivées et l'écran dit pourquoi176    await context.setOffline(true)177    await expect(page.getByTestId("snoozed-page").getByRole("status")).toHaveText(/Hors ligne/)178    await expect(item.getByRole("button", { name: /^Réveiller/ })).toBeDisabled()179    await context.setOffline(false)180    await expect(item.getByRole("button", { name: /^Réveiller/ })).toBeEnabled()181    // ---- réveiller maintenant : l'élément disparaît, la conversation retrouve la boîte de réception (toujours lue)182    await item.getByRole("button", { name: /^Réveiller/ }).click()183    await expect(toastText(page, "Conversation réveillée.")).toBeVisible()184    await expect(item).toHaveCount(0)185    await expect(page.getByTestId("snoozed-page")).toContainText("Aucune conversation en veille.")186    await h().shot(page, "snoozed-empty-light")187    await page.getByRole("link", { name: "Retour au courrier" }).click()188    await expect(deux).toBeVisible({ timeout: 20_000 })189    await expect(deux).not.toHaveClass(/unread/)190    // ---- hors ligne dans la liste : « b » explique au lieu d'ouvrir un sélecteur inutilisable191    await context.setOffline(true)192    await deux.click({ modifiers: ["ControlOrMeta"] })193    await page.keyboard.press("b")194    await expect(toastText(page, "Hors ligne : la mise en veille et les rappels sont planifiés par le serveur et demandent une connexion.")).toBeVisible()195    await expect(picker).toHaveCount(0)196    await context.setOffline(false)197    await page.keyboard.press("Escape")198  })199200  test("snooze : « Me le rappeler » (lecteur et liste), « Suivis » à venir puis à traiter, glyphe $followup, relancer, terminer, annuler", async () => {201    const { page } = h()202    await toInbox(page)203    const rappel = row(page, new RegExp(subj("rappel")))204    const liste = row(page, new RegExp(subj("liste")))205    // ---- depuis le lecteur : seulement sans réponse, note, échéance proposée206    await rappel.click()207    await page.getByRole("toolbar", { name: "Actions sur la conversation" }).getByRole("button", { name: "Me le rappeler" }).click()208    const dlg = page.getByRole("dialog", { name: "Me le rappeler" })209    await dlg.getByLabel("Seulement si personne n'a répondu").check()210    await dlg.getByLabel("Note (facultative)").fill("Relancer Prod Deux")211    await h().axe(page, "remind-picker-light")212    await h().shot(page, "remind-picker-light")213    await dlg.getByRole("button", { name: /Dans 3 jours/ }).click()214    await expect(toastText(page, /^Rappel créé pour le /)).toBeVisible()215    await page.keyboard.press("u")216    // ---- depuis la liste (menu contextuel), date libre217    await liste.click({ button: "right" })218    await page.getByRole("menu").getByRole("menuitem", { name: "Me le rappeler…" }).click()219    await dlg.getByLabel("Date", { exact: true }).fill("2031-03-10")220    await dlg.getByLabel("Heure", { exact: true }).fill("08:00")221    await dlg.getByRole("button", { name: "Créer le rappel" }).click()222    await expect.poll(async () => (await reminders(h(), "pending")).data.filter((r) => ids.includes(r.email_id)).length).toBe(2)223    let pending = (await reminders(h(), "pending")).data224    const fromReader = pending.find((r) => r.email_id === ids[2])!225    const fromList = pending.find((r) => r.email_id === ids[3])!226    expect([fromReader.note, fromReader.only_if_no_reply]).toEqual(["Relancer Prod Deux", true])227    expect([fromList.note, fromList.only_if_no_reply, fromList.due_at]).toEqual([null, false, "2031-03-10T12:00:00.000Z"]) // 8 h HAE (heure d'été dès le 9 mars 2031)228    // ---- « Suivis » : les deux rappels sont « à venir »229    await page.keyboard.press("g")230    await page.keyboard.press("u")231    await expect(page).toHaveURL(/\/followups$/)232    const fu = page.getByTestId("followups-page")233    const pendingSection = fu.locator('[data-section="nx-followups-pending"]')234    const dueSection = fu.locator('[data-section="nx-followups-due"]')235    await expect(pendingSection.getByTestId("followup-item")).toHaveCount(2)236    await expect(pendingSection.getByTestId("followup-item").filter({ hasText: subj("rappel") })).toContainText("Relancer Prod Deux")237    await expect(pendingSection.getByTestId("followup-item").filter({ hasText: subj("rappel") })).toContainText("si sans réponse")238    await expect(dueSection).toContainText("Rien à traiter pour l'instant.")239    // ---- échéance ramenée à quelques secondes : le serveur le rend « à traiter » (personne n'a répondu), sans rechargement240    await h().api(page, "PATCH", `/api/next/reminders/${fromReader.id}`, { due_at: soon(3000) })241    const dueItem = dueSection.getByTestId("followup-item").filter({ hasText: subj("rappel") })242    await expect(dueItem).toBeVisible({ timeout: 40_000 })243    await expect(pendingSection.getByTestId("followup-item")).toHaveCount(1)244    await expect(page.locator('#sidebar [data-slot="smart"]').getByRole("link", { name: /Suivis/ })).toContainText("1")245    await h().axeThemes(page, "followups")246    await h().shotThemes(page, "followups")247    // ---- le glyphe $followup marque la ligne dans la liste248    await dueItem.getByRole("link").click()249    await expect(page.getByRole("heading", { level: 1, name: new RegExp(subj("rappel")) })).toBeVisible()250    await page.keyboard.press("u")251    await expect(rappel.locator(".mrow-glyph-followup")).toBeVisible()252    await expect(rappel).toHaveAccessibleName(/suivi à faire/)253    await h().shot(page, "followup-glyph-light")254    // ---- relancer : il redevient « à venir », le glyphe part255    await page.keyboard.press("g")256    await page.keyboard.press("u")257    await dueItem.getByRole("button", { name: /^Relancer/ }).click()258    const rearm = page.getByRole("dialog", { name: "Relancer le rappel" })259    await rearm.getByRole("button", { name: /Dans une semaine/ }).click()260    await expect(toastText(page, /^Rappel relancé pour le /)).toBeVisible()261    await expect(pendingSection.getByTestId("followup-item")).toHaveCount(2)262    await expect(dueSection.getByTestId("followup-item")).toHaveCount(0)263    await expect.poll(async () => Object.keys((await h().jmap(page, h().P1, [["Email/get", { ids: [ids[2]], properties: ["keywords"] }, "g"]]))[0][1].list[0].keywords)).not.toContain("$followup")264    // ---- terminer l'un, annuler l'autre : l'écran est vide265    await pendingSection.getByTestId("followup-item").filter({ hasText: subj("rappel") }).getByRole("button", { name: /^Marquer/ }).click()266    await expect(toastText(page, "Suivi terminé.")).toBeVisible()267    await pendingSection.getByTestId("followup-item").filter({ hasText: subj("liste") }).getByRole("button", { name: /^Annuler le rappel/ }).click()268    await expect(toastText(page, "Rappel annulé.")).toBeVisible()269    await expect(fu).toContainText("Aucun suivi en cours.")270    pending = (await reminders(h(), "pending")).data271    expect(pending.filter((r) => ids.includes(r.email_id))).toHaveLength(0)272    expect((await reminders(h(), "done")).data.some((r) => r.id === fromReader.id)).toBe(true)273    expect((await reminders(h(), "cancelled")).data.some((r) => r.id === fromList.id)).toBe(true)274  })275276  test("snooze : téléphone — glissement long, sélecteur en feuille du bas, « En veille » et « Suivis »", async () => {277    const { page } = h()278    // un rappel et une mise en veille pour peupler les écrans279    const mb = await h().mailboxId(page, h().P1)280    await h().api(page, "POST", "/api/next/reminders", { mailbox_id: mb, email_id: ids[2], due_at: soon(86_400_000), note: "Sur téléphone" })281    const { ctx, p } = await h().fromStorage({ width: 390, height: 844 }, true)282    await p.goto("/")283    const liste = row(p, new RegExp(subj("liste")))284    await expect(liste).toBeVisible()285    // ---- glissement long vers la gauche : le sélecteur s'ouvre en feuille du bas, pleine largeur286    const box = (await liste.boundingBox())!287    const cdp = await ctx.newCDPSession(p)288    const y = box.y + box.height / 2289    await cdp.send("Input.dispatchTouchEvent", { type: "touchStart", touchPoints: [{ x: box.x + box.width - 20, y }] })290    for (let i = 1; i <= 8; i++) {291      await cdp.send("Input.dispatchTouchEvent", { type: "touchMove", touchPoints: [{ x: box.x + box.width - 20 - (260 * i) / 8, y }] })292      await p.waitForTimeout(16)293    }294    await cdp.send("Input.dispatchTouchEvent", { type: "touchEnd", touchPoints: [] })295    await cdp.detach()296    const sheet = p.getByTestId("snooze-picker")297    await expect(sheet).toBeVisible()298    // la feuille glisse en place : la géométrie est lue une fois l'animation d'entrée terminée299    await expect.poll(async () => { const b = (await sheet.boundingBox())!; return [Math.round(b.width), Math.round(b.y + b.height)] }).toEqual([390, 844])300    for (const b of await sheet.getByRole("button").all()) expect((await b.boundingBox())!.height).toBeGreaterThanOrEqual(40)301    await h().axe(p, "snooze-picker-phone")302    await h().shot(p, "snooze-picker-phone")303    await sheet.getByRole("button", { name: /Demain matin/ }).tap()304    await expect(liste).toHaveCount(0)305    // ---- « En veille » et « Suivis » au téléphone306    await p.goto("/snoozed")307    const item = p.getByTestId("snoozed-item").filter({ hasText: subj("liste") })308    await expect(item).toBeVisible()309    for (const b of await item.getByRole("button").all()) expect((await b.boundingBox())!.height).toBeGreaterThanOrEqual(44)310    expect(await p.evaluate(() => document.documentElement.scrollWidth)).toBeLessThanOrEqual(390)311    await h().axe(p, "snoozed-phone")312    await h().shot(p, "snoozed-phone")313    await p.goto("/followups")314    await expect(p.getByTestId("followup-item").filter({ hasText: "Sur téléphone" })).toBeVisible()315    expect(await p.evaluate(() => document.documentElement.scrollWidth)).toBeLessThanOrEqual(390)316    await h().axe(p, "followups-phone")317    await h().shot(p, "followups-phone")318    // rappel « Me le rappeler » : feuille du bas aussi319    await p.getByTestId("followup-item").filter({ hasText: "Sur téléphone" }).getByRole("button", { name: /^Replanifier/ }).tap()320    await expect(p.getByTestId("remind-picker")).toBeVisible()321    await h().shot(p, "remind-picker-phone")322    await ctx.close()323    // ménage : réveil et annulation, pour les zones suivantes324    for (const s of (await snoozes(h())).data.filter((x) => ids.includes(x.email_id))) await h().api(page, "DELETE", `/api/next/snoozes/${s.id}`)325    for (const r of (await reminders(h(), "pending")).data.filter((x) => ids.includes(x.email_id))) await h().api(page, "DELETE", `/api/next/reminders/${r.id}`)326  })327}328
Files main
Menu

Theme