fix: allow note drops to insert wikilinks

This commit is contained in:
lucaronin
2026-04-26 18:15:22 +02:00
parent 63877e61ec
commit 1d546dde3d
3 changed files with 36 additions and 1 deletions

View File

@@ -70,6 +70,7 @@ describe('NoteDropTarget', () => {
const dragStartData = createMockDataTransfer()
fireEvent.dragStart(screen.getByTestId(`draggable-note:${NOTE_PATH}`), { dataTransfer: dragStartData })
expect(dragStartData.effectAllowed).toBe('linkMove')
const target = screen.getByText('CircleCI Series').parentElement
expect(target).not.toBeNull()

View File

@@ -5,7 +5,7 @@ let activeDraggedNotePath: string | null = null
export function writeDraggedNotePath(event: DragEvent<HTMLElement>, notePath: string): void {
activeDraggedNotePath = notePath
event.dataTransfer.effectAllowed = 'move'
event.dataTransfer.effectAllowed = 'linkMove'
event.dataTransfer.setData(NOTE_DRAG_MIME, notePath)
event.dataTransfer.setData('text/plain', notePath)
}

View File

@@ -0,0 +1,34 @@
import { test, expect, type Page } from '@playwright/test'
import path from 'path'
import { createFixtureVaultCopy, openFixtureVault, removeFixtureVaultCopy } from '../helpers/fixtureVault'
let tempVaultDir: string
test.beforeEach(async ({ page }) => {
tempVaultDir = createFixtureVaultCopy()
await openFixtureVault(page, tempVaultDir)
})
test.afterEach(async () => {
removeFixtureVaultCopy(tempVaultDir)
})
async function openNote(page: Page, title: string) {
await page.getByTestId('note-list-container').getByText(title, { exact: true }).click()
await expect(page.getByRole('heading', { name: title, level: 1 })).toBeVisible({ timeout: 5_000 })
}
test('dragging a note into the rich editor inserts a canonical wikilink', async ({ page }) => {
await openNote(page, 'Note B')
const editor = page.locator('.bn-editor')
await expect(editor).toBeVisible({ timeout: 5_000 })
await editor.locator('p').last().click()
await page.keyboard.press('End')
await page.keyboard.press('Enter')
const draggedNotePath = path.join(tempVaultDir, 'project', 'alpha-project.md')
await page.getByTestId(`draggable-note:${draggedNotePath}`).dragTo(editor)
await expect(editor.locator('.wikilink[data-target="project/alpha-project"]')).toBeVisible({ timeout: 5_000 })
})