Comments (4)
Hey @matiasvillaverde, there was a proposal for improving the library in a way of making the lookup more dynamic and tolerant to the view structure changes.
Snapshotting or auto-generating the full path in the code saves time while you write the test, but the test remains fragile, where a tiny change in the view hierarchy could break it.
So far I have in plans digging towards that approach, but your proposal makes sense and I'll keep it in mind as a fall-back solution.
from viewinspector.
Cool! It makes sense. In the case of snapshot, a change that breaks the tests can be a trigger to re-run the generation of the tests.
Keep me in the loop, in case I can contribute to it, it is a topic that interest me.
from viewinspector.
@integer256 with the recent release of the aforementioned dynamic query I can outline what is technically available now.
To begin with, each view in the hierarchy now can be located dynamically with find
function, and after that, by calling pathToRoot
, you can get a string representing the full inspection chain that leads to this view. For example:
let view = MyCustomView()
let sut = try view.inspect().find(ViewType.Text, where: { try $0.string == "Hello, world!" })
print(sut.pathToRoot)
// "anyView().hStack().group(1).vStack(0).text(0)"
The path can be used in place of find
, and this thing resembles the process of "autogeneration" you were talking about. However, the usefulness of the replacement is questionable.
Looking at the functionality of the library you mentioned, I can add the feature of printing the entire view tree. It can, in theory, also print applied attributes and modifiers, however, it cannot yet calculate the layout frames.
Basically, ViewInspector can print a human-readable view structure with all the submitted values, and this dump will change every time something is tweaked inside the view. I cannot understand the use case where this can be helpful though - probably because I never used snapshot-generating libraries in tests. Let me know If such a full "dump" of the view hierarchy's structure is actually what you'd expect.
from viewinspector.
@nalexn That is great news! Thanks for the update.
I can imagine that would be helpful to have a method to print a human-readable view structure, as an intermediate step of writing the final test. Given that, due to the complexity of the hierarchy, sometimes it's difficult to inspect the correct view.
The new find
function already simplifies the process of writing test a lot!
from viewinspector.
Related Issues (20)
- Inspecting custom modifier doesn't see removed views HOT 1
- Inspecting conditional toolbar content
- Inspect fails to find views due to `guardType(value:namespacedPrefixes:inspectionCall:)` incorrectly failing HOT 4
- Xcode 15.0 - Type mismatch: ButtonAction is not () -> () HOT 1
- Question: trying to use the (super) ViewInspector in non test code HOT 1
- Runtime warning when using . modelContainer modifier for SwiftData HOT 1
- View Hosting on watchOS in a Swift Package HOT 1
- iOS 17: Button style check HOT 1
- Views with .help become unfindable HOT 4
- Find fails when view has recursion inside of ForEach HOT 1
- Issue with .tint() modifier in Tests after updating Deployment Target to iOS 16
- Not found Shape in test layer HOT 2
- Accessing properties on a view that takes a generic HOT 2
- Does find(button: "xyz") find custom button `label:`s? HOT 4
- Interface buttons by ID HOT 1
- Is there a timeline on when we can expect 0.10.0 to be released? HOT 4
- View for `UIViewControllerRepresentable` is absent
- Only able to find the first AccessibilityIdentifier applied to a View, unless applied using a ViewModifier.
- Inspection of onTap gesture on custom Layout HOT 1
- Not able to test Charts framework elements/protocols
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from viewinspector.