mirror of https://github.com/flutter/samples.git
[animations] adds widget test for expand card (#410)
parent
ef0114c210
commit
b2f3ccfad2
@ -0,0 +1,49 @@
|
|||||||
|
// Copyright 2020 The Flutter team. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:animations/src/misc/expand_card.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
Widget createExpandCardScreen() => MaterialApp(
|
||||||
|
home: ExpandCardDemo(),
|
||||||
|
);
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('ExpandCard Tests', () {
|
||||||
|
testWidgets('ExpandCard changes size on tap', (tester) async {
|
||||||
|
await tester.pumpWidget(createExpandCardScreen());
|
||||||
|
|
||||||
|
// Get the initial size of ExpandCard.
|
||||||
|
Size initialSize = tester.getSize(find.byType(ExpandCard));
|
||||||
|
|
||||||
|
// Tap on the ExpandCard.
|
||||||
|
await tester.tap(find.byType(ExpandCard));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
// The size of ExpandCard must change once tapped.
|
||||||
|
// The initialSize should be less than current ExpandCard size.
|
||||||
|
expect(
|
||||||
|
initialSize,
|
||||||
|
lessThan(tester.getSize(find.byType(ExpandCard))),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('ExpandCard changes image on tap', (tester) async {
|
||||||
|
await tester.pumpWidget(createExpandCardScreen());
|
||||||
|
|
||||||
|
Image initialImage = tester.widget(find.byType(Image).last);
|
||||||
|
|
||||||
|
// Tap on ExpandCard.
|
||||||
|
await tester.tap(find.byType(ExpandCard));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
// Once tapped, the image should change.
|
||||||
|
expect(
|
||||||
|
initialImage,
|
||||||
|
isNot(equals(tester.widget(find.byType(Image).last))),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in new issue