Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : KA Maps Engine8 * File : studio/e2e/sdk-preview.spec.ts9 * Module : studio10 * Repository : https://git.spboucher.ai/ka-maps-engine11 * Created : 2026-12-0112 * Last Modified : 2026-12-0113 *14 * Author : Simon-Pierre Boucher15 * Position : Professor of Finance16 * Institution : Université du Québec en Outaouais (UQO)17 * Organization : SP Boucher18 * Website : https://spboucher.ai19 * Git : https://git.spboucher.ai20 *21 * Preferred Contact: support@spboucher.ai22 * Development : dev@spboucher.ai23 * Support : support@spboucher.ai24 * Security/Admin : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142// Aperçu en direct par le SDK Web (@ka/maps, wasm) publié dans /sdk : la carte se dessine dans le43// navigateur (WebGL 2 logiciel en mode sans fenêtre) et suit le document en cours d'édition.44import { expect, test } from '@playwright/test';45import { existsSync, readFileSync } from 'node:fs';46import { dirname, join } from 'node:path';47import { fileURLToPath } from 'node:url';4849const here = dirname(fileURLToPath(import.meta.url));50const state = () => JSON.parse(readFileSync(join(here, '.state.json'), 'utf8'));51const shots = join(here, '..', 'test-results', 'shots');5253test('aperçu 2D et 3D par le SDK Web : carte dessinée, thème remplacé à chaud', async ({ browser }) => {54 test.skip(!existsSync('/var/lib/kamaps/sdk') || !process.env.E2E_SDK, 'aucun SDK Web publié (E2E_SDK=1 pour lancer)');55 const ctx = await browser.newContext();56 const page = await ctx.newPage();57 const errors: string[] = [];58 page.on('console', (m) => { if (m.type() === 'error') errors.push(m.text()); });59 page.on('pageerror', (e) => errors.push(String(e)));60 const cdp = await ctx.newCDPSession(page);61 await cdp.send('WebAuthn.enable');62 await cdp.send('WebAuthn.addVirtualAuthenticator', { options: { protocol: 'ctap2', transport: 'internal', hasResidentKey: true, hasUserVerification: true, isUserVerified: true, automaticPresenceSimulation: true } });63 await page.goto(`/activer#${state().tokens[1]}`);64 await page.getByRole('button', { name: "Créer ma clé d'accès" }).click();65 await page.getByRole('link', { name: 'Midnight' }).click();66 await expect(page.getByTestId('preview-kind')).toHaveValue('sdk', { timeout: 20_000 });67 for (const mode of ['2d', '3d']) {68 const pane = page.getByTestId(`preview-${mode}`);69 await expect(pane).toHaveAttribute('data-kind', 'sdk');70 await expect(pane.locator('canvas')).toBeVisible({ timeout: 30_000 });71 await expect(pane.locator('.err')).toHaveCount(0);72 }73 // la carte est réellement dessinée : l'image du canevas n'est pas uniforme74 const painted = async (mode: string) => {75 const png = await page.getByTestId(`preview-${mode}`).screenshot();76 return png.length;77 };78 await expect.poll(() => painted('2d'), { timeout: 40_000 }).toBeGreaterThan(15_000);79 await expect.poll(() => painted('3d'), { timeout: 40_000 }).toBeGreaterThan(15_000);80 const before = await page.getByTestId('preview-2d').screenshot();81 await page.screenshot({ path: join(shots, '20-sdk-midnight.png') });82 // changer la couleur du sol : la carte change sans rechargement83 const land = page.getByLabel('palette land', { exact: true });84 await land.fill('#3a1f1f');85 await land.blur();86 await expect.poll(async () => !(await page.getByTestId('preview-2d').screenshot()).equals(before), { timeout: 30_000 }).toBe(true);87 await page.waitForTimeout(1500);88 await page.screenshot({ path: join(shots, '21-sdk-sol-modifie.png') });89 // repli volontaire sur le rendu serveur90 await page.getByTestId('preview-kind').selectOption('serveur');91 await expect(page.locator('[data-testid=preview-2d] > img')).toHaveAttribute('src', /^blob:/, { timeout: 20_000 });92 expect(errors.filter((e) => !/favicon/.test(e))).toEqual([]);93 await ctx.close();94});95