Skip to content

Commit

Permalink
Test remaining transitions api examples (#148302)
Browse files Browse the repository at this point in the history
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
derdilla authored May 23, 2024
1 parent aaa4d33 commit 7fb7192
Show file tree
Hide file tree
Showing 15 changed files with 562 additions and 14 deletions.
13 changes: 0 additions & 13 deletions dev/bots/check_code_samples.dart
Original file line number Diff line number Diff line change
Expand Up @@ -380,19 +380,6 @@ final Set<String> _knownMissingTests = <String>{
'examples/api/test/widgets/media_query/media_query_data.system_gesture_insets.0_test.dart',
'examples/api/test/widgets/async/future_builder.0_test.dart',
'examples/api/test/widgets/animated_switcher/animated_switcher.0_test.dart',
'examples/api/test/widgets/transitions/relative_positioned_transition.0_test.dart',
'examples/api/test/widgets/transitions/positioned_transition.0_test.dart',
'examples/api/test/widgets/transitions/sliver_fade_transition.0_test.dart',
'examples/api/test/widgets/transitions/align_transition.0_test.dart',
'examples/api/test/widgets/transitions/animated_builder.0_test.dart',
'examples/api/test/widgets/transitions/rotation_transition.0_test.dart',
'examples/api/test/widgets/transitions/animated_widget.0_test.dart',
'examples/api/test/widgets/transitions/slide_transition.0_test.dart',
'examples/api/test/widgets/transitions/listenable_builder.2_test.dart',
'examples/api/test/widgets/transitions/scale_transition.0_test.dart',
'examples/api/test/widgets/transitions/default_text_style_transition.0_test.dart',
'examples/api/test/widgets/transitions/decorated_box_transition.0_test.dart',
'examples/api/test/widgets/transitions/size_transition.0_test.dart',
'examples/api/test/widgets/animated_list/animated_list.0_test.dart',
'examples/api/test/widgets/focus_traversal/focus_traversal_group.0_test.dart',
'examples/api/test/widgets/focus_traversal/ordered_traversal_policy.0_test.dart',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class _AlignTransitionExampleState extends State<AlignTransitionExample> with Ti
child: AlignTransition(
alignment: _animation,
child: const Padding(
padding: EdgeInsets.all(8),
padding: EdgeInsets.all(8.0),
child: FlutterLogo(size: 150.0),
),
),
Expand Down
49 changes: 49 additions & 0 deletions examples/api/test/widgets/transitions/align_transition.0_test.dart
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 examples/api/test/widgets/transitions/animated_builder.0_test.dart
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 examples/api/test/widgets/transitions/animated_widget.0_test.dart
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);
});
}
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.
),
),
);
});
}
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),
),
);
});
}
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);
});
}
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));
});
}
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));
});
}
Loading

0 comments on commit 7fb7192

Please sign in to comment.