mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-10-31 16:24:11 +00:00
Use iOS 26 Observation for Unit and Preview tests. (#5797)
* use observation in unit and preview tests instead of the async stream * use a parsing approach that is independent of the sourcery annotation * Fix observation deferred fulfillments not receiving the initial value Observation's observe only emits transitions, not the value present at subscription time. Drop the leading initial value from the affected transitionValues sequences and assert it directly with #expect instead. * improved docs
This commit is contained in:
@@ -42,6 +42,7 @@ struct TemplateScreen: View {
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
@available(iOS 26.0, *)
|
||||
struct TemplateScreen_Previews: PreviewProvider, TestablePreview {
|
||||
static let viewModel = makeViewModel()
|
||||
static let incrementedViewModel = makeViewModel(counterValue: 1)
|
||||
|
||||
@@ -18,11 +18,21 @@ import {{ import }}
|
||||
{% endfor %}
|
||||
|
||||
enum TestablePreviewsDictionary {
|
||||
static let dictionary: [String: any PreviewProvider.Type] = [
|
||||
{% for type in types.types where (type.implements.TestablePreview or type.based.TestablePreview or type|annotated:"TestablePreview") and type.name != "TestablePreview" %}
|
||||
"{{ type.name }}" : {{ type.name }}.self,
|
||||
{% endfor %}
|
||||
]
|
||||
static let dictionary: [String: any PreviewProvider.Type] = {
|
||||
var dictionary: [String: any PreviewProvider.Type] = [
|
||||
{% for type in types.types where (type.implements.TestablePreview or type.based.TestablePreview or type|annotated:"TestablePreview") and type.name != "TestablePreview" and not type.attributes.available %}
|
||||
"{{ type.name }}" : {{ type.name }}.self,
|
||||
{% endfor %}
|
||||
]
|
||||
// Previews carrying an @available attribute (e.g. those observing state through the iOS 26
|
||||
// Observations-based observe(_:)) can't be referenced unconditionally in this iOS 18 target.
|
||||
if #available(iOS 26.0, *) {
|
||||
{% for type in types.types where (type.implements.TestablePreview or type.based.TestablePreview or type|annotated:"TestablePreview") and type.name != "TestablePreview" and type.attributes.available %}
|
||||
dictionary["{{ type.name }}"] = {{ type.name }}.self
|
||||
{% endfor %}
|
||||
}
|
||||
return dictionary
|
||||
}()
|
||||
}
|
||||
|
||||
// swiftlint:enable all
|
||||
|
||||
Reference in New Issue
Block a user