SPB Git

Repository Public

v041.spec.ts 7.2 KB 133 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : KA Maps Engine8 * File             : sdk/web/tests/e2e/v041.spec.ts9 * Module           : sdk10 * 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// 0.4.1 : interroger la carte entre un changement de couche et la trame suivante ne lit plus les éléments de la43// trame d'avant (panique « index out of bounds » du moteur en 0.4.0 — correctif aa3fb88). C'est ce que fait un site44// quand un filtre change pendant que le pointeur bouge. Données synthétiques.45import { test, expect } from '@playwright/test';46import { mapBox, openDemo, settle, gpuMessages } from './helpers.js';4748test.afterEach(async ({ page }) => {49  expect(gpuMessages(page), 'validation graphique dans la console').toEqual([]);50});5152test('retrait ou remplacement de couche suivi d’une interrogation ou d’un clic avant la trame suivante : pas de panique', async ({ page }, testInfo) => {53  const problems = await openDemo(page, testInfo, { layers: '', zoom: 13 });54  await settle(page);55  const fatal: unknown[] = [];56  await page.exposeFunction('__kaFatal', (e: unknown) => fatal.push(e));57  await page.evaluate(() => window.kaMap!.on('error', (e) => (e as { fatal?: boolean }).fatal && (window as unknown as { __kaFatal(e: unknown): void }).__kaFatal(e)));58  const r = await page.evaluate(async () => {59    const m = window.kaMap!;60    const c = m.getCanvas() as HTMLCanvasElement;61    const frame = () => new Promise<void>((res) => requestAnimationFrame(() => requestAnimationFrame(() => res())));62    const b = m.getBounds();63    const mk = (n: number, seed: number) => {64      let s = seed;65      const r = () => ((s = (Math.imul(s, 1664525) + 1013904223) >>> 0) / 4294967296);66      return Array.from({ length: n }, (_, i) => ({ id: `${seed}-${i}`, lon: b[0] + (b[2] - b[0]) * r(), lat: b[1] + (b[3] - b[1]) * r(), value: 1000 + i, label: `${1000 + i} $` }));67    };68    const center: [number, number] = [c.clientWidth / 2, c.clientHeight / 2];69    const out: string[] = [];70    const step = (name: string, fn: () => unknown) => {71      try {72        fn();73        out.push(`${name} : ok`);74      } catch (e) {75        out.push(`${name} : ${String((e as Error).message).slice(0, 160)}`);76      }77    };78    for (let round = 0; round < 6; round++) {79      // Deux couches dessinées (pastilles, grappes, points), puis le « filtre » change dans le même tour.80      m.addLayer({ id: 'a', type: 'markers', data: mk(400, 10 + round), options: { cluster: { radius: 50, maxZoom: 14 } } });81      m.addLayer({ id: 'b', type: 'markers', data: mk(300, 50 + round), options: { cluster: false } });82      m.addLayer({ id: 'p', type: 'points', data: mk(200, 90 + round), options: { radius: 6 } });83      await frame();84      await frame();85      const drawn = m.queryLayer().length;86      // (1) couche retirée, puis interrogations avant la trame suivante.87      m.removeLayer('a');88      step('queryLayer après removeLayer', () => m.queryLayer());89      step('queryLayer(b) après removeLayer', () => m.queryLayer('b'));90      step('queryRendered après removeLayer', () => { for (let y = 60; y < c.clientHeight; y += 60) for (let x = 60; x < c.clientWidth; x += 60) m.queryRendered([x, y]); });91      // (2) données raccourcies, puis interrogations avant la trame suivante.92      m.setLayerData('b', mk(12, 500 + round));93      step('queryLayer après setLayerData', () => m.queryLayer('b'));94      step('queryRendered après setLayerData', () => { for (let y = 60; y < c.clientHeight; y += 60) for (let x = 60; x < c.clientWidth; x += 60) m.queryRendered([x, y]); });95      m.setLayerData('p', mk(3, 900 + round));96      step('queryRendered après setLayerData (points)', () => m.queryRendered(center));97      // (3) un clic et un survol synthétiques dans le même tour (le pointeur bouge pendant que le filtre change).98      const rect = c.getBoundingClientRect();99      step('pointeur après changement', () => {100        for (let i = 0; i < 12; i++) {101          const x = rect.left + 80 + i * 60;102          const y = rect.top + 120 + ((i * 53) % 400);103          const o = { bubbles: true, clientX: x, clientY: y, pointerId: 1, pointerType: 'mouse', isPrimary: true, button: 0 };104          c.dispatchEvent(new PointerEvent('pointermove', o));105          c.dispatchEvent(new PointerEvent('pointerdown', { ...o, buttons: 1 }));106          c.dispatchEvent(new PointerEvent('pointerup', o));107        }108      });109      await frame();110      out.push(`tour ${round} : ${drawn} éléments dessinés avant, ${m.queryLayer().length} après`);111      for (const id of ['b', 'p']) m.removeLayer(id);112      step('queryLayer après tout retirer', () => m.queryLayer());113    }114    await frame();115    return { out, alive: !m.isDestroyed, layers: m.listLayers().length, tiles: m.getPerf().tiles };116  });117  testInfo.annotations.push({ type: 'mesure', description: r.out.filter((l) => !l.endsWith(': ok')).join(' | ').slice(0, 900) });118  expect(r.out.filter((l) => !l.endsWith(': ok') && !l.startsWith('tour ')), 'commandes en erreur').toEqual([]);119  expect(fatal, 'erreur fatale du moteur (panique)').toEqual([]);120  expect(problems.errors.filter((e) => /panic|unreachable|RuntimeError|index out of bounds|pageerror/i.test(e))).toEqual([]);121  // La carte vit encore : une couche ajoutée ensuite se dessine et se laisse cliquer.122  await page.evaluate(() => window.kaMap!.addLayer({ id: 'fin', type: 'markers', data: window.kaDemo.markers, options: { cluster: false } }));123  await settle(page);124  const items = await page.evaluate(() => window.kaMap!.queryLayer('fin'));125  expect(items.length).toBeGreaterThan(10);126  const one = items.find((i) => i.pill !== false)!;127  const box = await mapBox(page);128  await page.mouse.click(box.x + (one.rect[0] + one.rect[2]) / 2, box.y + (one.rect[1] + one.rect[3]) / 2);129  await settle(page);130  expect(fatal).toEqual([]);131  expect(await page.evaluate(() => window.kaMap!.getPerf().tiles)).toBeGreaterThan(0);132});133
Files main
Menu

Theme