SPB Git

Repository Public

contacts.part.ts 31.1 KB 496 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : SP Mail8 * File             : tests/e2e/next-prod/contacts.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 « contacts » : fiche créée et modifiée à l'écran, suggestion née d'un vrai envoi, relation, doublons et fusion, vCard, fiche d'expéditeur, palette « @ », téléphone.44import { expect, test, type Page } from "@playwright/test"45import fs from "node:fs"46import { row, toastText } from "../helpers"47import type { Part } from "./harness"4849type ApiContact = { id: string; kind: string; name: string; emails: { email: string; label: string | null }[]; phones: { number: string }[]; organization: string | null; title: string | null; favorite: boolean; vip: boolean; groups: string[]; stats: { sent: number; received: number } }5051export const contactsPart: Part = (h) => {52  const who = () => ({53    alice: `Alice Tremblay ${h().run}`,54    aliceMail: `alice.${h().run}@example.com`,55    // boîte du domaine de recette, détachée de SP Mail avant l'envoi : une adresse du propriétaire n'est jamais suggérée56    ext: `web-contacts-${h().run}@stg.spboucher.ai`,57    carol: `carol.${h().run}@example.com`,58  })59  const list = (p: Page) => p.getByRole("list", { name: "Liste des contacts" })60  const card = (p: Page) => p.getByRole("region", { name: "Fiche du contact" })61  const find = async (p: Page, q: string) => (await h().api<{ data: ApiContact[] }>(p, "GET", `/api/next/contacts?q=${encodeURIComponent(q)}&limit=50`)).data62  const openContacts = async (p: Page) => {63    await p.getByRole("link", { name: "Contacts", exact: true }).click()64    await expect(p.getByRole("heading", { level: 1, name: "Contacts" })).toBeVisible()65    // l'écran garde sa recherche d'une visite à l'autre : chaque essai repart d'une liste non filtrée66    await p.getByLabel("Rechercher un contact").fill("")67  }68  /** Dialogue dans les trois thèmes (axe) et captures clair + minuit ; `open` l'ouvre, `close` le referme. */69  const dialogThemes = async (p: Page, name: string, open: () => Promise<void>, close: () => Promise<void>) => {70    for (const [theme, label] of [["light", "Clair"], ["dark", "Sombre"], ["midnight", "Minuit"]] as const) {71      await h().setTheme(p, label, theme)72      await open()73      await h().axe(p, `${name}-${theme}`)74      if (theme !== "dark") await h().shot(p, `${name}-${theme}`)75      await close()76    }77    await h().setTheme(p, "Clair", "light")78  }7980  test("contacts : création à l'écran, modification, favori, VIP, groupes", async () => {81    const { page } = h()82    const { alice, aliceMail } = who()83    await openContacts(page)84    // (dans le parcours complet, d'autres zones ont déjà fait naître des suggestions : la liste n'est pas forcément vide)85    await page.getByLabel("Rechercher un contact").fill(`personne-${h().run}-introuvable`)86    await expect(page.getByText("Aucun contact ne correspond à ces critères.")).toBeVisible()87    await page.getByLabel("Rechercher un contact").fill("")8889    await page.getByRole("button", { name: "Nouveau contact" }).first().click()90    let dlg = page.getByRole("dialog", { name: "Nouveau contact" })91    // fiche vide puis adresse mal formée : refusées avec une explication, rien n'est envoyé92    await dlg.getByRole("button", { name: "Enregistrer" }).click()93    await expect(dlg.getByRole("alert")).toContainText("au moins un nom")94    await dlg.getByLabel("Nom", { exact: true }).fill(alice)95    await dlg.getByLabel("Adresse de courriel 1", { exact: true }).fill("pas une adresse")96    await dlg.getByRole("button", { name: "Enregistrer" }).click()97    await expect(dlg.getByRole("alert")).toContainText("mal formée")98    await dlg.getByLabel("Adresse de courriel 1", { exact: true }).fill(aliceMail.toUpperCase())99    await dlg.getByLabel("Étiquette de l'adresse 1").fill("travail")100    await dlg.getByLabel("Organisation", { exact: true }).fill("Atelier <b>Tremblay</b>")101    await dlg.getByRole("button", { name: "Ajouter un téléphone" }).click()102    await dlg.getByLabel("Téléphone 1", { exact: true }).fill("+1 514 555-0101")103    await dlg.getByLabel("Notes", { exact: true }).fill("Rencontrée au salon.\n<img src=x onerror=alert(1)>")104    await dlg.getByRole("button", { name: "Enregistrer" }).click()105    await expect(dlg).toHaveCount(0)106    await expect(page).toHaveURL(/\/contacts\/[0-9a-f-]{36}$/)107    await expect(card(page).getByRole("heading", { level: 2, name: alice })).toBeVisible()108    // les champs sont du texte : aucune balise n'est interprétée109    await expect(card(page)).toContainText("Atelier <b>Tremblay</b>")110    await expect(card(page)).toContainText("<img src=x onerror=alert(1)>")111    expect(await card(page).locator("img, b").count()).toBe(0)112    await expect(card(page)).toContainText(aliceMail)113    await expect(card(page).getByText("travail")).toBeVisible()114    await expect(list(page).getByRole("link", { name: new RegExp(alice) })).toHaveAttribute("aria-current", "page")115    let [c] = await find(page, aliceMail)116    expect(c).toMatchObject({ kind: "saved", name: alice, organization: "Atelier <b>Tremblay</b>", favorite: false, vip: false })117    expect(c.emails).toEqual([{ email: aliceMail, label: "travail" }])118119    // modification120    await card(page).getByRole("button", { name: "Modifier" }).click()121    dlg = page.getByRole("dialog", { name: "Modifier le contact" })122    await dlg.getByLabel("Fonction", { exact: true }).fill("Directrice")123    await dlg.getByRole("button", { name: "Ajouter une adresse" }).click()124    await dlg.getByLabel("Adresse de courriel 2", { exact: true }).fill(`alice.perso.${h().run}@example.com`)125    await dlg.getByRole("button", { name: "Enregistrer" }).click()126    await expect(dlg).toHaveCount(0)127    await expect(card(page)).toContainText("Directrice · Atelier <b>Tremblay</b>")128    ;[c] = await find(page, aliceMail)129    expect(c.title).toBe("Directrice")130    expect(c.emails.map((e) => e.email)).toEqual([aliceMail, `alice.perso.${h().run}@example.com`])131132    // favori et VIP133    await card(page).getByRole("button", { name: "Ajouter aux favoris" }).click()134    await expect(card(page).getByRole("button", { name: "Retirer des favoris" })).toHaveAttribute("aria-pressed", "true")135    await card(page).getByRole("button", { name: "Marquer comme VIP" }).click()136    await expect(card(page).getByRole("button", { name: "Retirer la marque VIP" })).toHaveAttribute("aria-pressed", "true")137    ;[c] = await find(page, aliceMail)138    expect(c).toMatchObject({ favorite: true, vip: true })139140    // groupes : création, renommage et couleur, appartenance, filtre141    await page.getByRole("button", { name: "Autres actions des contacts" }).click()142    await page.getByRole("menuitem", { name: "Gérer les groupes" }).click()143    dlg = page.getByRole("dialog", { name: "Gérer les groupes" })144    await dlg.getByLabel("Nouveau groupe").fill(`Clients ${h().run}`)145    await dlg.getByRole("button", { name: "Créer le groupe" }).click()146    await expect(dlg.getByRole("list", { name: "Groupes" })).toContainText(`Clients ${h().run}`)147    await dlg.getByLabel("Nouveau groupe").fill(`Éphémère ${h().run}`)148    await dlg.getByRole("button", { name: "Créer le groupe" }).click()149    await expect(dlg.getByRole("list", { name: "Groupes" })).toContainText(`Éphémère ${h().run}`)150    await dlg.getByRole("button", { name: `Renommer ou recolorer le groupe Clients ${h().run}` }).click()151    await dlg.getByLabel("Nom du groupe").fill(`Clientèle ${h().run}`)152    await dlg.getByRole("radiogroup", { name: "Couleur du groupe" }).first().getByRole("radio", { name: "Couleur 3" }).click()153    await dlg.getByRole("button", { name: "Enregistrer" }).click()154    await expect(dlg.getByRole("list", { name: "Groupes" })).toContainText(`Clientèle ${h().run}`)155    // suppression (confirmée) du second groupe156    await dlg.getByRole("button", { name: `Supprimer le groupe Éphémère ${h().run}` }).click()157    await page.getByRole("alertdialog", { name: "Supprimer ce groupe ?" }).getByRole("button", { name: "Supprimer" }).click()158    await expect(dlg.getByRole("list", { name: "Groupes" })).not.toContainText("Éphémère")159    await dlg.getByRole("button", { name: "Fermer" }).last().click()160    const groups = (await h().api<{ data: { id: string; name: string; color: string }[] }>(page, "GET", "/api/next/contact-groups")).data161    // (le parcours « rédaction » laisse son propre groupe « Équipe <run> » au même propriétaire : il n'est pas de cet essai)162    expect(groups.filter((g) => g.name.includes(h().run) && !g.name.startsWith("Équipe "))).toHaveLength(1)163    const group = groups.find((g) => g.name === `Clientèle ${h().run}`)!164    expect(group.color).toBe("#7a5c00")165    await card(page).getByRole("button", { name: `Clientèle ${h().run}` }).click()166    await expect(card(page).getByRole("button", { name: `Clientèle ${h().run}` })).toHaveAttribute("aria-pressed", "true")167    ;[c] = await find(page, aliceMail)168    expect(c.groups).toEqual([group.id])169170    // une seconde fiche, hors groupe, pour vérifier les filtres de la liste171    await h().api(page, "POST", "/api/next/contacts", { name: `Zacharie Hors-Groupe ${h().run}`, emails: [{ email: `zacharie.${h().run}@example.com` }] })172    const aliceRow = list(page).getByRole("link", { name: new RegExp(alice) })173    const zachRow = list(page).getByRole("link", { name: /Zacharie Hors-Groupe/ })174    await page.getByLabel("Rechercher un contact").fill(`zacharie.${h().run}`)175    await expect(list(page).getByRole("link")).toHaveCount(1)176    await expect(zachRow).toBeVisible()177    await page.getByLabel("Rechercher un contact").fill("")178    await expect(aliceRow).toBeVisible()179    await expect(zachRow).toBeVisible()180    const chip = page.getByRole("region", { name: "Liste des contacts" }).getByRole("button", { name: new RegExp(`Clientèle ${h().run}`) })181    await chip.click()182    await expect(list(page).getByRole("link")).toHaveCount(1)183    await expect(aliceRow).toBeVisible()184    await chip.click()185    await expect(zachRow).toBeVisible()186    await page.getByRole("button", { name: "Favoris", exact: true }).click()187    await expect(aliceRow).toBeVisible()188    await expect(zachRow).toHaveCount(0)189    await page.getByRole("button", { name: "Favoris", exact: true }).click()190    await expect(zachRow).toBeVisible()191    await page.getByRole("group", { name: "Type de fiche" }).getByRole("button", { name: "Suggérés" }).click()192    await expect(aliceRow).toHaveCount(0)193    await page.getByRole("group", { name: "Type de fiche" }).getByRole("button", { name: "Tous" }).click()194    await expect(aliceRow).toBeVisible()195196    await h().axeThemes(page, "contacts")197    await h().shotThemes(page, "contacts")198    await dialogThemes(199      page,200      "contacts-edit",201      async () => {202        await card(page).getByRole("button", { name: "Modifier" }).click()203        await expect(page.getByRole("dialog", { name: "Modifier le contact" })).toBeVisible()204      },205      async () => {206        await page.getByRole("dialog", { name: "Modifier le contact" }).getByRole("button", { name: "Annuler" }).click()207        await expect(page.getByRole("dialog", { name: "Modifier le contact" })).toHaveCount(0)208      },209    )210  })211212  test("contacts : un vrai envoi fait naître une suggestion ; « Ajouter » ; la relation montre le message et l'ouvre", async () => {213    const { page, P1 } = h()214    const { ext } = who()215    const subject = `Relation réelle ${h().run}`216    // destinataire réel du domaine de recette, hors des adresses du propriétaire217    // inscrite au registre avant d'exister : même détachée de SP Mail, elle sera reprise puis purgée (ici, sinon au démontage global)218    h().track(ext)219    h().onTeardown(async () => {220      const adopted = await h().api<{ id: string }>(page, "POST", "/api/admin/mailboxes/adopt", { address: ext }).catch(() => null)221      if (adopted) await h().api(page, "DELETE", `/api/admin/mailboxes/${adopted.id}?purge=delete-all-mail`)222    })223    const made = await h().api<{ id: string }>(page, "POST", "/api/admin/mailboxes", { address: ext, display_name: "Correspondante Externe" })224    await h().api(page, "DELETE", `/api/admin/mailboxes/${made.id}`)225    await page.goto("/")226    await h().openBox(page, P1)227    // la rédaction choisit son expéditeur à l'ouverture : on attend que la boîte soit prête (dossiers et identités arrivent ensemble),228    // sinon le brouillon naît sans identité et « Envoyer » reste sans effet229    await expect(page.locator("#sidebar").getByRole("link", { name: /Brouillons/ })).toBeVisible()230    await expect(page.getByRole("listbox", { name: /^Conversations/ }).getByRole("option").first()).toBeVisible()231    await page.getByRole("button", { name: "Nouveau message" }).first().click()232    const composer = page.locator("section.composer")233    await expect(composer).toBeVisible()234    const from = composer.getByLabel("De :")235    await from.selectOption({ label: (await from.locator("option").allTextContents()).find((o) => o.includes(P1))! })236    await composer.getByRole("combobox", { name: "À :" }).fill(ext)237    await composer.getByRole("combobox", { name: "À :" }).press("Enter")238    await composer.getByLabel("Objet :").fill(subject)239    await composer.getByRole("textbox", { name: "Corps du message" }).click()240    await page.keyboard.type("Bonjour, voici le devis demandé.")241    await composer.getByRole("button", { name: "Envoyer" }).click()242    // le serveur de recette peut refuser un envoi de façon passagère : l'état de la rédaction est consigné, un second essai est fait243    const closed = await composer.waitFor({ state: "detached", timeout: 30_000 }).then(() => true, () => false)244    if (!closed) {245      test.info().annotations.push({ type: "send-retry", description: (await composer.innerText()).slice(0, 600) })246      await composer.getByRole("button", { name: "Envoyer" }).click()247      await expect(composer).toHaveCount(0, { timeout: 60_000 })248    }249    // remise réelle constatée, puis le suivi est masqué250    const delivery = page.locator('[data-testid="delivery"]').last()251    await expect(delivery.locator(`[data-recipient="${ext}"]`)).toHaveAttribute("data-delivered", "yes", { timeout: 60_000 })252    await delivery.getByRole("button", { name: "Masquer" }).click()253    // le veilleur moissonne la copie « Envoyés » : la correspondante devient une suggestion254    await expect.poll(async () => (await find(page, ext)).map((c) => `${c.kind}:${c.stats.sent}`), { timeout: 90_000, intervals: [2000] }).toEqual(["suggested:1"])255256    await openContacts(page)257    await page.getByRole("group", { name: "Type de fiche" }).getByRole("button", { name: "Suggérés" }).click()258    await page.getByLabel("Rechercher un contact").fill(ext.split("@")[0])259    const row = list(page).getByRole("listitem").filter({ hasText: ext })260    await expect(row).toBeVisible()261    await expect(list(page).getByRole("listitem")).toHaveCount(1)262    await row.getByRole("button", { name: /^Ajouter .* aux contacts$/ }).click()263    // enregistrée : elle quitte la liste des suggestions264    await expect(list(page).getByRole("listitem")).toHaveCount(0)265    await expect(page.getByText("Aucun contact ne correspond")).toBeVisible()266    expect((await find(page, ext))[0].kind).toBe("saved")267    await page.getByRole("group", { name: "Type de fiche" }).getByRole("button", { name: "Tous" }).click()268    await list(page).getByRole("link", { name: new RegExp(ext.split("@")[0]) }).click()269    await page.getByLabel("Rechercher un contact").fill("")270    await expect(card(page).getByRole("heading", { level: 2 })).toBeVisible()271    // relation : le message réellement envoyé, d'où l'on ouvre la conversation272    const item = card(page).getByRole("link", { name: new RegExp(subject) })273    await expect(item).toBeVisible({ timeout: 30_000 })274    await expect(item).toContainText("Envoyé :")275    await expect(card(page).locator(".nx-ct-stats")).toContainText("Envoyés")276    await item.click()277    await expect(page).toHaveURL(/\/m\/0\/sent\/t\//)278    await expect(page.locator(".reader-subject")).toHaveText(new RegExp(subject))279  })280281  test("contacts : doublons détectés, fusion claire, résultat vérifié par l'API", async () => {282    const { page } = h()283    const name = `Bruno Doublon ${h().run}`284    const a = await h().api<ApiContact>(page, "POST", "/api/next/contacts", { name, emails: [{ email: `bruno.${h().run}@example.com` }], phones: [{ number: "514 555-0199" }], organization: "Doublons inc." })285    const b = await h().api<ApiContact>(page, "POST", "/api/next/contacts", { name, emails: [{ email: `b.doublon.${h().run}@example.org`, label: "perso" }], favorite: true })286    await openContacts(page)287    await expect(list(page).getByRole("link", { name: new RegExp(name) })).toHaveCount(2)288    const open = async () => {289      await page.getByRole("button", { name: "Autres actions des contacts" }).click()290      await page.getByRole("menuitem", { name: "Doublons" }).click()291      await expect(page.getByRole("dialog", { name: "Doublons" }).getByRole("listitem").filter({ hasText: `bruno.${h().run}@example.com` }).getByRole("button", { name: "Fusionner ces 2 fiches" })).toBeVisible()292    }293    const close = async () => {294      await page.getByRole("dialog", { name: "Doublons" }).getByRole("button", { name: "Fermer" }).last().click()295      await expect(page.getByRole("dialog", { name: "Doublons" })).toHaveCount(0)296    }297    await dialogThemes(page, "contacts-merge", open, close)298    await open()299    const whole = page.getByRole("dialog", { name: "Doublons" })300    const dlg = whole.getByRole("listitem").filter({ hasText: `bruno.${h().run}@example.com` })301    await expect(dlg).toContainText("Même nom :")302    // la fiche la plus riche est proposée ; le résultat annoncé réunit les deux adresses303    const keep = dlg.getByRole("group", { name: "Fiche à conserver" })304    await expect(keep.getByRole("radio").first()).toBeChecked()305    const result = dlg.getByRole("group", { name: "Après la fusion" })306    await expect(result).toContainText(`bruno.${h().run}@example.com`)307    await expect(result).toContainText(`b.doublon.${h().run}@example.org`)308    await expect(result).toContainText("1 autre fiche sera supprimée.")309    // on choisit de garder la seconde fiche : l'aperçu suit310    await keep.getByRole("radio").nth(1).check()311    await expect(result.locator(".small").first()).toHaveText(`b.doublon.${h().run}@example.org`)312    await dlg.getByRole("button", { name: "Fusionner ces 2 fiches" }).click()313    // le groupe résolu quitte la liste (seul doublon du carnet : l'état « aucun doublon » s'affiche)314    await expect(dlg).toHaveCount(0)315    if (!(await whole.getByRole("listitem").count())) await expect(whole.getByText("Aucun doublon détecté.")).toBeVisible()316    await close()317    await expect(list(page).getByRole("link", { name: new RegExp(name) })).toHaveCount(1)318    const left = await find(page, name)319    expect(left).toHaveLength(1)320    expect(left[0].id).toBe(b.id)321    expect(left[0].emails.map((e) => e.email)).toEqual([`b.doublon.${h().run}@example.org`, `bruno.${h().run}@example.com`])322    expect(left[0]).toMatchObject({ favorite: true, organization: "Doublons inc." })323    expect(left[0].phones.map((p) => p.number)).toEqual(["514 555-0199"])324    await expect(h().api(page, "GET", `/api/next/contacts/${a.id}`)).rejects.toThrow(/404/)325  })326327  test("contacts : vCard — export vérifié octet par octet, import par le sélecteur de fichier et par dépôt", async () => {328    const { page } = h()329    const { alice, aliceMail } = who()330    await openContacts(page)331    await page.getByRole("button", { name: "Autres actions des contacts" }).click()332    const [download] = await Promise.all([page.waitForEvent("download"), page.getByRole("menuitem", { name: "Exporter en vCard" }).click()])333    expect(download.suggestedFilename()).toBe("contacts.vcf")334    const vcf = fs.readFileSync(await download.path(), "utf8")335    expect(vcf).toContain("BEGIN:VCARD")336    expect(vcf).toContain(`FN:${alice}`)337    expect(vcf).toMatch(new RegExp(`EMAIL[^\\r\\n]*:${aliceMail.replace(/\./g, "\\.")}`))338    expect(vcf).toContain("Atelier <b>Tremblay</b>")339    expect(vcf.match(/BEGIN:VCARD/g)!.length).toBeGreaterThanOrEqual(3)340341    // import : une fiche nouvelle, une qui complète Alice (même adresse), une inutilisable342    const fixture = [343      "BEGIN:VCARD", "VERSION:3.0", `FN:Denis Importé ${h().run}`, `N:Importé ${h().run};Denis;;;`, `EMAIL;TYPE=WORK:denis.${h().run}@example.com`, "TEL;TYPE=CELL:+1 418 555-0142", "ORG:Imports & Cie", "END:VCARD",344      "BEGIN:VCARD", "VERSION:3.0", "FN:Alice T.", `EMAIL:${aliceMail}`, "TEL:+1 514 555-0177", "END:VCARD",345      "BEGIN:VCARD", "VERSION:3.0", "END:VCARD", "",346    ].join("\r\n")347    await page.getByLabel("Fichier vCard à importer").setInputFiles({ name: "carnet.vcf", mimeType: "text/vcard", buffer: Buffer.from(fixture, "utf8") })348    let dlg = page.getByRole("dialog", { name: "Import terminé" })349    await expect(dlg.getByTestId("import-result")).toHaveText(/Créés\s*1\s*Complétés\s*1\s*Ignorés\s*1/)350    await dlg.getByRole("button", { name: "Fermer" }).last().click()351    await expect(list(page).getByRole("link", { name: new RegExp(`Denis Importé ${h().run}`) })).toBeVisible()352    const [denis] = await find(page, `denis.${h().run}@example.com`)353    expect(denis).toMatchObject({ kind: "saved", name: `Denis Importé ${h().run}`, organization: "Imports & Cie" })354    const [al] = await find(page, aliceMail)355    expect(al.name).toBe(alice) // le nom existant est gardé, le téléphone s'ajoute356    expect(al.phones.map((p) => p.number)).toEqual(["+1 514 555-0101", "+1 514 555-0177"])357358    // un fichier qui n'est pas une vCard est refusé avant tout envoi359    await page.getByLabel("Fichier vCard à importer").setInputFiles({ name: "photo.png", mimeType: "image/png", buffer: Buffer.from("x") })360    await expect(toastText(page, "Choisissez un fichier .vcf")).toBeVisible()361362    // dépôt d'un fichier sur l'écran363    const dropped = ["BEGIN:VCARD", "VERSION:4.0", `FN:Élodie Déposée ${h().run}`, `EMAIL:elodie.${h().run}@example.com`, "END:VCARD", ""].join("\r\n")364    const data = await page.evaluateHandle((text) => {365      const dt = new DataTransfer()366      dt.items.add(new File([text], "depot.vcf", { type: "text/vcard" }))367      return dt368    }, dropped)369    await page.locator(".nx-ct").dispatchEvent("dragenter", { dataTransfer: data })370    await expect(page.getByText("Déposez un fichier .vcf pour l'importer")).toBeVisible()371    await page.locator(".nx-ct").dispatchEvent("drop", { dataTransfer: data })372    dlg = page.getByRole("dialog", { name: "Import terminé" })373    await expect(dlg.getByTestId("import-result")).toHaveText(/Créés\s*1\s*Complétés\s*0\s*Ignorés\s*0/)374    await dlg.getByRole("button", { name: "Fermer" }).last().click()375    await expect(page.getByText("Déposez un fichier .vcf pour l'importer")).toHaveCount(0)376    expect((await find(page, `elodie.${h().run}@example.com`))[0].name).toBe(`Élodie Déposée ${h().run}`)377  })378379  test("contacts : fiche de l'expéditeur dans le lecteur, palette « @ », raccourci « g c », écrire", async () => {380    const { page, P1 } = h()381    const { carol, alice, aliceMail } = who()382    const subject = `Devis de Carole ${h().run}`383    await h().seed(page, P1, [{ subject, from: ["Carole Expéditrice", carol], preview: "Voici le devis.", minutesAgo: 3 }])384    await page.goto("/")385    await h().openBox(page, P1)386    await row(page, new RegExp(subject)).click()387    await expect(page.locator(".reader-subject")).toHaveText(new RegExp(subject))388    const btn = page.getByRole("button", { name: "Fiche de Carole Expéditrice" })389    await btn.click()390    let pop = page.getByRole("dialog", { name: "Carole Expéditrice" })391    await expect(pop).toContainText(carol)392    // recherche de ses messages : lien vers la recherche dans toutes les boîtes393    await expect(pop.getByRole("link", { name: "Rechercher ses messages" })).toHaveAttribute("href", `/u/search?q=${encodeURIComponent(`from:${carol}`)}`)394    await pop.getByRole("button", { name: "Ajouter aux contacts" }).click()395    await expect(pop.getByRole("link", { name: "Ouvrir la fiche" })).toBeVisible()396    await expect.poll(async () => (await find(page, carol)).map((c) => c.kind)).toEqual(["saved"])397    await pop.getByRole("button", { name: "Favori" }).click()398    await expect(pop.getByRole("button", { name: "Favori" })).toHaveAttribute("aria-pressed", "true")399    await pop.getByRole("button", { name: "Expéditeur important (VIP)" }).click()400    await expect(pop.getByRole("button", { name: "Expéditeur important (VIP)" })).toHaveAttribute("aria-pressed", "true")401    expect((await find(page, carol))[0]).toMatchObject({ favorite: true, vip: true, name: "Carole Expéditrice" })402    await h().axe(page, "contacts-sender-popover")403    await h().shot(page, "contacts-sender-popover-light")404    // Échap ferme et rend le focus au bouton405    await page.keyboard.press("Escape")406    await expect(pop).toHaveCount(0)407    await expect(btn).toBeFocused()408    await btn.click()409    pop = page.getByRole("dialog", { name: "Carole Expéditrice" })410    await pop.getByRole("link", { name: "Ouvrir la fiche" }).click()411    await expect(page).toHaveURL(/\/contacts\/[0-9a-f-]{36}$/)412    await expect(card(page).getByRole("heading", { level: 2, name: "Carole Expéditrice" })).toBeVisible()413    // la relation montre le message reçu414    await expect(card(page).getByRole("link", { name: new RegExp(subject) })).toContainText("Reçu :")415416    // palette « @ » : le correspondant, puis sa fiche417    await page.keyboard.press("Control+k")418    const pal = page.getByRole("dialog", { name: "Palette de commandes" })419    await pal.getByRole("combobox").fill("@alice.")420    await expect(pal.getByRole("option").first()).toContainText(alice)421    await expect(pal.getByRole("option").first()).toContainText(aliceMail)422    await page.keyboard.press("Enter")423    await expect(pal).toHaveCount(0)424    await expect(card(page).getByRole("heading", { level: 2, name: alice })).toBeVisible()425426    // « Écrire » : la rédaction s'ouvre avec le destinataire427    await card(page).getByRole("button", { name: "Écrire", exact: true }).click()428    const composer = page.locator("section.composer")429    await expect(composer.locator(".rcpt-chips").first()).toContainText(alice)430    await expect(composer.locator(".rcpt-chips").first().getByRole("button", { name: `Retirer ${alice}` })).toBeVisible()431    await composer.getByRole("button", { name: "Supprimer le brouillon" }).click()432    await page.getByRole("alertdialog", { name: "Supprimer ce brouillon ?" }).getByRole("button", { name: "Supprimer le brouillon" }).click()433    await expect(composer).toHaveCount(0)434435    // raccourci « g c » depuis le courrier, palette de commandes, aide des raccourcis436    await page.goto("/")437    await h().openBox(page, P1)438    await page.locator("body").press("g")439    await page.locator("body").press("c")440    await expect(page.getByRole("heading", { level: 1, name: "Contacts" })).toBeVisible()441    await page.goto("/")442    await h().openBox(page, P1)443    await h().palette(page, ">aller aux contacts", /^Aller aux contacts/)444    await expect(page.getByRole("heading", { level: 1, name: "Contacts" })).toBeVisible()445    await page.goto("/")446    await h().openBox(page, P1)447    await page.locator("body").press("?")448    await expect(page.getByRole("dialog", { name: /raccourcis/i })).toContainText("Aller aux contacts")449    await page.keyboard.press("Escape")450451    // suppression confirmée d'une fiche452    await openContacts(page)453    await list(page).getByRole("link", { name: /Zacharie Hors-Groupe/ }).click()454    await card(page).getByRole("button", { name: "Autres actions de la fiche" }).click()455    await page.getByRole("menuitem", { name: "Supprimer" }).click()456    await page.getByRole("alertdialog", { name: "Supprimer ce contact ?" }).getByRole("button", { name: "Supprimer" }).click()457    await expect(page).toHaveURL(/\/contacts$/)458    await expect(list(page).getByRole("link", { name: /Zacharie Hors-Groupe/ })).toHaveCount(0)459    expect(await find(page, `zacharie.${h().run}@example.com`)).toEqual([])460  })461462  test("contacts : téléphone — une colonne, fiche avec retour, cibles de 44 px", async () => {463    const { alice } = who()464    const { ctx, p } = await h().fromStorage({ width: 390, height: 844 }, true)465    try {466      await p.goto("/contacts")467      await expect(p.getByRole("heading", { level: 1, name: "Contacts" })).toBeVisible()468      await expect(list(p).getByRole("link", { name: new RegExp(alice) })).toBeVisible()469      await expect(p.getByRole("navigation", { name: "Navigation principale" })).toBeVisible()470      await expect(card(p)).toBeHidden()471      expect(await p.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth)).toBe(true)472      await h().axe(p, "contacts-phone-list")473      await h().shot(p, "contacts-phone")474      await list(p).getByRole("link", { name: new RegExp(alice) }).click()475      await expect(card(p).getByRole("heading", { level: 2, name: alice })).toBeVisible()476      await expect(p.getByRole("region", { name: "Liste des contacts" })).toBeHidden()477      expect(await p.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth)).toBe(true)478      for (const name of ["Écrire", "Modifier", "Retirer des favoris"]) {479        const box = (await card(p).getByRole("button", { name, exact: true }).boundingBox())!480        expect(Math.min(box.width, box.height), name).toBeGreaterThanOrEqual(44)481      }482      await h().axe(p, "contacts-phone-card")483      await h().shot(p, "contacts-card-phone")484      await card(p).getByRole("button", { name: "Modifier" }).click()485      await expect(p.getByRole("dialog", { name: "Modifier le contact" })).toBeVisible()486      await h().shot(p, "contacts-edit-phone")487      await p.getByRole("dialog", { name: "Modifier le contact" }).getByRole("button", { name: "Annuler" }).click()488      await card(p).getByRole("link", { name: "Contacts" }).click()489      await expect(p).toHaveURL(/\/contacts$/)490      await expect(list(p).getByRole("link", { name: new RegExp(alice) })).toBeVisible()491    } finally {492      await ctx.close()493    }494  })495}496
Files main
Menu

Theme