halkyon/packages/halkyon_ui/test/widget/tab_visibility_test.dart

83 lines
2.4 KiB
Dart
Raw Normal View History

import 'package:flutter_test/flutter_test.dart';
import 'package:halkyon_ui/halkyon_ui.dart';
import 'package:material_ui/material_ui.dart';
import '../support/test_app.dart';
void main() {
/// Pumps [child] under a screen tint, in a medium window, so a gradient
/// in it claims its colour while in view.
Future<ScreenTint> show(WidgetTester tester, {required bool visible}) async {
tester.view.physicalSize = const Size(800, 600);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final tint = ScreenTint();
addTearDown(tint.dispose);
await tester.pumpWidget(
testApp(
ScreenTintScope(
notifier: tint,
child: TabVisibility(
visible: visible,
child: const TopGradient(
color: Color(0xFFBA1E55),
background: Color(0xFFFFFFFF),
child: SizedBox.expand(),
),
),
),
),
);
await tester.pump();
return tint;
}
testWidgets('a screen whose tab shows gives the frame its colour', (
tester,
) async {
final tint = await show(tester, visible: true);
expect(tint.color, const Color(0xFFBA1E55));
});
testWidgets("a hidden tab's screen leaves the frame's colour alone", (
tester,
) async {
final tint = await show(tester, visible: false);
expect(tint.color, Brand.primary);
});
testWidgets('outside any tabs, a screen counts as shown', (tester) async {
late bool visible;
await tester.pumpWidget(
Builder(
builder: (context) {
visible = TabVisibility.of(context);
return const SizedBox();
},
),
);
expect(visible, isTrue);
});
testWidgets('the tabs stack shows the tab chosen, keeps the others alive, '
'and tells each whether it shows', (tester) async {
final visible = <String, bool>{};
Widget tab(String name) => Builder(
builder: (context) {
visible[name] = TabVisibility.of(context);
return Text(name);
},
);
await tester.pumpWidget(
testApp(TabsStack(index: 1, children: [tab('Home'), tab('Maps')])),
);
expect(find.text('Maps'), findsOneWidget);
expect(find.text('Home'), findsNothing, reason: 'offstage');
expect(find.text('Home', skipOffstage: false), findsOneWidget);
expect(visible, {'Home': false, 'Maps': true});
});
}