-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Description
Is there an existing issue for this?
- I have searched the existing issues
- I have read the guide to filing a bug
Steps to reproduce
- Use
MergeSemanticsto wrap one or more multiple widgets that emitSemantics(container: true)to consolidate the semantics tree. - Test the semantics of the consolidated widget using
tester.semantics.simulatedAccessibilityTraversal().
See code further below.
Expected results
Per @goderbauer, simulatedAccessibilityTraversal() should account for the force-merging to enable unit testing of MergeSemantics-based code. Effectively, it should be testing a SemanticsData tree to capture the platform accessibility tree that will be generated from the semantics tree.
Actual results
simulatedAccessibilityTraversal() enumerates the semantics tree as-is, including all SemanticsNodes that are merged upward. It does not use the SemanticsData due to force-merging.
Maybe this is inherent to the API? Should it be deprecated in favor of a new API that emits SemanticsData (and also exposes the number of children so that we can assert when something should be a leaf node)? Is it possible to test the structure of the platform accessibility that will be generated?
Code sample
https://dartpad.dev/?id=06937c78a65c3c3daf75eb81648b1783
Code sample
await tester.pumpWidget(
MaterialApp(
home: MergeSemantics(
child: Semantics(
container: true,
label: 'Container',
child: Semantics(
button: true,
container: true,
label: 'Foo',
child: const SizedBox(width: 10, height: 10),
),
),
),
),
);
// Fails since `simulatedAccessibilityTraversal` doesn't account
// for force-merging.
expect(
tester.semantics.simulatedAccessibilityTraversal(),
[containsSemantics(label: 'Container\nFoo', isButton: true)],
);