Skip to content

Test Coverage Phase 3: XCUITest Implementation #199

@schuyler

Description

@schuyler

Overview

Phase 3 of the test coverage improvement plan from plans/xcuitest.md. Targeted UI tests for critical user workflows.

Target: v3000.1.x or v3001.0.0 (can be written in Swift as part of port)

Depends on:

XCUITest Target Setup

New Target: MacDownUITests

Configuration:

  • Test target with host application
  • Accessibility identifiers added to key UI elements
  • Test data fixtures (sample markdown files)

Critical Path Tests (8-10 tests max)

Keep the UI test suite small and focused on high-value scenarios.

BasicWorkflowUITests.swift

class BasicWorkflowUITests: XCTestCase {
    func testCreateEditExportWorkflow() {
        // New doc → type markdown → preview updates → export
    }
    
    func testFileOpenSaveWorkflow() {
        // Open file → modify → save → verify disk
    }
    
    func testPreviewUpdatesInRealTime() {
        // Type in editor → preview renders
    }
}

ScrollSyncUITests.swift

class ScrollSyncUITests: XCTestCase {
    func testScrollEditorUpdatesPreview() {
        // Issue #39: Scroll editor → preview follows
    }
    
    func testScrollSyncWithImages() {
        // Long doc with images → scroll stays synced
    }
    
    func testScrollPositionRestoration() {
        // Scroll → close → reopen → position restored
    }
}

ExportUITests.swift

class ExportUITests: XCTestCase {
    func testExportHTML() {
        // Menu → Export → file created
    }
    
    func testCopyAsHTML() {
        // Menu → Copy as HTML → clipboard has HTML
    }
}

PreferencesUITests.swift

class PreferencesUITests: XCTestCase {
    func testThemeChange() {
        // Prefs → change theme → preview updates
    }
    
    func testSyntaxHighlightingToggle() {
        // Prefs → toggle highlighting → preview changes
    }
}

Page Object Pattern

class EditorPage {
    let app: XCUIApplication
    var textView: XCUIElement { app.textViews["markdown-editor"] }
    
    func typeMarkdown(_ text: String) {
        textView.click()
        textView.typeText(text)
    }
}

class PreviewPage {
    let app: XCUIApplication
    var webView: XCUIElement { app.webViews["preview-pane"] }
    
    func waitForRender() {
        webView.waitForExistence(timeout: 2)
    }
    
    func containsText(_ text: String) -> Bool {
        return webView.staticTexts[text].exists
    }
}

Test Data Fixtures

MacDownUITests/
  Fixtures/
    simple.md
    with-images.md
    long-document.md
    math-equations.md

Accessibility Identifiers Required

Add to codebase before XCUITests:

  • markdown-editor on MPEditorView
  • preview-pane on WebView/WKWebView
  • document-window on main window
  • Menu item identifiers as needed

Success Criteria

  • XCUITest target created and builds
  • 8-10 focused UI tests implemented
  • Tests complete in < 10 minutes
  • Test flakiness < 5%
  • Page objects provide reusable abstractions

Risks and Mitigations

Risk Mitigation
XCUITest flakiness Use waitForExistence(), generous timeouts, retry logic
WebView testing unreliable Ensure WKWebView migration (#111) complete first
Slow test execution Keep test count low, parallelize where possible

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions