mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-06-22 14:51:45 +00:00
de157cb87b
Server (172 tests): - journeyService unit tests (87 tests): CRUD, access control, sync, photos, contributors - journeyShareService unit tests (20 tests): share links, token validation, public access - journey integration tests (45 tests): all API routes, auth, permissions, edge cases - Test helpers: journey factories, RESET_TABLES updated Client (340+ tests): - journeyStore tests (15 tests): all store actions and state management - JourneyPage tests (20 tests): frontpage, create flow, suggestions, navigation - JourneyDetailPage tests (94 tests): all sub-components, entry editor, settings, share links, contributors, gallery, map, trip linking - JourneyPublicPage tests (18 tests): public view, tabs, restricted access - JourneyBookPDF tests (6 tests): PDF generation - BottomNav tests (9 tests): profile sheet, navigation - PhotoLightbox tests (8 tests): keyboard nav, counter - JourneyMap tests (12 tests): markers, polylines, zoom - Component tests: moodConfig, stripMarkdown, MarkdownToolbar, JournalBody, MobileTopHeader - DashboardPage tests (32 tests): spotlight card, quick actions, widget settings SonarQube: exclude unused MemoriesPanel from coverage (dead code, moved to Journey)
73 lines
3.0 KiB
TypeScript
73 lines
3.0 KiB
TypeScript
// FE-COMP-MDTOOLBAR-001 to FE-COMP-MDTOOLBAR-006
|
|
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import { render, screen, fireEvent } from '../../../tests/helpers/render';
|
|
import MarkdownToolbar from './MarkdownToolbar';
|
|
import React from 'react';
|
|
|
|
function createTextareaRef(value = '', selectionStart = 0, selectionEnd = 0) {
|
|
const textarea = document.createElement('textarea');
|
|
textarea.value = value;
|
|
textarea.selectionStart = selectionStart;
|
|
textarea.selectionEnd = selectionEnd;
|
|
textarea.focus = vi.fn();
|
|
textarea.setSelectionRange = vi.fn();
|
|
return { current: textarea } as React.RefObject<HTMLTextAreaElement>;
|
|
}
|
|
|
|
describe('MarkdownToolbar', () => {
|
|
let onUpdate: ReturnType<typeof vi.fn>;
|
|
|
|
beforeEach(() => {
|
|
onUpdate = vi.fn();
|
|
});
|
|
|
|
it('FE-COMP-MDTOOLBAR-001: renders all 8 toolbar buttons', () => {
|
|
const ref = createTextareaRef();
|
|
render(<MarkdownToolbar textareaRef={ref} onUpdate={onUpdate} />);
|
|
const buttons = screen.getAllByRole('button');
|
|
expect(buttons).toHaveLength(8);
|
|
});
|
|
|
|
it('FE-COMP-MDTOOLBAR-002: buttons have correct title labels', () => {
|
|
const ref = createTextareaRef();
|
|
render(<MarkdownToolbar textareaRef={ref} onUpdate={onUpdate} />);
|
|
expect(screen.getByTitle('Bold')).toBeInTheDocument();
|
|
expect(screen.getByTitle('Italic')).toBeInTheDocument();
|
|
expect(screen.getByTitle('Link')).toBeInTheDocument();
|
|
expect(screen.getByTitle('Heading')).toBeInTheDocument();
|
|
expect(screen.getByTitle('Quote')).toBeInTheDocument();
|
|
expect(screen.getByTitle('List')).toBeInTheDocument();
|
|
expect(screen.getByTitle('Ordered')).toBeInTheDocument();
|
|
expect(screen.getByTitle('Divider')).toBeInTheDocument();
|
|
});
|
|
|
|
it('FE-COMP-MDTOOLBAR-003: bold button wraps selected text with **', () => {
|
|
const ref = createTextareaRef('hello world', 6, 11);
|
|
render(<MarkdownToolbar textareaRef={ref} onUpdate={onUpdate} />);
|
|
fireEvent.click(screen.getByTitle('Bold'));
|
|
expect(onUpdate).toHaveBeenCalledWith('hello **world**');
|
|
});
|
|
|
|
it('FE-COMP-MDTOOLBAR-004: italic button wraps selected text with _', () => {
|
|
const ref = createTextareaRef('hello world', 6, 11);
|
|
render(<MarkdownToolbar textareaRef={ref} onUpdate={onUpdate} />);
|
|
fireEvent.click(screen.getByTitle('Italic'));
|
|
expect(onUpdate).toHaveBeenCalledWith('hello _world_');
|
|
});
|
|
|
|
it('FE-COMP-MDTOOLBAR-005: link button wraps selected text as markdown link', () => {
|
|
const ref = createTextareaRef('click me', 0, 8);
|
|
render(<MarkdownToolbar textareaRef={ref} onUpdate={onUpdate} />);
|
|
fireEvent.click(screen.getByTitle('Link'));
|
|
expect(onUpdate).toHaveBeenCalledWith('[click me](url)');
|
|
});
|
|
|
|
it('FE-COMP-MDTOOLBAR-006: heading button inserts line prefix', () => {
|
|
const ref = createTextareaRef('my title', 0, 0);
|
|
render(<MarkdownToolbar textareaRef={ref} onUpdate={onUpdate} />);
|
|
fireEvent.click(screen.getByTitle('Heading'));
|
|
expect(onUpdate).toHaveBeenCalledWith('## my title');
|
|
});
|
|
});
|