SPB Git

Repository Public

attachments.part.ts 24.3 KB 400 lines typescript

1// SP Mail Next — essais de la zone « pièces jointes » : galerie (filtres, vignettes sûres), aperçu (image, texte, PDF), ZIP vérifié octet par octet, message d'origine, lecteur, rédaction, téléphone.2import { expect, test, type Page } from "@playwright/test"3import fs from "node:fs"4import zlib from "node:zlib"5import { row, toastText } from "../helpers"6import type { Part } from "./harness"78// ---------------------------------------------------------------- fichiers d'essai (construits en mémoire)9/** PNG RVB sans dépendance : dégradé simple, pour des vignettes reconnaissables. */10function png(width: number, height: number, tint: [number, number, number]): Buffer {11  const raw = Buffer.alloc((width * 3 + 1) * height)12  for (let y = 0; y < height; y++) {13    raw[y * (width * 3 + 1)] = 014    for (let x = 0; x < width; x++) {15      const at = y * (width * 3 + 1) + 1 + x * 316      raw[at] = Math.round((tint[0] * (x + 1)) / width)17      raw[at + 1] = Math.round((tint[1] * (y + 1)) / height)18      raw[at + 2] = tint[2]19    }20  }21  const chunk = (type: string, data: Buffer) => {22    const len = Buffer.alloc(4)23    len.writeUInt32BE(data.length)24    const body = Buffer.concat([Buffer.from(type, "latin1"), data])25    const crc = Buffer.alloc(4)26    crc.writeUInt32BE(zlib.crc32(body) >>> 0)27    return Buffer.concat([len, body, crc])28  }29  const head = Buffer.alloc(13)30  head.writeUInt32BE(width, 0)31  head.writeUInt32BE(height, 4)32  head[8] = 833  head[9] = 234  return Buffer.concat([Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]), chunk("IHDR", head), chunk("IDAT", zlib.deflateSync(raw)), chunk("IEND", Buffer.alloc(0))])35}36/** PDF d'une page portant un court texte. */37function pdf(text: string): Buffer {38  const stream = `BT /F1 28 Tf 40 100 Td (${text}) Tj ET`39  const objs = [40    "<< /Type /Catalog /Pages 2 0 R >>", "<< /Type /Pages /Kids [3 0 R] /Count 1 >>", "<< /Type /Page /Parent 2 0 R /MediaBox [0 0 360 220] /Contents 4 0 R /Resources << /Font << /F1 5 0 R >> >> >>",41    `<< /Length ${stream.length} >>\nstream\n${stream}\nendstream`, "<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>",42  ]43  let out = "%PDF-1.4\n"44  const offsets: number[] = []45  objs.forEach((o, i) => {46    offsets.push(out.length)47    out += `${i + 1} 0 obj\n${o}\nendobj\n`48  })49  const xref = out.length50  out += `xref\n0 ${objs.length + 1}\n0000000000 65535 f \n${offsets.map((o) => `${String(o).padStart(10, "0")} 00000 n \n`).join("")}trailer\n<< /Size ${objs.length + 1} /Root 1 0 R >>\nstartxref\n${xref}\n%%EOF\n`51  return Buffer.from(out, "latin1")52}53/** Entrées d'une archive ZIP lues dans son répertoire central, contenu décompressé (deflate brut). */54function unzip(buf: Buffer): { name: string; data: Buffer; crc: number }[] {55  const end = buf.lastIndexOf(Buffer.from([0x50, 0x4b, 0x05, 0x06]))56  if (end < 0) throw new Error("no end of central directory")57  const count = buf.readUInt16LE(end + 10)58  let at = buf.readUInt32LE(end + 16)59  const out: { name: string; data: Buffer; crc: number }[] = []60  for (let i = 0; i < count; i++) {61    if (buf.readUInt32LE(at) !== 0x02014b50) throw new Error("bad central header")62    const method = buf.readUInt16LE(at + 10)63    const crc = buf.readUInt32LE(at + 16)64    const packed = buf.readUInt32LE(at + 20)65    const size = buf.readUInt32LE(at + 24)66    const nameLen = buf.readUInt16LE(at + 28)67    const extraLen = buf.readUInt16LE(at + 30)68    const commentLen = buf.readUInt16LE(at + 32)69    const local = buf.readUInt32LE(at + 42)70    const name = buf.subarray(at + 46, at + 46 + nameLen).toString("utf8")71    if (buf.readUInt32LE(local) !== 0x04034b50) throw new Error("bad local header")72    const start = local + 30 + buf.readUInt16LE(local + 26) + buf.readUInt16LE(local + 28)73    const body = buf.subarray(start, start + packed)74    const data = method === 8 ? zlib.inflateRawSync(body) : Buffer.from(body)75    if (data.length !== size) throw new Error(`size mismatch for ${name}`)76    out.push({ name, data, crc })77    at += 46 + nameLen + extraLen + commentLen78  }79  return out80}8182export const attachmentsPart: Part = (h) => {83  const f = () => {84    const run = h().run85    return {86      photo: `photo-${run}.png`, notes: `notes-${run}.txt`, report: `rapport-${run}.pdf`, logo: `logo-${run}.svg`, other: `image-p2-${run}.png`, sheet: `chiffres-${run}.csv`,87      s1: `Photos du chantier ${run}`, s2: `Rapport trimestriel ${run}`, s3: `Documents de la seconde boîte ${run}`,88    }89  }90  const PHOTO = png(96, 72, [230, 120, 60])91  const OTHER = png(80, 80, [40, 160, 220])92  const NOTES = "Notes de réunion — été 2026\n<b>gras</b> & <script>alert(1)</script>\nLigne 3 : çà et là.\n"93  const REPORT = pdf("Rapport SP Mail")94  const LOGO = `<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40"><script>alert(1)</script><rect width="40" height="40" fill="red"/></svg>`95  const SHEET = "mois;total\njanvier;12\nfévrier;15\n"96  const grid = (p: Page) => p.getByRole("list", { name: "Pièces jointes" })97  const tile = (p: Page, name: string) => grid(p).getByRole("listitem").filter({ hasText: name })98  /** Fichiers de cette zone affichés (dans le parcours complet, d'autres zones déposent aussi des pièces jointes). */99  const names = async (p: Page) => (await grid(p).locator(".nx-ga-name").allTextContents()).filter((n) => Object.values(f()).includes(n)).sort()100  const preview = (p: Page) => p.locator(".nx-pv")101  const openGallery = async (p: Page) => {102    await p.getByRole("link", { name: "Pièces jointes", exact: true }).click()103    await expect(p.getByRole("heading", { level: 1, name: "Pièces jointes" })).toBeVisible()104  }105106  test("pièces jointes : galerie — vignettes des seules images sûres, filtres par type, boîte, nom, taille", async () => {107    const { page, P1, P2 } = h()108    const x = f()109    await h().seed(page, P1, [110      { subject: x.s1, from: ["Carole Chantier", `carole.${h().run}@example.com`], preview: "Voici les photos.", minutesAgo: 6, attachments: [{ name: x.photo, type: "image/png", base64: PHOTO.toString("base64") }, { name: x.notes, type: "text/plain", text: NOTES }, { name: x.logo, type: "image/svg+xml", text: LOGO }] },111      { subject: x.s2, from: ["Denis Rapport", `denis.${h().run}@example.com`], preview: "Le rapport est joint.", minutesAgo: 4, attachments: [{ name: x.report, type: "application/pdf", base64: REPORT.toString("base64") }] },112    ])113    await h().seed(page, P2, [114      { subject: x.s3, from: ["Émile Second", `emile.${h().run}@example.com`], preview: "Deux fichiers.", minutesAgo: 2, attachments: [{ name: x.other, type: "image/png", base64: OTHER.toString("base64") }, { name: x.sheet, type: "text/csv", text: SHEET }] },115    ])116    await openGallery(page)117    const all = [x.photo, x.notes, x.logo, x.report, x.other, x.sheet].sort()118    await expect.poll(() => names(page), { timeout: 30_000 }).toEqual(all)119120    // vignette : seulement les PNG (servis par la passerelle avec inline=1) ; SVG, PDF, texte : un glyphe121    for (const name of [x.photo, x.other]) {122      const img = tile(page, name).locator(".nx-ga-thumb img")123      await expect(img).toHaveAttribute("src", /\/api\/jmap\/[0-9a-f-]+\/download\/.*accept=image%2Fpng&inline=1$/)124      await expect.poll(() => img.evaluate((el: HTMLImageElement) => el.complete && el.naturalWidth)).toBeGreaterThan(0)125    }126    for (const name of [x.logo, x.report, x.notes, x.sheet]) await expect(tile(page, name).locator("img")).toHaveCount(0)127    expect(await page.locator('.nx-ga img[src*="svg"]').count()).toBe(0)128    await expect(tile(page, x.report)).toContainText("PDF")129    await expect(tile(page, x.photo)).toContainText("Carole Chantier")130131    // type : images (le SVG en est une pour le serveur, sans vignette), puis PDF en plus132    await page.getByRole("group", { name: "Type de fichier" }).getByRole("button", { name: "Images" }).click()133    await expect.poll(() => names(page)).toEqual([x.photo, x.logo, x.other].sort())134    await page.getByRole("group", { name: "Type de fichier" }).getByRole("button", { name: "PDF" }).click()135    await expect.poll(() => names(page)).toEqual([x.photo, x.logo, x.other, x.report].sort())136    await page.getByRole("button", { name: "Réinitialiser" }).click()137    await expect.poll(() => names(page)).toEqual(all)138    // boîte139    await page.getByLabel("Boîte", { exact: true }).selectOption({ label: P2 })140    await expect.poll(() => names(page)).toEqual([x.other, x.sheet].sort())141    await page.getByLabel("Boîte", { exact: true }).selectOption({ label: "Toutes les boîtes" })142    // nom de fichier143    await page.getByLabel("Rechercher un nom de fichier").fill("RAPPORT")144    await expect.poll(() => names(page)).toEqual([x.report])145    await page.getByLabel("Rechercher un nom de fichier").fill("")146    // expéditeur147    await page.getByLabel("Expéditeur", { exact: true }).fill(`denis.${h().run}@example.com`)148    await expect.poll(() => names(page)).toEqual([x.report])149    await page.getByLabel("Expéditeur", { exact: true }).fill("")150    await expect.poll(() => names(page)).toEqual(all)151    // période et taille : tout est récent et petit152    await page.getByLabel("Période").selectOption({ label: "7 derniers jours" })153    await expect.poll(() => names(page)).toEqual(all)154    await page.getByLabel("Taille", { exact: true }).selectOption({ label: "Plus de 10 Mo" })155    await expect(page.getByText("Aucune pièce jointe ne correspond à ces filtres.")).toBeVisible()156    await page.getByRole("button", { name: "Réinitialiser" }).last().click()157    await expect.poll(() => names(page)).toEqual(all)158159    await h().axeThemes(page, "attachments")160    await h().shotThemes(page, "attachments")161  })162163  test("pièces jointes : aperçu — image, texte brut jamais interprété, PDF selon le navigateur, flèches, téléchargement", async () => {164    const { page } = h()165    const x = f()166    await openGallery(page)167    await expect(tile(page, x.photo)).toBeVisible()168    // image169    await page.getByRole("button", { name: `Aperçu de ${x.photo}` }).click()170    const dlg = page.getByRole("dialog", { name: x.photo })171    await expect(dlg).toBeVisible()172    const img = dlg.locator("img.nx-pv-img")173    await expect(img).toHaveAttribute("src", /&inline=1$/)174    await expect.poll(() => img.evaluate((el: HTMLImageElement) => el.naturalWidth)).toBe(96)175    await expect(dlg).toContainText(/\d+ sur \d+/)176    for (const [theme, label] of [["dark", "Sombre"], ["midnight", "Minuit"], ["light", "Clair"]] as const) {177      await page.keyboard.press("Escape")178      await h().setTheme(page, label, theme)179      await page.getByRole("button", { name: `Aperçu de ${x.photo}` }).click()180      await expect(preview(page).locator("img.nx-pv-img")).toBeVisible()181      await h().axe(page, `attachments-preview-${theme}`)182      if (theme !== "dark") await h().shot(page, `attachments-preview-${theme}`)183    }184    // flèches : la galerie est parcourue dans son ordre, sans quitter le dialogue185    const order = await grid(page).locator(".nx-ga-name").allTextContents()186    const at = order.indexOf(x.photo)187    if (at < order.length - 1) {188      await page.keyboard.press("ArrowRight")189      await expect(preview(page).getByRole("heading", { level: 2 })).toHaveText(order[at + 1])190      await page.keyboard.press("ArrowLeft")191    } else {192      await page.keyboard.press("ArrowLeft")193      await expect(preview(page).getByRole("heading", { level: 2 })).toHaveText(order[at - 1])194      await page.keyboard.press("ArrowRight")195    }196    await expect(preview(page).getByRole("heading", { level: 2 })).toHaveText(x.photo)197    await page.keyboard.press("Escape")198    await expect(preview(page)).toHaveCount(0)199200    // texte : le contenu est du texte, aucune balise n'est créée201    await page.getByRole("button", { name: `Aperçu de ${x.notes}` }).click()202    const pre = preview(page).locator("pre.nx-pv-text")203    await expect.poll(() => pre.evaluate((el) => el.textContent)).toBe(NOTES)204    await expect(pre).toContainText("<b>gras</b> & <script>alert(1)</script>")205    expect(await preview(page).locator("b, script, iframe").count()).toBe(0)206    await h().shot(page, "attachments-preview-text-light")207    await page.keyboard.press("Escape")208209    // SVG : jamais affiché, seulement proposé au téléchargement210    await page.getByRole("button", { name: `Aperçu de ${x.logo}` }).click()211    await expect(preview(page)).toContainText("Pas d'aperçu pour ce type de fichier.")212    expect(await preview(page).locator("img, iframe, svg:not(.icon), object, embed").count()).toBe(0)213    await page.keyboard.press("Escape")214215    // PDF : jamais de visionneuse dans la page (CSP inchangée) → une ligne d'explication et le téléchargement216    await page.getByRole("button", { name: `Aperçu de ${x.report}` }).click()217    await expect(preview(page)).toContainText("Par sécurité, SP Mail n'ouvre pas les PDF dans la page : téléchargez le fichier pour le lire.")218    expect(await preview(page).locator("iframe, object, embed").count()).toBe(0)219    await h().axe(page, "attachments-preview-pdf")220    await h().shot(page, "attachments-preview-pdf-light")221    const [download] = await Promise.all([page.waitForEvent("download"), preview(page).locator(".nx-pv-body").getByRole("link", { name: "Télécharger" }).click()])222    expect(download.suggestedFilename()).toBe(x.report)223    expect(fs.readFileSync(await download.path()).equals(REPORT)).toBe(true)224    // la passerelle sert le fichier en pièce jointe opaque, dans un bac à sable225    const headers = await page.evaluate(async (url) => {226      const r = await fetch(url)227      return { type: r.headers.get("content-type"), disposition: r.headers.get("content-disposition"), csp: r.headers.get("content-security-policy") }228    }, (await preview(page).locator(".nx-pv-body").getByRole("link", { name: "Télécharger" }).getAttribute("href"))!)229    expect(headers.type).toBe("application/octet-stream")230    expect(headers.disposition).toMatch(/^attachment;/)231    expect(headers.csp).toContain("sandbox")232    await page.keyboard.press("Escape")233    await expect(preview(page)).toHaveCount(0)234  })235236  test("pièces jointes : sélection multiple → ZIP dont les octets sont vérifiés ; erreurs 413, 404, 429", async () => {237    const { page } = h()238    const x = f()239    await openGallery(page)240    await expect(tile(page, x.photo)).toBeVisible()241    for (const name of [x.photo, x.notes, x.other, x.sheet]) await page.getByRole("checkbox", { name: `Sélectionner ${name}` }).check()242    const bar = page.getByRole("group", { name: "Sélection" })243    await expect(bar).toContainText("4 sélectionnées")244    await h().shot(page, "attachments-selection-light")245    const [download] = await Promise.all([page.waitForEvent("download"), bar.getByRole("button", { name: "Télécharger en ZIP" }).click()])246    expect(download.suggestedFilename()).toBe("pieces-jointes.zip")247    const zip = fs.readFileSync(await download.path())248    expect(zip.subarray(0, 4).equals(Buffer.from([0x50, 0x4b, 0x03, 0x04]))).toBe(true)249    const entries = unzip(zip)250    expect(entries.map((e) => e.name).sort()).toEqual([x.photo, x.notes, x.other, x.sheet].sort())251    const by = (name: string) => entries.find((e) => e.name === name)!252    expect(by(x.notes).data.toString("utf8")).toBe(NOTES)253    expect(by(x.sheet).data.toString("utf8")).toBe(SHEET)254    expect(by(x.photo).data.equals(PHOTO)).toBe(true)255    expect(by(x.other).data.equals(OTHER)).toBe(true)256    for (const e of entries) expect(zlib.crc32(e.data) >>> 0, e.name).toBe(e.crc)257    await expect(toastText(page, "Archive téléchargée : pieces-jointes.zip")).toBeVisible()258    // la sélection est vidée après le téléchargement259    await expect(page.getByRole("group", { name: "Sélection" })).toHaveCount(0)260261    // refus du serveur : chaque cas a son message, la sélection est gardée pour réessayer262    await page.getByRole("checkbox", { name: `Sélectionner ${x.notes}` }).check()263    const cases: [number, string, string][] = [[413, "too_large", "La sélection dépasse 200 Mo"], [404, "not_found", "Une pièce jointe n'existe plus"], [429, "rate_limited", "Trop d'archives demandées"]]264    for (const [status, error, text] of cases) {265      await page.route("**/api/next/attachments/zip", (route) => route.fulfill({ status, contentType: "application/json", body: JSON.stringify({ error, message: "x" }) }), { times: 1 })266      await page.getByRole("group", { name: "Sélection" }).getByRole("button", { name: "Télécharger en ZIP" }).click()267      await expect(toastText(page, text)).toBeVisible()268      await expect(page.getByRole("group", { name: "Sélection" })).toContainText("1 sélectionnée")269      await toastText(page, text).locator("button").last().click()270      await expect(toastText(page, text)).toHaveCount(0)271    }272    await page.getByRole("button", { name: "Tout désélectionner" }).click()273    await expect(page.getByRole("group", { name: "Sélection" })).toHaveCount(0)274  })275276  test("pièces jointes : message d'origine, aperçu commun dans le lecteur", async () => {277    const { page, P1 } = h()278    const x = f()279    await openGallery(page)280    await page.getByRole("link", { name: `Ouvrir le message de ${x.report}` }).click()281    await expect(page).toHaveURL(/\/m\/0\/inbox\/t\//)282    await expect(page.locator(".reader-subject")).toHaveText(new RegExp(x.s2))283    // lecteur : le PDF et le texte passent par le même dialogue que la galerie284    const strip = page.getByRole("region", { name: "Pièces jointes" })285    await strip.getByRole("button", { name: `Aperçu de ${x.report}` }).click()286    await expect(preview(page)).toContainText("Par sécurité, SP Mail n'ouvre pas les PDF dans la page : téléchargez le fichier pour le lire.")287    await page.keyboard.press("Escape")288    await h().openBox(page, P1)289    await row(page, new RegExp(x.s1)).click()290    await expect(page.locator(".reader-subject")).toHaveText(new RegExp(x.s1))291    await page.getByRole("region", { name: "Pièces jointes" }).getByRole("button", { name: `Aperçu de ${x.notes}` }).click()292    await expect(preview(page).locator("pre.nx-pv-text")).toContainText("Notes de réunion — été 2026")293    await expect(preview(page)).toContainText("sur 3")294    // les pièces du message se parcourent aux flèches ; l'image garde l'affichage en ligne de la passerelle295    await page.keyboard.press("ArrowLeft")296    await expect(preview(page).getByRole("heading", { level: 2 })).toHaveText(x.photo)297    await expect.poll(() => preview(page).locator("img.nx-pv-img").evaluate((el: HTMLImageElement) => el.naturalWidth)).toBe(96)298    await page.keyboard.press("ArrowRight")299    await page.keyboard.press("ArrowRight")300    await expect(preview(page).getByRole("heading", { level: 2 })).toHaveText(x.logo)301    await expect(preview(page)).toContainText("Pas d'aperçu pour ce type de fichier.")302    await h().axe(page, "attachments-reader-preview")303    await page.keyboard.press("Escape")304    await expect(preview(page)).toHaveCount(0)305  })306307  test("pièces jointes : joindre à un nouveau message — le brouillon enregistré porte vraiment les fichiers", async () => {308    const { page, P1 } = h()309    const x = f()310    await page.goto("/")311    await h().openBox(page, P1)312    await openGallery(page)313    // une pièce de la boîte du brouillon (reprise par son blob) et une d'une autre boîte (octets recopiés)314    await page.getByRole("checkbox", { name: `Sélectionner ${x.notes}` }).check()315    await page.getByRole("checkbox", { name: `Sélectionner ${x.other}` }).check()316    await page.getByRole("group", { name: "Sélection" }).getByRole("button", { name: "Joindre à un nouveau message" }).click()317    const composer = page.locator("section.composer")318    await expect(composer).toBeVisible()319    await expect(composer.locator(".composer-att")).toHaveCount(2)320    await expect(composer.locator(".composer-atts")).toContainText(x.notes)321    await expect(composer.locator(".composer-atts")).toContainText(x.other)322    await expect(composer.locator(".composer-att progress")).toHaveCount(0)323    await expect(composer.locator(".composer-att.error")).toHaveCount(0)324    await expect(toastText(page, "2 pièces jointes au nouveau message.")).toBeVisible()325    await composer.getByLabel("Objet :").fill(`Brouillon avec pièces ${h().run}`)326    await expect(composer.locator('.composer-save[data-save="saved"]')).toHaveText("Enregistré", { timeout: 30_000 })327    // vérification côté serveur : le brouillon de P1 porte les deux fichiers, octets identiques328    const res = await h().jmap(page, P1, [329      ["Email/query", { filter: { subject: `Brouillon avec pièces ${h().run}` } }, "q"],330      ["Email/get", { "#ids": { resultOf: "q", name: "Email/query", path: "/ids" }, properties: ["subject", "keywords", "attachments"] }, "g"],331    ])332    const drafts = res[1][1].list as { keywords: Record<string, boolean>; attachments: { name: string; blobId: string; type: string; size: number }[] }[]333    expect(drafts).toHaveLength(1)334    expect(drafts[0].keywords.$draft).toBe(true)335    expect(drafts[0].attachments.map((a) => a.name).sort()).toEqual([x.notes, x.other].sort())336    const bytes = async (name: string) => {337      const a = drafts[0].attachments.find((p) => p.name === name)!338      const b64 = await page.evaluate(async ({ address, blobId, type }) => {339        const me = await (await fetch("/api/me")).json()340        const mb = me.mailboxes.find((m: { address: string }) => m.address === address).id341        const session = await (await fetch(`/api/jmap/${mb}/session`)).json()342        const accountId = session.primaryAccounts["urn:ietf:params:jmap:mail"]343        const r = await fetch(`/api/jmap/${mb}/download/${accountId}/${blobId}/f?accept=${encodeURIComponent(type)}`)344        if (!r.ok) throw new Error(`download → ${r.status}`)345        let s = ""346        for (const c of new Uint8Array(await r.arrayBuffer())) s += String.fromCharCode(c)347        return btoa(s)348      }, { address: P1, blobId: a.blobId, type: a.type })349      return Buffer.from(b64, "base64")350    }351    expect((await bytes(x.notes)).toString("utf8")).toBe(NOTES)352    expect((await bytes(x.other)).equals(OTHER)).toBe(true)353    await composer.getByRole("button", { name: "Supprimer le brouillon" }).click()354    await page.getByRole("alertdialog", { name: "Supprimer ce brouillon ?" }).getByRole("button", { name: "Supprimer le brouillon" }).click()355    await expect(composer).toHaveCount(0)356    await expect(page.getByRole("group", { name: "Sélection" })).toHaveCount(0)357358    // raccourci « g f » et palette359    await page.goto("/")360    await h().openBox(page, P1)361    await page.locator("body").press("g")362    await page.locator("body").press("f")363    await expect(page.getByRole("heading", { level: 1, name: "Pièces jointes" })).toBeVisible()364    await page.goto("/")365    await h().openBox(page, P1)366    await h().palette(page, ">aller aux pièces jointes", /^Aller aux pièces jointes/)367    await expect(page.getByRole("heading", { level: 1, name: "Pièces jointes" })).toBeVisible()368  })369370  test("pièces jointes : téléphone — grille à deux colonnes, cases et actions de 44 px, aperçu plein écran", async () => {371    const x = f()372    const { ctx, p } = await h().fromStorage({ width: 390, height: 844 }, true)373    try {374      await p.goto("/attachments")375      await expect(p.getByRole("heading", { level: 1, name: "Pièces jointes" })).toBeVisible()376      await expect(tile(p, x.photo)).toBeVisible()377      await expect(p.getByRole("navigation", { name: "Navigation principale" })).toBeVisible()378      expect(await p.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth)).toBe(true)379      const boxes = await grid(p).getByRole("listitem").evaluateAll((els) => els.slice(0, 2).map((el) => el.getBoundingClientRect().top))380      expect(boxes[0]).toBe(boxes[1]) // deux tuiles par rangée381      for (const loc of [p.locator(".nx-ga-check").first(), tile(p, x.photo).getByRole("link", { name: `Télécharger ${x.photo}` }), tile(p, x.photo).getByRole("link", { name: `Ouvrir le message de ${x.photo}` })]) {382        const box = (await loc.boundingBox())!383        expect(Math.min(box.width, box.height)).toBeGreaterThanOrEqual(44)384      }385      await h().axe(p, "attachments-phone")386      await h().shot(p, "attachments-phone")387      await p.getByRole("button", { name: `Aperçu de ${x.photo}` }).tap()388      await expect(preview(p).locator("img.nx-pv-img")).toBeVisible()389      const box = (await preview(p).boundingBox())!390      expect(Math.round(box.width)).toBe(390)391      await h().axe(p, "attachments-preview-phone")392      await h().shot(p, "attachments-preview-phone")393      await preview(p).getByRole("button", { name: "Fermer" }).tap()394      await expect(preview(p)).toHaveCount(0)395    } finally {396      await ctx.close()397    }398  })399}400
Files main
Menu

Theme