forked from flutter/packages
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test remaining transitions api examples (#148302)
Adds tests for `relative_positioned_transition`, `positioned_transition`, `sliver_fade_transition`, `align_transition`, `animated_builder`, `rotation_transition`, `animated_widget`, `slide_transition`, `listenable_builder`, `scale_transition`, `default_text_style_transition`, `decorated_box_transition`, `size_transition` api examples. Makes double type in the `align_transition` example explicit. A test for `fade_transition` is already in currently open #148178. Part of #130459.
- Loading branch information
Showing
15 changed files
with
562 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
examples/api/test/widgets/transitions/align_transition.0_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2014 The Flutter Authors. 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:flutter/material.dart'; | ||
import 'package:flutter_api_samples/widgets/transitions/align_transition.0.dart' as example; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
testWidgets('Shows flutter logo in transition', (WidgetTester tester) async { | ||
await tester.pumpWidget(const example.AlignTransitionExampleApp()); | ||
expect(find.byType(ColoredBox), findsOneWidget); | ||
expect( | ||
find.byWidgetPredicate((Widget padding) => padding is Padding | ||
&& padding.padding == const EdgeInsets.all(8.0)), | ||
findsOneWidget, | ||
); | ||
expect(find.byType(FlutterLogo), findsOneWidget); | ||
expect(find.byType(AlignTransition), findsOneWidget); | ||
}); | ||
|
||
testWidgets('Animates repeatedly every 2 seconds', (WidgetTester tester) async { | ||
await tester.pumpWidget(const example.AlignTransitionExampleApp()); | ||
final Finder paddingFinder = find.byWidgetPredicate( | ||
(Widget padding) => padding is Padding | ||
&& padding.padding == const EdgeInsets.all(8.0)); | ||
|
||
expect( | ||
tester.getBottomLeft(paddingFinder), | ||
tester.getBottomLeft(find.byType(AlignTransition)), | ||
); | ||
|
||
await tester.pump(const Duration(seconds: 2)); | ||
await tester.pump(); | ||
|
||
expect( | ||
tester.getCenter(paddingFinder), | ||
tester.getCenter(find.byType(AlignTransition)), | ||
); | ||
|
||
await tester.pump(const Duration(seconds: 2)); | ||
await tester.pump(); | ||
|
||
expect( | ||
tester.getBottomLeft(paddingFinder), | ||
tester.getBottomLeft(find.byType(AlignTransition)), | ||
); | ||
}); | ||
} |
30 changes: 30 additions & 0 deletions
30
examples/api/test/widgets/transitions/animated_builder.0_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2014 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'dart:math' as math; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_api_samples/widgets/transitions/animated_builder.0.dart' as example; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
testWidgets('Rotates text and container', (WidgetTester tester) async { | ||
await tester.pumpWidget(const example.AnimatedBuilderExampleApp()); | ||
expect(find.text('Whee!'), findsOneWidget); | ||
expect(find.byType(Container), findsOneWidget); | ||
expect(tester.widget(find.byType(Container)), isA<Container>() | ||
.having((Container container) => container.color, 'color', Colors.green)); | ||
|
||
expect(find.byWidgetPredicate((Widget widget) => widget is Transform | ||
&& widget.transform == Transform.rotate(angle: 0.0).transform), | ||
findsOneWidget); | ||
|
||
await tester.pump(const Duration(seconds: 5)); | ||
await tester.pump(); | ||
|
||
expect(find.byWidgetPredicate((Widget widget) => widget is Transform | ||
&& widget.transform == Transform.rotate(angle: math.pi).transform), | ||
findsOneWidget); | ||
}); | ||
} |
29 changes: 29 additions & 0 deletions
29
examples/api/test/widgets/transitions/animated_widget.0_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2014 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import 'dart:math' as math; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_api_samples/widgets/transitions/animated_widget.0.dart' as example; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
testWidgets('Rotates green container', (WidgetTester tester) async { | ||
await tester.pumpWidget(const example.AnimatedWidgetExampleApp()); | ||
expect(find.byType(Container), findsOneWidget); | ||
expect(tester.widget(find.byType(Container)), isA<Container>() | ||
.having((Container container) => container.color, 'color', Colors.green)); | ||
|
||
expect(find.byWidgetPredicate((Widget widget) => widget is Transform | ||
&& widget.transform == Transform.rotate(angle: 0.0).transform), | ||
findsOneWidget); | ||
|
||
await tester.pump(const Duration(seconds: 5)); | ||
await tester.pump(); | ||
|
||
expect(find.byWidgetPredicate((Widget widget) => widget is Transform | ||
&& widget.transform == Transform.rotate(angle: math.pi).transform), | ||
findsOneWidget); | ||
}); | ||
} |
66 changes: 66 additions & 0 deletions
66
examples/api/test/widgets/transitions/decorated_box_transition.0_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2014 The Flutter Authors. 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:flutter/material.dart'; | ||
import 'package:flutter_api_samples/widgets/transitions/decorated_box_transition.0.dart' as example; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
testWidgets('Shows container in 3 second loop', (WidgetTester tester) async { | ||
await tester.pumpWidget(const example.DecoratedBoxTransitionExampleApp()); | ||
expect(find.byType(FlutterLogo), findsOneWidget); | ||
expect(find.byType(Center), findsOneWidget); | ||
expect(find.descendant( | ||
of: find.byType(Center), | ||
matching: find.byType(FlutterLogo) | ||
), findsOneWidget); | ||
expect(find.ancestor( | ||
of: find.byType(FlutterLogo), | ||
matching: find.byType(Container) | ||
), findsAtLeast(1)); | ||
expect(find.byType(DecoratedBoxTransition), findsOneWidget); | ||
|
||
expect( | ||
tester.widget(find.byType(DecoratedBoxTransition)), | ||
isA<DecoratedBoxTransition>() | ||
.having( | ||
(DecoratedBoxTransition transition) => transition.decoration.value, | ||
'decoration', | ||
BoxDecoration( | ||
color: const Color(0xFFFFFFFF), | ||
border: Border.all(style: BorderStyle.none), | ||
borderRadius: BorderRadius.circular(60.0), | ||
boxShadow: const <BoxShadow>[ | ||
BoxShadow( | ||
color: Color(0x66666666), | ||
blurRadius: 10.0, | ||
spreadRadius: 3.0, | ||
offset: Offset(0, 6.0), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
|
||
await tester.pump(const Duration(seconds: 3)); | ||
await tester.pump(); | ||
|
||
expect( | ||
tester.widget(find.byType(DecoratedBoxTransition)), | ||
isA<DecoratedBoxTransition>() | ||
.having( | ||
(DecoratedBoxTransition transition) => transition.decoration.value, | ||
'decoration', | ||
BoxDecoration( | ||
color: const Color(0xFFFFFFFF), | ||
border: Border.all( | ||
style: BorderStyle.none, | ||
), | ||
borderRadius: BorderRadius.zero, | ||
// No shadow. | ||
), | ||
), | ||
); | ||
}); | ||
} |
56 changes: 56 additions & 0 deletions
56
examples/api/test/widgets/transitions/default_text_style_transition.0_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2014 The Flutter Authors. 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:flutter/material.dart'; | ||
import 'package:flutter_api_samples/widgets/transitions/default_text_style_transition.0.dart' as example; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
testWidgets('Transforms text style periodically', (WidgetTester tester) async { | ||
await tester.pumpWidget(const example.DefaultTextStyleTransitionExampleApp()); | ||
expect(find.byType(Center), findsOneWidget); | ||
expect(find.byType(Text), findsOneWidget); | ||
expect(find.text('Flutter'), findsOneWidget); | ||
expect( | ||
find.descendant( | ||
of: find.byType(Center), | ||
matching: find.byType(Text) | ||
), | ||
findsOneWidget, | ||
); | ||
expect(find.byType(DefaultTextStyleTransition), findsOneWidget); | ||
expect(tester.widget(find.byType(DefaultTextStyleTransition)), | ||
isA<DefaultTextStyleTransition>() | ||
.having( | ||
(DefaultTextStyleTransition transition) => transition.style.value, | ||
'style', | ||
const TextStyle(fontSize: 50, color: Colors.blue, fontWeight: FontWeight.w900), | ||
), | ||
); | ||
|
||
await tester.pump(const Duration(seconds: 2)); | ||
await tester.pump(); | ||
|
||
expect(tester.widget(find.byType(DefaultTextStyleTransition)), | ||
isA<DefaultTextStyleTransition>() | ||
.having( | ||
(DefaultTextStyleTransition transition) => transition.style.value, | ||
'style', | ||
const TextStyle(fontSize: 50, color: Colors.red, fontWeight: FontWeight.w100), | ||
), | ||
); | ||
|
||
await tester.pump(const Duration(seconds: 2)); | ||
await tester.pump(); | ||
|
||
expect(tester.widget(find.byType(DefaultTextStyleTransition)), | ||
isA<DefaultTextStyleTransition>() | ||
.having( | ||
(DefaultTextStyleTransition transition) => transition.style.value, | ||
'style', | ||
const TextStyle(fontSize: 50, color: Colors.blue, fontWeight: FontWeight.w900), | ||
), | ||
); | ||
}); | ||
} |
34 changes: 34 additions & 0 deletions
34
examples/api/test/widgets/transitions/listenable_builder.2_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2014 The Flutter Authors. 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:flutter/material.dart'; | ||
import 'package:flutter_api_samples/widgets/transitions/listenable_builder.2.dart' as example; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
testWidgets('Increments counter', (WidgetTester tester) async { | ||
await tester.pumpWidget(const example.ListenableBuilderExample()); | ||
expect(find.text('ListenableBuilder Example'), findsOneWidget); | ||
expect(find.text('Current counter value:'), findsOneWidget); | ||
expect(find.byIcon(Icons.add), findsOneWidget); | ||
expect(find.descendant( | ||
of: find.byType(FloatingActionButton), | ||
matching: find.byIcon(Icons.add) | ||
), findsOneWidget); | ||
|
||
|
||
expect(find.text('0'), findsOneWidget); | ||
expect(find.text('1'), findsNothing); | ||
await tester.tap(find.byIcon(Icons.add)); | ||
await tester.pump(); | ||
expect(find.text('0'), findsNothing); | ||
expect(find.text('1'), findsOneWidget); | ||
|
||
for (int i = 0; i < 4; i++) { | ||
await tester.tap(find.byIcon(Icons.add)); | ||
} | ||
await tester.pump(); | ||
expect(find.text('5'), findsOneWidget); | ||
}); | ||
} |
42 changes: 42 additions & 0 deletions
42
examples/api/test/widgets/transitions/positioned_transition.0_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2014 The Flutter Authors. 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:flutter/material.dart'; | ||
import 'package:flutter_api_samples/widgets/transitions/positioned_transition.0.dart' as example; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
testWidgets('Shows flutter logo in transition', (WidgetTester tester) async { | ||
await tester.pumpWidget(const example.PositionedTransitionExampleApp()); | ||
expect(find.byType(FlutterLogo), findsOneWidget); | ||
expect(find.byType(Padding), findsAtLeast(1)); | ||
expect(find.byType(PositionedTransition), findsOneWidget); | ||
}); | ||
|
||
testWidgets('Animates repeatedly every 2 seconds', (WidgetTester tester) async { | ||
await tester.pumpWidget(const example.PositionedTransitionExampleApp()); | ||
|
||
expect(tester.getSize(find.byType(FlutterLogo)), const Size(100.0 - 2.0 * 8.0, 100.0 - 2.0 * 8.0)); | ||
expect(tester.getTopLeft(find.byType(FlutterLogo)), const Offset(8.0, 8.0)); | ||
|
||
await tester.pump(const Duration(seconds: 2)); | ||
await tester.pump(); | ||
|
||
final Size canvasSize = tester.getSize(find.byType(LayoutBuilder)); | ||
expect(tester.getSize(find.byType(FlutterLogo)), const Size(200.0 - 2.0 * 8.0, 200.0 - 2.0 * 8.0)); | ||
expect(tester.getBottomRight(find.byType(FlutterLogo)), Offset(canvasSize.width - 8.0, canvasSize.height - 8.0)); | ||
|
||
await tester.pump(const Duration(seconds: 2)); | ||
await tester.pump(); | ||
|
||
expect(tester.getSize(find.byType(FlutterLogo)), const Size(100.0 - 2.0 * 8.0, 100.0 - 2.0 * 8.0)); | ||
expect(tester.getTopLeft(find.byType(FlutterLogo)), const Offset(8.0, 8.0)); | ||
|
||
await tester.pump(const Duration(seconds: 2)); | ||
await tester.pump(); | ||
|
||
expect(tester.getSize(find.byType(FlutterLogo)), const Size(200.0 - 2.0 * 8.0, 200.0 - 2.0 * 8.0)); | ||
expect(tester.getBottomRight(find.byType(FlutterLogo)), Offset(canvasSize.width - 8.0, canvasSize.height - 8.0)); | ||
}); | ||
} |
42 changes: 42 additions & 0 deletions
42
examples/api/test/widgets/transitions/relative_positioned_transition.0_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2014 The Flutter Authors. 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:flutter/material.dart'; | ||
import 'package:flutter_api_samples/widgets/transitions/relative_positioned_transition.0.dart' as example; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
testWidgets('Shows flutter logo in transition', (WidgetTester tester) async { | ||
await tester.pumpWidget(const example.RelativePositionedTransitionExampleApp()); | ||
expect(find.byType(FlutterLogo), findsOneWidget); | ||
expect(find.byType(Padding), findsAtLeast(1)); | ||
expect(find.byType(RelativePositionedTransition), findsOneWidget); | ||
}); | ||
|
||
testWidgets('Animates repeatedly every 2 seconds', (WidgetTester tester) async { | ||
await tester.pumpWidget(const example.RelativePositionedTransitionExampleApp()); | ||
|
||
expect(tester.getSize(find.byType(FlutterLogo)), const Size(200.0 - 2.0 * 8.0, 200.0 - 2.0 * 8.0)); | ||
expect(tester.getTopLeft(find.byType(FlutterLogo)), const Offset(8.0, 8.0)); | ||
|
||
await tester.pump(const Duration(seconds: 2)); | ||
await tester.pump(); | ||
|
||
final Size canvasSize = tester.getSize(find.byType(LayoutBuilder)); | ||
expect(tester.getSize(find.byType(FlutterLogo)), const Size(100.0 - 2.0 * 8.0, 100.0 - 2.0 * 8.0)); | ||
expect(tester.getBottomRight(find.byType(FlutterLogo)), Offset(canvasSize.width - 8.0, canvasSize.height - 8.0)); | ||
|
||
await tester.pump(const Duration(seconds: 2)); | ||
await tester.pump(); | ||
|
||
expect(tester.getSize(find.byType(FlutterLogo)), const Size(200.0 - 2.0 * 8.0, 200.0 - 2.0 * 8.0)); | ||
expect(tester.getTopLeft(find.byType(FlutterLogo)), const Offset(8.0, 8.0)); | ||
|
||
await tester.pump(const Duration(seconds: 2)); | ||
await tester.pump(); | ||
|
||
expect(tester.getSize(find.byType(FlutterLogo)), const Size(100.0 - 2.0 * 8.0, 100.0 - 2.0 * 8.0)); | ||
expect(tester.getBottomRight(find.byType(FlutterLogo)), Offset(canvasSize.width - 8.0, canvasSize.height - 8.0)); | ||
}); | ||
} |
Oops, something went wrong.