halkyon/packages/halkyon_ui/test/widget/tab_visibility_test.dart
Tizian 「ティツィアーン」 b45db6ea7c
feat(ui): every app's frame around its tabs, Learn's moved into halkyon_ui
NavigationFrame is Learn's AppShell without its router and its tabs: a
navigation rail from medium windows on with the app's icon on top,
leading to the first tab, a bar floating above the foot below, the
background of the screen in view around it, and a tick on every choice.
TabsStack is Learn's container of the tabs' navigators, every tab kept
alive and told whether it shows. Learn's shell is built on both, its
tests unchanged; Train's is next.

The rail's icon is drawn from 120 px at most in memory, as Learn's was.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-10-30 23:52:39 +01:00

83 lines
2.4 KiB
Dart

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});
});
}