SPB Git

Repository Public

templates-phone.spec.ts 8.5 KB 168 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : SP Mail8 * File             : tests/e2e/studio/templates-phone.spec.ts9 * Module           : tests10 * Repository       : https://git.spboucher.ai/sp-mail11 * Project Website  : https://mail.spboucher.ai12 * Created          : 2026-11-1913 * Last Modified    : 2026-11-1914 *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// Studio de modèles sur téléphone (390 × 844, tactile) : une zone à la fois, onglets, aucun défilement horizontal.44import { OUT } from "./env"45import { axe, card, expect, noOverflow, pretendAiConfigured, previewFrame, test, toastText } from "./fixtures"46import { recordedScenario, startReplay, stubGeneration, type Replay } from "./replay"47import { recordedTemplate, seedSimple, seedTemplate } from "./seed"4849let replay: Replay50test.describe.configure({ mode: "serial" })51test.beforeAll(async () => {52  replay = await startReplay()53})54test.afterAll(async () => {55  await replay.close()56})5758test("téléphone : bibliothèque en deux colonnes, sans défilement horizontal", async ({ page, request }) => {59  await seedSimple(request, "Téléphone — commande")60  await page.goto("/templates")61  const c = card(page, "Téléphone — commande")62  await expect(c).toBeVisible()63  await expect(c.frameLocator("iframe").locator("body")).toContainText("Bonjour Camille")64  const box = (await c.boundingBox())!65  expect(box.width).toBeLessThan(195)66  expect(box.width).toBeGreaterThan(150)67  await noOverflow(page)68  await axe(page, "phone-library")69  await page.screenshot({ path: `${OUT}/shots/phone-library.png` })70  // actions de la carte au doigt71  await c.getByRole("button", { name: /^Actions pour/ }).tap()72  await expect(page.getByRole("menuitem", { name: "Dupliquer" })).toBeVisible()73  await page.keyboard.press("Escape")74  await noOverflow(page)75})7677test("téléphone : création par IA (flux rejoué), identité de marque, puis éditeur", async ({ page, request }) => {78  const t = recordedTemplate()79  const made = await seedTemplate(request, { name: `${t.name} (téléphone)`, category: "transactional", subject: t.subject, preheader: t.preheader, html: t.html, text: t.text, variables: t.variables })80  await pretendAiConfigured(page)81  await stubGeneration(page, replay, recordedScenario(made, { delay: 40, firstDelay: 300 }))82  await page.goto("/templates")83  await page.getByRole("link", { name: "Créer avec l'IA" }).tap()84  await expect(page.getByRole("heading", { name: "Décrivez le courriel" })).toBeVisible()85  await page.locator("summary", { hasText: "Identité de marque" }).tap()86  await expect(page.getByLabel("Couleur d'accent", { exact: true })).toBeVisible()87  await noOverflow(page)88  await axe(page, "phone-generator")89  await page.screenshot({ path: `${OUT}/shots/phone-generator.png`, fullPage: true })90  await page.getByRole("button", { name: "Infolettre" }).tap()91  await expect(page.getByLabel("Brief")).toHaveValue(/^Numéro d'une infolettre mensuelle/)92  await page.getByRole("button", { name: "Générer le modèle" }).tap()93  const gen = page.getByTestId("generation")94  await expect(gen).toHaveAttribute("data-phase", "running")95  await gen.scrollIntoViewIfNeeded()96  await expect(gen.getByRole("button", { name: "Annuler la génération" })).toBeVisible()97  await noOverflow(page)98  await page.screenshot({ path: `${OUT}/shots/phone-generating.png` })99  await expect(page).toHaveURL(new RegExp(`/templates/${made.id}$`), { timeout: 20_000 })100  await expect(previewFrame(page).locator("body")).toContainText("Bienvenue,")101  expect(replay.requests.at(-1)).toMatchObject({ category: "newsletter", language: "fr" })102})103104test("téléphone : éditeur en onglets (aperçu, contenu, variables), enregistrement, versions", async ({ page, request }) => {105  const tpl = await seedSimple(request, "Téléphone — éditeur")106  await page.goto(`/templates/${tpl.id}`)107  const zones = page.getByRole("tablist", { name: "Zones de l'éditeur" })108  await expect(zones.getByRole("tab")).toHaveText(["Aperçu", "Contenu", "Variables"])109  await expect(zones.getByRole("tab", { name: "Aperçu" })).toHaveAttribute("aria-selected", "true")110  const frame = previewFrame(page)111  await expect(frame.locator("body")).toContainText("Bonjour Camille")112  await expect(page.getByRole("tabpanel", { name: "Contenu" })).toBeHidden()113  // l'aperçu « ordinateur » est réduit pour tenir dans l'écran ; « téléphone » montre le cadre de 390 px114  const stage = page.getByTestId("preview-stage")115  expect((await stage.locator(".tpl-frame").boundingBox())!.width).toBeLessThan(360)116  await expect(frame.locator("h1")).toHaveCSS("font-size", "28px")117  await page.getByRole("button", { name: "Téléphone" }).tap()118  await expect(stage.locator(".tpl-device.mobile")).toBeVisible()119  await expect(frame.locator("h1")).toHaveCSS("font-size", "22px")120  await page.getByRole("button", { name: "Sombre" }).tap()121  await expect(frame.locator("table.card")).toHaveCSS("background-color", "rgb(32, 32, 32)")122  await noOverflow(page)123  await axe(page, "phone-editor-preview")124  await page.screenshot({ path: `${OUT}/shots/phone-editor-preview.png` })125126  // variables127  await zones.getByRole("tab", { name: "Variables" }).tap()128  await expect(page.getByRole("tabpanel", { name: "Variables" })).toBeVisible()129  await expect(page.getByRole("tabpanel", { name: "Aperçu" })).toBeHidden()130  await page.locator('[data-variable="first_name"]').fill("Maëlle")131  await noOverflow(page)132  await axe(page, "phone-editor-variables")133  await zones.getByRole("tab", { name: "Aperçu" }).tap()134  await expect(frame.locator("body")).toContainText("Bonjour Maëlle")135136  // contenu : champs, source HTML, enregistrement137  await zones.getByRole("tab", { name: "Contenu" }).tap()138  await page.getByLabel("Nom du modèle").fill("Téléphone — éditeur (v2)")139  await page.getByLabel("Objet", { exact: true }).fill("Commande {{order_id}} expédiée")140  await noOverflow(page)141  await axe(page, "phone-editor-content")142  await page.screenshot({ path: `${OUT}/shots/phone-editor-content.png` })143  await page.getByRole("tab", { name: "HTML" }).tap()144  await expect(page.getByRole("textbox", { name: "Source HTML du modèle" })).toBeVisible()145  await noOverflow(page)146  await axe(page, "phone-editor-html")147  await page.screenshot({ path: `${OUT}/shots/phone-editor-html.png` })148  await page.getByTestId("save").tap()149  await expect(toastText(page, "Enregistré — version 2")).toBeVisible()150  await expect(page.getByTestId("save-state")).toContainText("Enregistré · version 2")151152  // tiroir des versions en pleine largeur153  await page.getByRole("button", { name: /^Versions?( \d+)?$/ }).tap()154  const drawer = page.getByTestId("versions-drawer")155  await expect(drawer).toBeVisible()156  expect((await drawer.boundingBox())!.width).toBe(390)157  await drawer.locator('.tpl-version[data-version="1"]').tap()158  await expect(drawer.frameLocator("iframe").locator("body")).toContainText("Bonjour Camille")159  await noOverflow(page)160  await axe(page, "phone-versions")161  await drawer.getByRole("button", { name: "Fermer" }).tap()162  // utiliser dans un message : dialogue lisible sur téléphone163  await page.getByRole("button", { name: "Utiliser dans un message" }).tap()164  await expect(page.getByRole("dialog", { name: "Utiliser ce modèle" })).toBeVisible()165  await noOverflow(page)166  await page.keyboard.press("Escape")167})168
Files main
Menu

Theme