Repository navigation
Closed
Description
Problem Statement
While individual components are tested (Issues #151, #152), the complete user flow from typing "@" to inserting a node reference is untested. Integration bugs between ContentEditableController, NodeAutocomplete, and EventBus could break the feature silently.
Untested Flow:
- User types "@test" in editor
- Autocomplete modal appears at cursor
- Results filter as user types
- User selects with Enter
- Reference inserted in markdown format:
[Title](nodespace://id) - EventBus emits 'nodeReferenceSelected' event
- Modal closes and focus returns to editor
Why This Matters
Real Bugs This Would Catch:
- Autocomplete doesn't appear when "@" typed
- Results don't filter with query updates
- Enter key creates new node instead of selecting reference
- Reference inserted in wrong format
- Focus lost after selection
- EventBus events not fired
Current Risk: Full integration chain has never been automatically verified.
Files Involved
Components:
src/lib/design/components/contentEditableController.ts(trigger detection)src/lib/design/components/base-node.svelte(autocomplete integration)src/lib/components/ui/node-autocomplete/node-autocomplete.sveltesrc/lib/services/eventBus.ts
Test File:
src/tests/integration/autocomplete-flow.test.ts
Acceptance Criteria
Create integration test file with 12+ test cases:
Complete Flow Tests
-
Trigger Detection (3 tests)
- Typing "@" shows autocomplete
- Typing " @" (space before) shows autocomplete
- Typing "text@" (mid-word) doesn't show autocomplete
-
Query Filtering (3 tests)
-
Selection Flow (4 tests)
- Enter key inserts reference and closes modal
- Click on result inserts reference
- Escape closes without inserting
- Typing continues updates query
-
EventBus Integration (2 tests)
- 'triggerDetected' event fired when "@" typed
- 'nodeReferenceSelected' event fired on selection
- Events contain correct nodeId and title
-
Focus Management (2 tests)
- Focus stays in editor while modal open
- Focus returns to editor after selection
- Cursor positioned correctly after insertion
-
Content Integrity (2 tests)
- Reference inserted in correct markdown format
- Existing content preserved around insertion
- Undo/redo works correctly
Implementation Guide
// src/tests/integration/autocomplete-flow.test.ts
import { describe, it, expect, beforeEach, vi } from 'vitest';
import { render, screen, fireEvent } from '@testing-library/svelte';
import userEvent from '@testing-library/user-event';
import BaseNode from '$lib/design/components/base-node.svelte';
import { eventBus } from '$lib/services/eventBus';
describe('Node Reference Autocomplete - Complete Flow', () => {
beforeEach(() => {
eventBus.reset();
});
describe('Trigger Detection', () => {
it('should show autocomplete when @ typed', async () => {
const user = userEvent.setup();
const { container } = render(BaseNode, {
props: {
nodeId: 'test-node',
nodeType: 'text',
content: '',
autoFocus: true
}
});
const editor = container.querySelector('[contenteditable]');
expect(editor).toBeInTheDocument();
// Type "@"
await user.type(editor, '@');
// Autocomplete should appear
expect(screen.getByRole('listbox')).toBeInTheDocument();
expect(screen.getByLabelText('Node reference autocomplete')).toBeInTheDocument();
});
it('should filter results as user types query', async () => {
const user = userEvent.setup();
const { container } = render(BaseNode, {
props: {
nodeId: 'test-node',
nodeType: 'text',
content: '',
autoFocus: true
}
});
const editor = container.querySelector('[contenteditable]');
// Type "@test"
await user.type(editor, '@test');
// Results should be filtered
const listbox = screen.getByRole('listbox');
expect(listbox).toBeInTheDocument();
// Should show filtered results (mock data contains "Test Node")
expect(screen.getByText(/Test Node/i)).toBeInTheDocument();
});
});
describe('Selection and Insertion', () => {
it('should insert reference when Enter pressed', async () => {
const user = userEvent.setup();
const { container } = render(BaseNode, {
props: {
nodeId: 'test-node',
nodeType: 'text',
content: '',
autoFocus: true
}
});
const editor = container.querySelector('[contenteditable]');
// Type "@" to trigger
await user.type(editor, '@');
// Wait for autocomplete to appear
expect(screen.getByRole('listbox')).toBeInTheDocument();
// Press Enter to select first result
await user.keyboard('{Enter}');
// Reference should be inserted in markdown format
const content = editor.textContent;
expect(content).toMatch(/\[.*\]\(nodespace:\/\/.*\)/);
});
it('should close modal after selection', async () => {
const user = userEvent.setup();
const { container } = render(BaseNode, {
props: {
nodeId: 'test-node',
nodeType: 'text',
content: '',
autoFocus: true
}
});
const editor = container.querySelector('[contenteditable]');
await user.type(editor, '@');
expect(screen.getByRole('listbox')).toBeInTheDocument();
await user.keyboard('{Enter}');
// Modal should close
expect(screen.queryByRole('listbox')).not.toBeInTheDocument();
});
it('should close without inserting on Escape', async () => {
const user = userEvent.setup();
const { container } = render(BaseNode, {
props: {
nodeId: 'test-node',
nodeType: 'text',
content: 'Before @',
autoFocus: true
}
});
const editor = container.querySelector('[contenteditable]');
await user.type(editor, '@');
expect(screen.getByRole('listbox')).toBeInTheDocument();
await user.keyboard('{Escape}');
// Modal closed, content unchanged
expect(screen.queryByRole('listbox')).not.toBeInTheDocument();
expect(editor.textContent).toBe('Before @');
});
});
describe('EventBus Integration', () => {
it('should emit triggerDetected event when @ typed', async () => {
const user = userEvent.setup();
const eventHandler = vi.fn();
eventBus.subscribe('trigger:detected', eventHandler);
const { container } = render(BaseNode, {
props: {
nodeId: 'test-node',
nodeType: 'text',
content: '',
autoFocus: true
}
});
const editor = container.querySelector('[contenteditable]');
await user.type(editor, '@');
expect(eventHandler).toHaveBeenCalledWith(
expect.objectContaining({
type: 'trigger:detected',
nodeId: 'test-node'
})
);
});
it('should emit nodeReferenceSelected event on selection', async () => {
const user = userEvent.setup();
const eventHandler = vi.fn();
eventBus.subscribe('node:reference-selected', eventHandler);
const { container } = render(BaseNode, {
props: {
nodeId: 'test-node',
nodeType: 'text',
content: '',
autoFocus: true
}
});
const editor = container.querySelector('[contenteditable]');
await user.type(editor, '@');
await user.keyboard('{Enter}');
expect(eventHandler).toHaveBeenCalledWith(
expect.objectContaining({
type: 'node:reference-selected',
nodeId: expect.any(String),
nodeTitle: expect.any(String)
})
);
});
});
describe('Focus Management', () => {
it('should maintain editor focus during autocomplete', async () => {
const user = userEvent.setup();
const { container } = render(BaseNode, {
props: {
nodeId: 'test-node',
nodeType: 'text',
content: '',
autoFocus: true
}
});
const editor = container.querySelector('[contenteditable]');
await user.type(editor, '@');
// Autocomplete visible but editor still focused
expect(screen.getByRole('listbox')).toBeInTheDocument();
expect(document.activeElement).toBe(editor);
});
it('should return focus to editor after selection', async () => {
const user = userEvent.setup();
const { container } = render(BaseNode, {
props: {
nodeId: 'test-node',
nodeType: 'text',
content: '',
autoFocus: true
}
});
const editor = container.querySelector('[contenteditable]');
await user.type(editor, '@');
await user.keyboard('{Enter}');
// Focus back in editor
expect(document.activeElement).toBe(editor);
});
});
});Dependencies
Requires:
- Issue Set up Svelte Component Testing Infrastructure #151: Testing infrastructure
- Issue Add comprehensive event tests for NodeAutocomplete component #152: NodeAutocomplete tests
Blocks:
- Phase 3 advanced tests (Issues Svelte frontend renders with placeholder panels #7, Development server works with hot reload #8)
Definition of Done
- 12+ integration test cases passing
- Complete flow tested: trigger → filter → select → insert
- EventBus events verified
- Focus management verified
- Content integrity verified
- Tests run with
bun run test
Estimated Effort
4-5 hours - Complex integration testing with multiple components
Priority
High - Critical user workflow must be verified
Activity
Add comprehensive end-to-end integration tests for node reference aut…
Add comprehensive node creation event chain integration tests (closes #…
Add comprehensive node creation event chain integration tests (closes #…
Add comprehensive end-to-end integration tests for node reference aut…
Add comprehensive node creation event chain integration tests (closes #…
Add comprehensive end-to-end integration tests for node reference aut…
Add comprehensive node creation event chain integration tests (closes #…
Add comprehensive end-to-end integration tests for node reference aut…
Add comprehensive node creation event chain integration tests (closes #…