-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
Support the Component/Module Creation for Xcode Previews #63
Labels
enhancement
New feature or request
Comments
1 task
1 task
1 task
1 task
Supereg
added a commit
that referenced
this issue
Jan 9, 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. ## :gear: 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. ## :books: 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. ## :white_check_mark: Testing Several test cases were added to support this new functionality. ## :pencil: Code of Conduct & Contributing Guidelines By submitting creating this pull request, you agree to follow our [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md): - [x] I agree to follow the [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md).
Completed as of #95 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem
Using some code in a SwiftUI view that, e.g., uses an
@EnvironmentObject
injected by Spezi requires the manual annotation in the SwiftUI preview to inject this object:While this is possible for simple components with no
@Dependency
-annotated components, injecting more complex components that require the injection of dependencies makes this difficult.Solution
We propose the creation of a
.previewComponent(...)
or.previewComponents(...)
view modifier that injects a specified amount of components in the environment.The modifier would also require the definition of the associated standard or any generic requirement that are imposed on a component.
Additional context
Input on the design of this preview injection mechanism is greatly welcome. Please leave your thoughts and comments under this issue.
Code of Conduct
The text was updated successfully, but these errors were encountered: