From 97a0a25d61f93083aa0cdfe3935c5da929fb0254 Mon Sep 17 00:00:00 2001 From: bchanot Date: Fri, 20 Nov 2026 16:01:26 +0100 Subject: [PATCH] test(tests): addByKeyboard in its own helper module --- apps/app/tests/helpers/addByKeyboard.ts | 7 +++++++ apps/app/tests/helpers/editorHarness.ts | 7 ------- apps/app/tests/unit/editor-add-buttons.test.tsx | 8 ++------ apps/app/tests/unit/editor-annotations-tab.test.tsx | 2 +- apps/app/tests/unit/editor-creation-dialog.test.tsx | 9 ++------- apps/app/tests/unit/editor-keep-alive.test.tsx | 2 +- apps/app/tests/unit/editor-no-loss.test.tsx | 2 +- apps/app/tests/unit/editor-point-edit.test.tsx | 2 +- apps/app/tests/unit/editor-sections.test.tsx | 2 +- 9 files changed, 16 insertions(+), 25 deletions(-) create mode 100644 apps/app/tests/helpers/addByKeyboard.ts diff --git a/apps/app/tests/helpers/addByKeyboard.ts b/apps/app/tests/helpers/addByKeyboard.ts new file mode 100644 index 00000000..ec68a93b --- /dev/null +++ b/apps/app/tests/helpers/addByKeyboard.ts @@ -0,0 +1,7 @@ +import type { UserEvent } from '@testing-library/user-event' + +/** C7: « Ajouter … » by keyboard (Enter), the shape at the centre with its dialog at once. */ +export async function addByKeyboard(user: UserEvent, button: HTMLElement) { + button.focus() + await user.keyboard('{Enter}') +} diff --git a/apps/app/tests/helpers/editorHarness.ts b/apps/app/tests/helpers/editorHarness.ts index 0c6d9c36..4bcee79c 100644 --- a/apps/app/tests/helpers/editorHarness.ts +++ b/apps/app/tests/helpers/editorHarness.ts @@ -1,6 +1,5 @@ import { expect, vi } from 'vitest' import { fireEvent } from '@testing-library/react' -import type { UserEvent } from '@testing-library/user-event' import type { EditCommand } from '@faunosteo/core-wasm/types' import * as supabase from '@faunosteo/supabase' import { useEditorStore } from '@/editor/state/editorStore' @@ -112,9 +111,3 @@ export function pressAt(el: Element, x = 0, y = 0): void { fireEvent.pointerDown(el, init) fireEvent.pointerUp(el, { ...init, buttons: 0 }) } - -/** C7: « Ajouter … » by keyboard (Enter), the shape at the centre with its dialog at once. */ -export async function addByKeyboard(user: UserEvent, button: HTMLElement) { - button.focus() - await user.keyboard('{Enter}') -} diff --git a/apps/app/tests/unit/editor-add-buttons.test.tsx b/apps/app/tests/unit/editor-add-buttons.test.tsx index d03ee28a..a5e2a7f8 100644 --- a/apps/app/tests/unit/editor-add-buttons.test.tsx +++ b/apps/app/tests/unit/editor-add-buttons.test.tsx @@ -15,12 +15,8 @@ import { fr } from '@/i18n/fr' import { useLocaleStore } from '@/state/localeStore' import { drawnText, insert, point } from '../helpers/editorFixtures' import { LayeredTab } from '../helpers/annotationLayer' -import { - addByKeyboard, - openReady, - pressAt, - resetStore, -} from '../helpers/editorHarness' +import { addByKeyboard } from '../helpers/addByKeyboard' +import { openReady, pressAt, resetStore } from '../helpers/editorHarness' vi.mock('@/lib/supabase', () => ({ getSupabaseClient: () => ({}) })) vi.mock('@faunosteo/supabase', async (orig) => ({ diff --git a/apps/app/tests/unit/editor-annotations-tab.test.tsx b/apps/app/tests/unit/editor-annotations-tab.test.tsx index 43723191..42e866c8 100644 --- a/apps/app/tests/unit/editor-annotations-tab.test.tsx +++ b/apps/app/tests/unit/editor-annotations-tab.test.tsx @@ -28,6 +28,7 @@ import { svgBytes, } from '../helpers/editorFixtures' import { LayeredTab } from '../helpers/annotationLayer' +import { addByKeyboard } from '../helpers/addByKeyboard' import { USER, VERSION, @@ -38,7 +39,6 @@ import { sb, store, versionAnswer, - addByKeyboard, } from '../helpers/editorHarness' vi.mock('@/lib/supabase', () => ({ getSupabaseClient: () => ({}) })) diff --git a/apps/app/tests/unit/editor-creation-dialog.test.tsx b/apps/app/tests/unit/editor-creation-dialog.test.tsx index d7da2609..05d3714b 100644 --- a/apps/app/tests/unit/editor-creation-dialog.test.tsx +++ b/apps/app/tests/unit/editor-creation-dialog.test.tsx @@ -29,13 +29,8 @@ import { guardDrawing } from '@/editor/annotations/drawingGuard' import { useLocaleStore } from '@/state/localeStore' import { drawnText, insert, point } from '../helpers/editorFixtures' import { LayeredTab } from '../helpers/annotationLayer' -import { - addByKeyboard, - openReady, - pressAt, - resetStore, - store, -} from '../helpers/editorHarness' +import { addByKeyboard } from '../helpers/addByKeyboard' +import { openReady, pressAt, resetStore, store } from '../helpers/editorHarness' vi.mock('@/lib/supabase', () => ({ getSupabaseClient: () => ({}) })) vi.mock('@faunosteo/supabase', async (orig) => ({ diff --git a/apps/app/tests/unit/editor-keep-alive.test.tsx b/apps/app/tests/unit/editor-keep-alive.test.tsx index 666aff43..c5c18c15 100644 --- a/apps/app/tests/unit/editor-keep-alive.test.tsx +++ b/apps/app/tests/unit/editor-keep-alive.test.tsx @@ -29,6 +29,7 @@ import { insert, point, } from '../helpers/editorFixtures' +import { addByKeyboard } from '../helpers/addByKeyboard' import { baseText, resetStore, @@ -37,7 +38,6 @@ import { store, versionAnswer, pressAt, - addByKeyboard, } from '../helpers/editorHarness' import { testLayer } from '../helpers/findingsHost' import { mountDraft, setWidth } from '../helpers/editorRoute' diff --git a/apps/app/tests/unit/editor-no-loss.test.tsx b/apps/app/tests/unit/editor-no-loss.test.tsx index 583c66f0..50d09789 100644 --- a/apps/app/tests/unit/editor-no-loss.test.tsx +++ b/apps/app/tests/unit/editor-no-loss.test.tsx @@ -12,6 +12,7 @@ import userEvent from '@testing-library/user-event' import { useAuthStore } from '@/state/authStore' import { useLocaleStore } from '@/state/localeStore' import { drawnText, emptyText, insert, point } from '../helpers/editorFixtures' +import { addByKeyboard } from '../helpers/addByKeyboard' import { SHEET, USER, @@ -23,7 +24,6 @@ import { storedCopy, store, sb, - addByKeyboard, } from '../helpers/editorHarness' import { adminAnswer, diff --git a/apps/app/tests/unit/editor-point-edit.test.tsx b/apps/app/tests/unit/editor-point-edit.test.tsx index 4866187a..df50e5ac 100644 --- a/apps/app/tests/unit/editor-point-edit.test.tsx +++ b/apps/app/tests/unit/editor-point-edit.test.tsx @@ -23,6 +23,7 @@ import { point, svgBytes, } from '../helpers/editorFixtures' +import { addByKeyboard } from '../helpers/addByKeyboard' import { USER, VERSION, @@ -32,7 +33,6 @@ import { sb, store, versionAnswer, - addByKeyboard, } from '../helpers/editorHarness' vi.mock('@/lib/supabase', () => ({ getSupabaseClient: () => ({}) })) diff --git a/apps/app/tests/unit/editor-sections.test.tsx b/apps/app/tests/unit/editor-sections.test.tsx index 6c132ddc..739215ef 100644 --- a/apps/app/tests/unit/editor-sections.test.tsx +++ b/apps/app/tests/unit/editor-sections.test.tsx @@ -18,6 +18,7 @@ import { import { targetOfKey } from '@/editor/navigation' import { useLocaleStore } from '@/state/localeStore' import { drawnText, insert, point } from '../helpers/editorFixtures' +import { addByKeyboard } from '../helpers/addByKeyboard' import { baseText, openReady, @@ -25,7 +26,6 @@ import { serverHas, store, pressAt, - addByKeyboard, } from '../helpers/editorHarness' import { mountDraft, setWidth } from '../helpers/editorRoute'