guanghu/tests/smoke/quick-open-create-note.spec.ts
冰朔 8739805f99
Some checks failed
Auto-update PR branches / Update open PR branches (push) Has been cancelled
CI / Frontend Static Quality Checks (push) Has been cancelled
CI / Frontend Tests & Coverage (push) Has been cancelled
CI / Rust Tests & Quality Checks (push) Has been cancelled
CI / Linux build verification (push) Has been cancelled
Release (Alpha) / Compute alpha version (push) Has been cancelled
Release (Alpha) / Build release artifacts (push) Has been cancelled
Release (Alpha) / GitHub Release (alpha) (push) Has been cancelled
Release (Alpha) / Update docs and release pages (push) Has been cancelled
Deploy docs / Build VitePress site (push) Has been cancelled
Deploy docs / Deploy to GitHub Pages (push) Has been cancelled
光湖开源源码快照 · Tolaria AGPL 分叉基线 · 独立更新链
2026-07-05 17:45:16 +08:00

53 lines
1.7 KiB
TypeScript

import fs from 'fs'
import path from 'path'
import { test, expect } from '@playwright/test'
import {
createFixtureVaultCopy,
openFixtureVaultDesktopHarness,
removeFixtureVaultCopy,
} from '../helpers/fixtureVault'
import { dispatchShortcutEvent } from './testBridge'
let tempVaultDir: string
test.beforeEach(() => {
tempVaultDir = createFixtureVaultCopy()
})
test.afterEach(() => {
removeFixtureVaultCopy(tempVaultDir)
})
async function openNoteWithCmdO(page: import('@playwright/test').Page): Promise<void> {
await dispatchShortcutEvent(page, {
key: 'o',
code: 'KeyO',
ctrlKey: false,
metaKey: true,
shiftKey: false,
altKey: false,
bubbles: true,
cancelable: true,
})
await expect(page.getByTestId('quick-open-palette')).toBeVisible({ timeout: 5_000 })
}
test('quick open creates a note when the typed title has no matches @smoke', async ({ page }) => {
const title = 'New Research Brief'
const notePath = path.join(tempVaultDir, 'new-research-brief.md')
await openFixtureVaultDesktopHarness(page, tempVaultDir)
await openNoteWithCmdO(page)
await page.locator('input[placeholder="Search notes..."]').fill(title)
await expect(page.getByRole('button', { name: `Create note "${title}"` })).toBeVisible()
await page.keyboard.press('Enter')
await expect(page.getByTestId('quick-open-palette')).not.toBeVisible({ timeout: 5_000 })
await expect(page.getByTestId('breadcrumb-filename-trigger')).toContainText('new-research-brief', { timeout: 5_000 })
await expect.poll(() => fs.existsSync(notePath), { timeout: 5_000 }).toBe(true)
const content = fs.readFileSync(notePath, 'utf8')
expect(content).toContain(`title: ${title}`)
expect(content).toContain('type: Note')
})