test: simplify main entrypoint setup
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { describe, expect, it, vi, beforeEach } from 'vitest'
|
||||
import { describe, expect, it, vi, beforeAll, beforeEach } from 'vitest'
|
||||
import { createElement, type ReactNode } from 'react'
|
||||
|
||||
const MAIN_ENTRYPOINT_TEST_TIMEOUT_MS = 30_000
|
||||
|
||||
type ReactRootErrorInfo = { componentStack?: string }
|
||||
type ReactRootOptions = {
|
||||
onCaughtError?: (error: unknown, errorInfo: ReactRootErrorInfo) => void
|
||||
@@ -52,15 +54,17 @@ function rootOptions(): ReactRootOptions {
|
||||
}
|
||||
|
||||
describe('main entrypoint', () => {
|
||||
beforeEach(() => {
|
||||
vi.resetModules()
|
||||
beforeAll(async () => {
|
||||
vi.clearAllMocks()
|
||||
document.body.innerHTML = '<div id="root"></div>'
|
||||
await importEntrypoint()
|
||||
}, MAIN_ENTRYPOINT_TEST_TIMEOUT_MS)
|
||||
|
||||
beforeEach(() => {
|
||||
mocks.sentryHandler.mockClear()
|
||||
})
|
||||
|
||||
it('captures React root errors through Sentry with component stack context', async () => {
|
||||
await importEntrypoint()
|
||||
|
||||
it('captures React root errors through Sentry with component stack context', () => {
|
||||
expect(mocks.reactErrorHandler).toHaveBeenCalledOnce()
|
||||
expect(mocks.createRoot).toHaveBeenCalledWith(
|
||||
document.getElementById('root'),
|
||||
@@ -77,9 +81,7 @@ describe('main entrypoint', () => {
|
||||
expect(mocks.sentryHandler).toHaveBeenCalledWith(error, { componentStack: '\n in App' })
|
||||
})
|
||||
|
||||
it('normalizes missing React component stacks before handing errors to Sentry', async () => {
|
||||
await importEntrypoint()
|
||||
|
||||
it('normalizes missing React component stacks before handing errors to Sentry', () => {
|
||||
const error = new Error('recoverable render error')
|
||||
rootOptions().onRecoverableError?.(error, {})
|
||||
|
||||
|
||||
58
tests/smoke/arrow-ligatures.spec.ts
Normal file
58
tests/smoke/arrow-ligatures.spec.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { test, expect, type Page } from '@playwright/test'
|
||||
import { executeCommand, openCommandPalette } from './helpers'
|
||||
|
||||
const AI_AGENTS_ONBOARDING_DISMISSED_KEY = 'tolaria:ai-agents-onboarding-dismissed'
|
||||
const CLAUDE_CODE_ONBOARDING_DISMISSED_KEY = 'tolaria:claude-code-onboarding-dismissed'
|
||||
|
||||
async function createNote(page: Page) {
|
||||
await page.waitForSelector('[data-testid="sidebar-top-nav"]', { timeout: 10000 })
|
||||
await page.locator('button[title="Create new note"]').first().click()
|
||||
await expect(page.getByTestId('breadcrumb-filename-trigger')).toContainText(/untitled-note-\d+/i, {
|
||||
timeout: 5_000,
|
||||
})
|
||||
await expect(page.locator('.bn-editor')).toBeVisible({ timeout: 5_000 })
|
||||
await page.waitForTimeout(500)
|
||||
await page.keyboard.press('Enter')
|
||||
}
|
||||
|
||||
async function toggleRawEditor(page: Page) {
|
||||
await openCommandPalette(page)
|
||||
await executeCommand(page, 'Toggle Raw')
|
||||
}
|
||||
|
||||
async function getRawEditorContent(page: Page) {
|
||||
return page.locator('[data-testid="raw-editor-codemirror"]').evaluate((element) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const view = (element as any).__cmView
|
||||
return view?.state?.doc?.toString?.() ?? element.textContent ?? ''
|
||||
})
|
||||
}
|
||||
|
||||
test('typing keeps arrow ligatures aligned between rich and raw editors', async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1600, height: 900 })
|
||||
await page.addInitScript(({ aiAgentsKey, claudeKey }: { aiAgentsKey: string; claudeKey: string }) => {
|
||||
localStorage.clear()
|
||||
localStorage.setItem(aiAgentsKey, '1')
|
||||
localStorage.setItem(claudeKey, '1')
|
||||
}, {
|
||||
aiAgentsKey: AI_AGENTS_ONBOARDING_DISMISSED_KEY,
|
||||
claudeKey: CLAUDE_CODE_ONBOARDING_DISMISSED_KEY,
|
||||
})
|
||||
await page.goto(process.env.BASE_URL ?? 'http://localhost:5201', { waitUntil: 'domcontentloaded' })
|
||||
|
||||
await createNote(page)
|
||||
await page.keyboard.type('-> <- <-> \\<->')
|
||||
|
||||
await expect(page.locator('.bn-editor')).toContainText('→ ← ↔ <->', { timeout: 5_000 })
|
||||
|
||||
await toggleRawEditor(page)
|
||||
await expect(page.locator('[data-testid="raw-editor-codemirror"]')).toBeVisible({ timeout: 5_000 })
|
||||
await expect.poll(() => getRawEditorContent(page)).toContain('→ ← ↔ <->')
|
||||
|
||||
await page.locator('[data-testid="raw-editor-codemirror"]').click()
|
||||
await page.keyboard.type('\n-> <- <-> \\<->')
|
||||
await expect.poll(() => getRawEditorContent(page)).toMatch(/→ ← ↔ <->\s+→ ← ↔ <->/u)
|
||||
|
||||
await toggleRawEditor(page)
|
||||
await expect(page.locator('.bn-editor')).toContainText('→ ← ↔ <->', { timeout: 5_000 })
|
||||
})
|
||||
Reference in New Issue
Block a user