Skip to content

Add previews reference document#61

Merged
AvdLee merged 3 commits into
AvdLee:mainfrom
jack-old-archive:feature/add-testing-previews-reference
May 28, 2026
Merged

Add previews reference document#61
AvdLee merged 3 commits into
AvdLee:mainfrom
jack-old-archive:feature/add-testing-previews-reference

Conversation

@jack-old-archive
Copy link
Copy Markdown
Contributor

@jack-old-archive jack-old-archive commented Apr 27, 2026

Summary

  • Add references/previews.md covering SwiftUI preview patterns
  • Includes #Preview macro usage, preview traits, @Previewable for inline interactive state (iOS 18+), and mock data patterns for self-contained previews
  • Updates SKILL.md to register the new reference in the topic router and reference list
  • Adds a correctness-checklist item: previews must use self-contained mock data with no dependency on live services or network

Notes

This started as a broader testing-and-previews contribution, but per AGENTS.md testing frameworks and patterns are explicitly out of scope for this skill, so the testing sections were dropped and the file was renamed from testing-previews.md to previews.md. See the discussion thread for details.

…terns

The skill currently has no coverage for testing or previews. Add a new
reference covering #Preview macro usage and traits, @Previewable for
inline bindings, mock data patterns for previews, XCTest strategies
for @observable models and UI tests, ViewInspector for view-layer
unit testing, and snapshot testing with swift-snapshot-testing.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new on-demand reference for SwiftUI testing and preview workflows, then wires that reference into the skill so agents can discover it through the topic router and references list. It expands the skill’s coverage around previews, mock data, model testing, UI tests, and snapshot testing.

Changes:

  • Add references/testing-previews.md with guidance for #Preview, @Previewable, mock preview data, XCTest/XCUITest patterns, and snapshot testing.
  • Register the new testing/previews reference in the SKILL topic router and reference list.
  • Extend the SKILL correctness checklist with a preview-specific rule about using self-contained mock data instead of live services.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 9 comments.

File Description
swiftui-expert-skill/references/testing-previews.md New reference document covering preview setup, mock data patterns, testing approaches, diagnostics, and checklist guidance.
swiftui-expert-skill/SKILL.md Adds the new reference to discovery points and updates the correctness checklist with a preview-data rule.

Comment thread swiftui-expert-skill/references/testing-previews.md Outdated
Comment thread swiftui-expert-skill/references/testing-previews.md Outdated
Comment thread swiftui-expert-skill/references/testing-previews.md Outdated
Comment thread swiftui-expert-skill/references/testing-previews.md Outdated
Comment thread swiftui-expert-skill/references/testing-previews.md Outdated
Comment thread swiftui-expert-skill/references/testing-previews.md Outdated
Comment thread swiftui-expert-skill/references/testing-previews.md Outdated
Comment thread swiftui-expert-skill/references/testing-previews.md Outdated
Comment thread swiftui-expert-skill/references/testing-previews.md Outdated
Per AGENTS.md, testing frameworks and patterns are excluded from this
skill. Drop the XCTest, XCUITest, snapshot testing, and @observable
model testing sections, and rename the reference to previews.md so the
file name matches its remaining scope.

Also addresses the Copilot review:
- Remove the UIKit/AppKit preview section (off-mission per the
  SwiftUI-first operating rule).
- Replace the invented URLSession.decode(_:from:) call with a real
  URLSession.data(from:) + JSONDecoder pair.
- Switch the @Previewable @focusstate example from .onAppear writes to
  .defaultFocus, matching focus-patterns.md.
- Soften the "use #Preview for all new previews" checklist item to a
  preference, since PreviewProvider is not deprecated.
- Cross-link state-management.md and focus-patterns.md from the
  preview docs.
- Restore the blank line between the correctness checklist and the
  References section in SKILL.md.
@AvdLee
Copy link
Copy Markdown
Owner

AvdLee commented May 28, 2026

Hi @jack-old-archive — since this PR has been waiting on review feedback for a while, I've pushed a commit to your branch (the Allow edits by maintainers checkbox was enabled, thank you) so we can move it forward. Here's what changed and why.

Scope reduction

Per AGENTS.md, this skill explicitly excludes testing frameworks and patterns as a topic. The XCTest, XCUITest, snapshot testing, and @Observable model testing sections are out of scope and have been removed. The previews half of the contribution is genuinely SwiftUI-specific and stays.

  • references/testing-previews.md → renamed to references/previews.md
  • Final size: ~250 lines, down from 643
  • SKILL.md topic router and references list updated to match

The correctness checklist item about preview mock data is kept — that's a correctness concern (previews must compile and render without external dependencies) and fits the skill's scope.

Resolution of Copilot's review comments

# Comment Resolution
1 XCTest heading uses Swift Testing examples Section removed (out of scope)
2 UIKit/AppKit preview section is off-mission Section removed
3 URLSession.decode(_:from:) is an invented API Replaced with real URLSession.data(from:) + JSONDecoder
4 Hosting controller test doesn't actually verify SwiftUI hierarchy Section removed (out of scope)
5 PR claims ViewInspector but doc has none PR description updated separately; ViewInspector is out of scope
6 "Use #Preview for all new previews" too prescriptive Reworded to "Prefer #Preview for new previews; PreviewProvider is still valid"
7 @FocusState set in .onAppear conflicts with focus-patterns.md Switched to .defaultFocus($isFocused, true)
8 swift-snapshot-testing claim about auto-creating reference is false Section removed (out of scope)
9 testFetchItemsSetsLoadingState doesn't assert what its name claims Section removed (out of scope)

Additional fixes I noticed

  • Item.id type inconsistency: the snapshot example used Item(id: "A", ...) while the struct declared let id: UUID — would not have compiled. Removed with the snapshot section.
  • CartModel referenced undefined methods: tests called addItem, removeAll, total which were never shown on the model. Removed with the testing section.
  • Missing cross-links: the new doc now links to state-management.md (for @Observable) and focus-patterns.md (for the focus rationale), matching the cross-linking pattern used by other reference files.
  • Missing blank line in SKILL.md: between the correctness checklist and ## References. Restored.

What stayed

  • #Preview macro basics, named previews, traits, NavigationStack previews
  • Static sample data on models, mock @Observable models, environment injection
  • Protocol-based async data mocking (with corrected URLSession example)
  • @Previewable (iOS 18+), interactive previews, @Previewable + @FocusState, pre-iOS 18 fallback
  • Diagnostics table and summary checklist (both trimmed to previews-only)

Thanks for the contribution — the previews material is genuinely useful and worth keeping. Please shout if you'd like to revisit any of the removed testing content as a separate, scoped contribution to a different repository (or a focused follow-up if we ever expand the skill's scope).

@AvdLee AvdLee changed the title Add testing and previews reference document Add previews reference document May 28, 2026
@AvdLee AvdLee merged commit 934a860 into AvdLee:main May 28, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants