Skip to content

Test Coverage Phase 1b: Notification, Lifecycle, and Edge Case Tests #234

@schuyler

Description

@schuyler

Overview

Follow-up to #197 (Phase 1 unit tests). These tests address gaps discovered during Phase 1 implementation and focus on integration points and edge cases that can still run headless in CI.

Target: v3000.0.x

New Test Suites

1. Notification/Observer Integration Tests

Test that components respond correctly to preference changes (not just that preferences persist):

- testRendererRespondsToStyleChange       // MPRenderer updates when theme changes
- testHighlighterRespondsToFontChange     // Editor re-highlights on font change
- testPreferenceChangeCoalescence         // Rapid changes don't cause thrashing
- testThemeChangeNotification             // Verify observers receive theme changes
- testFontSizeChangeNotification          // Font changes propagate correctly

Approach:

  • Register mock observers for NSNotificationCenter
  • Trigger preference changes
  • Verify callbacks fire with correct data
  • Test that dependent components update state

2. MPDocument Lifecycle Tests

Test document state management beyond basic I/O:

- testDocumentDirtyFlagAfterEdit
- testDocumentRevertToSaved
- testDocumentEncodingDetection           // Auto-detect UTF-8 vs Latin-1
- testDocumentWithNoExtension
- testSaveWithFileConflict                // File modified externally
- testOpenFileDeletedDuringEdit           // File removed while open

Approach:

  • Create MPDocument instances programmatically
  • Manipulate document state
  • Verify flags and behaviors

3. Renderer Edge Cases

Additional renderer scenarios discovered during Phase 1:

- testRendererWithNilDataSource
- testRendererWithEmptyMarkdown
- testRendererExtensionCombinations       // Tables + footnotes + strikethrough
- testRendererWithMalformedHTMLInCodeBlocks
- testRenderCancellation
- testConcurrentRenderRequests

4. HGMarkdownHighlighter Coverage Gaps

The highlighter has 75% coverage but some paths are untested:

- testHighlighterWithLargeDocument        // Performance/stress test
- testHighlighterStyleParsingErrors       // Error callback (0% covered)
- testHighlighterTextViewDidChange        // 0% covered currently
- testHighlighterScrollHandler            // Partial coverage

5. Image Handling in Exports

- testExportWithEmbeddedImages            // Base64 images render correctly
- testExportWithLinkedImages              // External image URLs preserved
- testInvalidImageURLs                    // Graceful handling of broken images

Out of Scope (Requires GUI)

  • PDF export (needs print subsystem)
  • Clipboard operations (needs pasteboard)
  • Live preview synchronization (needs WebView display)
  • Autosave (tightly coupled to AppKit)

Success Criteria

  • All new tests pass
  • Tests run headless in CI
  • No flaky tests
  • Coverage improvement measurable (target: 50%+ overall)

Priority

  1. High: Notification/observer tests - this is where integration bugs hide
  2. Medium: Document lifecycle tests
  3. Medium: Renderer edge cases
  4. Lower: Highlighter gaps (already decent coverage)

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions