Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve support for Previews and Unit Testing #95

Merged
merged 7 commits into from
Jan 9, 2024

Conversation

Supereg
Copy link
Member

@Supereg Supereg commented Jan 7, 2024

Improve support for Previews and Unit Testing

♻️ Current situation & Problem

As outlined in #63, there is a need to more easily configure the Spezi framework within SwiftUI Previews. This currently is not easily possible, as we require an SpeziAppDelegate to be configured to support infrastructure like the LifecycleHandler protocol. This is not available for Previews.

This PR adds two new shorthand previewWith(simulateLifecycle:_:) and previewWith(standard:simulateLifecycle:_:) modifiers that are targeted for preview usage only. As documented, LifecycleHandler are not fully supported with this configuration due to the missing App delegate. However, there is an option to partially simulate its behavior.

Further, #64 illustrates difficulties to unit test Spezi Modules due to missing abilities to resolve Module dependencies without initializing a SwiftUI App. This PR adds first-hand support for this scenario using the methods withDependencyResolution(simulateLifecycle:_:) and withDependencyResolution(standard:simulateLifecycle:_:) in the XCTSpezi package.

⚙️ Release Notes

  • Add new previewWith(simulateLifecycle:_:) and previewWith(standard:simulateLifecycle:_:) modifiers to be used within SwiftUI Previews.
  • Add new withDependencyResolution(simulateLifecycle:_:) and withDependencyResolution(standard:simulateLifecycle:_:) methods to support unit testing Spezi Modules.

📚 Documentation

Documentation was added to illustrate that these modifiers should only be used within Previews. Further, they are placed in a dedicated Previews section in the DocC landing page.

New DocC bundle was added for the XCTSpezi target.

✅ Testing

Several test cases were added to support this new functionality.

📝 Code of Conduct & Contributing Guidelines

By submitting creating this pull request, you agree to follow our Code of Conduct and Contributing Guidelines:

@Supereg Supereg requested a review from PSchmiedmayer January 7, 2024 19:22
Copy link

codecov bot commented Jan 7, 2024

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (d8b6645) 91.53% compared to head (d8e8643) 91.20%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #95      +/-   ##
==========================================
- Coverage   91.53%   91.20%   -0.33%     
==========================================
  Files          31       34       +3     
  Lines         661      693      +32     
==========================================
+ Hits          605      632      +27     
- Misses         56       61       +5     
Files Coverage Δ
...pabilities/Lifecycle/Spezi+LifecycleHandlers.swift 100.00% <100.00%> (ø)
Sources/Spezi/Configuration/Configuration.swift 100.00% <ø> (ø)
Sources/Spezi/Spezi/View+Spezi.swift 100.00% <ø> (ø)
...Spezi/Utilities/ProcessInfo+PreviewSimulator.swift 100.00% <100.00%> (ø)
Sources/XCTSpezi/DependencyResolution.swift 90.00% <90.00%> (ø)
Sources/Spezi/Spezi/Spezi+Preview.swift 78.95% <78.95%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d8b6645...d8e8643. Read the comment docs.

@Supereg Supereg force-pushed the feature/simple-spezi-configuration branch from 2ff7277 to 56eaaa8 Compare January 8, 2024 23:03
@Supereg
Copy link
Member Author

Supereg commented Jan 8, 2024

@PSchmiedmayer incorporated the ideas from our meeting today. Feel free to review. We are currently failing slightly on diff coverage. Do think it is necessary to cover this case with an UI test still?

Copy link
Member

@PSchmiedmayer PSchmiedmayer left a comment

Choose a reason for hiding this comment

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

Thank you @Supereg; I looked at the PR and only had a few minor comments 👍

Sources/Spezi/Configuration/Configuration.swift Outdated Show resolved Hide resolved
Sources/Spezi/Spezi/View+Spezi.swift Outdated Show resolved Hide resolved
Sources/Spezi/Spezi/View+Spezi.swift Outdated Show resolved Hide resolved
Sources/Spezi/Spezi/View+Spezi.swift Outdated Show resolved Hide resolved
Sources/Spezi/Spezi/View+Spezi.swift Outdated Show resolved Hide resolved
@PSchmiedmayer
Copy link
Member

Does it make sense to add #64 (comment) in the same PR as it will share a bit of the functionality with the lifecycle method and could e.g. use the same type in the configuration.

@Supereg Supereg changed the title Allow for simple Spezi configuration within Previews Improve support for Previews and Unit Testing Jan 9, 2024
Copy link
Member

@PSchmiedmayer PSchmiedmayer left a comment

Choose a reason for hiding this comment

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

Thank you for the improvements @Supereg!

Sources/XCTSpezi/DependencyResolution.swift Outdated Show resolved Hide resolved
Sources/Spezi/Spezi/Spezi+Preview.swift Show resolved Hide resolved
Sources/XCTSpezi/XCTSpezi.docc/XCTSpezi.md Outdated Show resolved Hide resolved
@Supereg Supereg merged commit bf2f55b into main Jan 9, 2024
7 of 8 checks passed
@Supereg Supereg deleted the feature/simple-spezi-configuration branch January 9, 2024 03:19
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.

2 participants