mirror of
https://github.com/bretzel-app/crumbs.git
synced 2026-10-13 04:06:57 +02:00
- Add TipTap WYSIWYG editor (headless @tiptap/core) with StarterKit, TaskList, TaskItem, Link, Placeholder, and tiptap-markdown extensions - Always-visible formatting toolbar with undo/redo, H1-H3, bold, italic, strikethrough, inline code, code block, blockquote, bullet/ordered/task lists, horizontal rule, and link - Raw markdown toggle for power users - Render rich text (HTML) on note cards instead of stripped plain text - Update all e2e tests for TipTap contenteditable editor Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
122 lines
5.4 KiB
TypeScript
122 lines
5.4 KiB
TypeScript
import { test, expect } from './helpers/fixtures.js';
|
|
import type { Page, Locator } from '@playwright/test';
|
|
|
|
/** Run a TipTap command chain via the exposed editor instance on the DOM element */
|
|
async function runTiptapCommand(page: Page, commandFn: string) {
|
|
await page.getByTestId('tiptap-editor').evaluate(
|
|
(el, fn) => {
|
|
const editor = (el as any).__tiptapEditor;
|
|
if (!editor) throw new Error('TipTap editor not found on element');
|
|
new Function('editor', fn)(editor);
|
|
},
|
|
commandFn
|
|
);
|
|
}
|
|
|
|
/** Type content into the TipTap editor via markdown mode (reliable for e2e) */
|
|
async function typeViaMarkdown(page: Page, content: string) {
|
|
await page.getByTestId('markdown-toggle').click();
|
|
await page.getByTestId('note-content-input').fill(content);
|
|
await page.getByTestId('markdown-toggle').click();
|
|
}
|
|
|
|
test.describe('Rich text formatting', () => {
|
|
test('Scenario: Bold shortcut formats selected text in the editor', async ({ authenticatedPage: page }) => {
|
|
// Given the user is editing a new note with content "hello world"
|
|
await page.getByTestId('new-note-btn').click();
|
|
await typeViaMarkdown(page, 'hello world');
|
|
const editor = page.getByTestId('tiptap-editor').locator('.tiptap');
|
|
|
|
// When the user selects "world" and applies bold formatting
|
|
await runTiptapCommand(page, 'editor.chain().focus().setTextSelection({from:7,to:12}).toggleBold().run()');
|
|
|
|
// Then the selected text appears bold in the editor
|
|
await expect(editor.locator('strong')).toHaveText('world');
|
|
|
|
// And the markdown content contains bold syntax
|
|
await page.getByTestId('markdown-toggle').click();
|
|
await expect(page.getByTestId('note-content-input')).toHaveValue('hello **world**');
|
|
});
|
|
|
|
test('Scenario: Italic shortcut formats selected text in the editor', async ({ authenticatedPage: page }) => {
|
|
// Given the user is editing a new note with content "hello world"
|
|
await page.getByTestId('new-note-btn').click();
|
|
await typeViaMarkdown(page, 'hello world');
|
|
const editor = page.getByTestId('tiptap-editor').locator('.tiptap');
|
|
|
|
// When the user selects "world" and applies italic formatting
|
|
await runTiptapCommand(page, 'editor.chain().focus().setTextSelection({from:7,to:12}).toggleItalic().run()');
|
|
|
|
// Then the selected text appears italic in the editor
|
|
await expect(editor.locator('em')).toHaveText('world');
|
|
});
|
|
|
|
test('Scenario: Formatting toolbar applies bold to selected text', async ({ authenticatedPage: page }) => {
|
|
// Given the user is editing a note
|
|
await page.getByTestId('new-note-btn').click();
|
|
await typeViaMarkdown(page, 'hello world');
|
|
|
|
// When the user selects "world" and clicks the bold button
|
|
await runTiptapCommand(page, 'editor.chain().focus().setTextSelection({from:7,to:12}).run()');
|
|
await page.getByTestId('format-bold').click();
|
|
|
|
// Then the selected text appears bold
|
|
const editor = page.getByTestId('tiptap-editor').locator('.tiptap');
|
|
await expect(editor.locator('strong')).toHaveText('world');
|
|
});
|
|
|
|
test('Scenario: Formatting toolbar is always visible when editing', async ({ authenticatedPage: page }) => {
|
|
// When the user opens a new note
|
|
await page.getByTestId('new-note-btn').click();
|
|
|
|
// Then the formatting toolbar is visible immediately
|
|
await expect(page.getByTestId('formatting-toolbar')).toBeVisible();
|
|
});
|
|
|
|
test('Scenario: Inline code shortcut wraps selected text', async ({ authenticatedPage: page }) => {
|
|
// Given the user is editing a note with content "use npm install"
|
|
await page.getByTestId('new-note-btn').click();
|
|
await typeViaMarkdown(page, 'use npm install');
|
|
const editor = page.getByTestId('tiptap-editor').locator('.tiptap');
|
|
|
|
// When the user selects "npm install" and applies code formatting
|
|
await runTiptapCommand(page, 'editor.chain().focus().setTextSelection({from:5,to:16}).toggleCode().run()');
|
|
|
|
// Then the selected text appears as inline code
|
|
await expect(editor.locator('code')).toHaveText('npm install');
|
|
});
|
|
|
|
test('Scenario: Existing note shows rich text in TipTap editor', async ({ authenticatedPage: page }) => {
|
|
// Given a note with bold markdown content exists
|
|
await page.getByTestId('new-note-btn').click();
|
|
await page.getByTestId('note-title-input').fill('Rich Text Note');
|
|
await typeViaMarkdown(page, 'Hello **bold** world');
|
|
await page.getByTestId('close-editor-btn').click();
|
|
|
|
// When the user reopens the note
|
|
await page.getByTestId('note-card').click();
|
|
|
|
// Then the content is rendered as rich text in the TipTap editor
|
|
await expect(page.getByTestId('tiptap-editor')).toBeVisible();
|
|
await expect(page.getByTestId('tiptap-editor').locator('strong')).toHaveText('bold');
|
|
});
|
|
|
|
test('Scenario: Markdown toggle shows raw markdown content', async ({ authenticatedPage: page }) => {
|
|
// Given the user is editing a note with bold content
|
|
await page.getByTestId('new-note-btn').click();
|
|
await typeViaMarkdown(page, 'Hello **bold** world');
|
|
|
|
// Verify the rich text renders correctly first
|
|
const editor = page.getByTestId('tiptap-editor').locator('.tiptap');
|
|
await expect(editor.locator('strong')).toHaveText('bold');
|
|
|
|
// When the user toggles markdown mode
|
|
await page.getByTestId('markdown-toggle').click();
|
|
|
|
// Then the raw markdown textarea is shown with the markdown source
|
|
await expect(page.getByTestId('note-content-input')).toBeVisible();
|
|
await expect(page.getByTestId('tiptap-editor')).not.toBeVisible();
|
|
await expect(page.getByTestId('note-content-input')).toHaveValue('Hello **bold** world');
|
|
});
|
|
});
|