|
| 1 | +import { test, expect, type Browser, type Page } from "@playwright/test"; |
| 2 | +import path from "path"; |
| 3 | +import type { ChildProcess } from "child_process"; |
| 4 | +import { |
| 5 | + createTestVault, |
| 6 | + cleanTestVault, |
| 7 | + launchObsidian, |
| 8 | +} from "../helpers/obsidian-setup"; |
| 9 | +import { |
| 10 | + ensureActiveEditor, |
| 11 | + executeCommandViaPalette, |
| 12 | +} from "../helpers/commands"; |
| 13 | +import { findFilesByPrefix, readFileContent } from "../helpers/vault"; |
| 14 | +import { |
| 15 | + waitForModal, |
| 16 | + selectNodeType, |
| 17 | + fillNodeContent, |
| 18 | + confirmModal, |
| 19 | +} from "../helpers/modal"; |
| 20 | +import { captureStep } from "../helpers/screenshots"; |
| 21 | + |
| 22 | +const VAULT_PATH = path.join(__dirname, "..", "test-vault-node-creation"); |
| 23 | + |
| 24 | +let browser: Browser; |
| 25 | +let page: Page; |
| 26 | +let obsidianProcess: ChildProcess; |
| 27 | + |
| 28 | +test.beforeAll(async () => { |
| 29 | + createTestVault(VAULT_PATH); |
| 30 | + const launched = await launchObsidian(VAULT_PATH); |
| 31 | + browser = launched.browser; |
| 32 | + page = launched.page; |
| 33 | + obsidianProcess = launched.obsidianProcess; |
| 34 | + |
| 35 | + // Wait for plugins to initialize |
| 36 | + await page.waitForTimeout(5_000); |
| 37 | +}); |
| 38 | + |
| 39 | +test.afterAll(async () => { |
| 40 | + if (browser) { |
| 41 | + await browser.close(); |
| 42 | + } |
| 43 | + if (obsidianProcess) { |
| 44 | + obsidianProcess.kill(); |
| 45 | + } |
| 46 | + cleanTestVault(VAULT_PATH); |
| 47 | +}); |
| 48 | + |
| 49 | +test("Create a Question node via command palette", async () => { |
| 50 | + await ensureActiveEditor(page); |
| 51 | + |
| 52 | + await executeCommandViaPalette( |
| 53 | + page, |
| 54 | + "Discourse Graph: Create discourse node", |
| 55 | + ); |
| 56 | + |
| 57 | + await waitForModal(page); |
| 58 | + await captureStep(page, "node-creation", "01-modal-open"); |
| 59 | + |
| 60 | + await selectNodeType(page, "Question"); |
| 61 | + await fillNodeContent(page, `What is discourse graph testing ${Date.now()}`); |
| 62 | + await captureStep(page, "node-creation", "02-modal-filled"); |
| 63 | + |
| 64 | + await confirmModal(page); |
| 65 | + await captureStep(page, "node-creation", "03-node-created"); |
| 66 | + |
| 67 | + // Verify file was created with correct prefix |
| 68 | + const files = await findFilesByPrefix(page, "QUE -"); |
| 69 | + expect(files.length).toBeGreaterThan(0); |
| 70 | + |
| 71 | + // Verify frontmatter contains nodeTypeId |
| 72 | + const content = await readFileContent(page, files[0]!); |
| 73 | + if (content) { |
| 74 | + expect(content).toContain("nodeTypeId"); |
| 75 | + } |
| 76 | +}); |
0 commit comments