add ability to match child semantics data (#22001)

This commit is contained in:
Jonah Williams
2018-10-05 17:44:26 -07:00
committed by GitHub
parent 21a32fdd0c
commit cdf1cec902
16 changed files with 307 additions and 62 deletions

View File

@@ -409,8 +409,8 @@ void main() {
},
));
expect(tester.getSemanticsData(find.byKey(key)),
matchesSemanticsData(
expect(tester.getSemantics(find.byKey(key)),
matchesSemantics(
label: 'foo',
hint: 'bar',
value: 'baz',
@@ -432,8 +432,8 @@ void main() {
);
// Doesn't match custom actions
expect(tester.getSemanticsData(find.byKey(key)),
isNot(matchesSemanticsData(
expect(tester.getSemantics(find.byKey(key)),
isNot(matchesSemantics(
label: 'foo',
hint: 'bar',
value: 'baz',
@@ -453,8 +453,8 @@ void main() {
);
// Doesn't match wrong hints
expect(tester.getSemanticsData(find.byKey(key)),
isNot(matchesSemanticsData(
expect(tester.getSemantics(find.byKey(key)),
isNot(matchesSemantics(
label: 'foo',
hint: 'bar',
value: 'baz',
@@ -500,8 +500,10 @@ void main() {
scrollExtentMin: null,
customSemanticsActionIds: <int>[CustomSemanticsAction.getIdentifier(action)],
);
final _FakeSemanticsNode node = _FakeSemanticsNode();
node.data = data;
expect(data, matchesSemanticsData(
expect(node, matchesSemantics(
rect: Rect.fromLTRB(0.0, 0.0, 10.0, 10.0),
size: const Size(10.0, 10.0),
/* Flags */
@@ -548,6 +550,35 @@ void main() {
customActions: <CustomSemanticsAction>[action],
));
});
testWidgets('Can match child semantics', (WidgetTester tester) async {
final SemanticsHandle handle = tester.ensureSemantics();
const Key key = Key('a');
await tester.pumpWidget(Semantics(
key: key,
label: 'Foo',
container: true,
explicitChildNodes: true,
textDirection: TextDirection.ltr,
child: Semantics(
label: 'Bar',
textDirection: TextDirection.ltr,
),
));
final SemanticsNode node = tester.getSemantics(find.byKey(key));
expect(node, matchesSemantics(
label: 'Foo',
textDirection: TextDirection.ltr,
children: <Matcher>[
matchesSemantics(
label: 'Bar',
textDirection: TextDirection.ltr,
),
],
));
handle.dispose();
});
});
}
@@ -592,3 +623,9 @@ class _FakeComparator implements GoldenFileComparator {
return Future<void>.value();
}
}
class _FakeSemanticsNode extends SemanticsNode {
SemanticsData data;
@override
SemanticsData getSemanticsData() => data;
}

View File

@@ -540,7 +540,7 @@ void main() {
),
);
expect(() => tester.getSemanticsData(find.text('hello')),
expect(() => tester.getSemantics(find.text('hello')),
throwsA(isInstanceOf<StateError>()));
});
@@ -560,7 +560,7 @@ void main() {
),
);
expect(() => tester.getSemanticsData(find.text('hello')),
expect(() => tester.getSemantics(find.text('hello')),
throwsA(isInstanceOf<StateError>()));
semanticsHandle.dispose();
});
@@ -581,7 +581,8 @@ void main() {
),
);
final SemanticsData semantics = tester.getSemanticsData(find.text('hello'));
final SemanticsNode node = tester.getSemantics(find.text('hello'));
final SemanticsData semantics = node.getSemanticsData();
expect(semantics.label, 'hello');
expect(semantics.hasAction(SemanticsAction.tap), true);
expect(semantics.hasFlag(SemanticsFlag.isButton), true);
@@ -609,7 +610,8 @@ void main() {
),
);
final SemanticsData semantics = tester.getSemanticsData(find.byKey(key));
final SemanticsNode node = tester.getSemantics(find.byKey(key));
final SemanticsData semantics = node.getSemanticsData();
expect(semantics.label, 'A\nB\nC');
semanticsHandle.dispose();
});