963adec122
One floating frosted tab bar (host NavigationBar / CupertinoTabBar in the shared GlassPill) replaces the NavigationRail, the Cupertino sidebar and the run detail, stage page and pipeline detail tab strips. Below 600px it spans the width minus 16px margins; wider it is sized to its tabs at the right edge. Content keeps the full width, scrolls behind the bar and learns its height as bottom media padding; lists pad their end clear of it and FABs sit above it. The bar now sizes itself from its own constraints instead of the screen size, which fixes the widget_test failure where a MediaQuery without a size gave it negative width constraints.
187 lines
6.8 KiB
Dart
187 lines
6.8 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/shell/adaptive_shell.dart';
|
|
import 'package:pipelines_app/shell/destination.dart';
|
|
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
|
|
import 'package:pipelines_app/ui/adaptive/glass_pill.dart';
|
|
|
|
/// The shell's one floating glass tab bar: full width on a phone, sized to its
|
|
/// tabs at the right edge on a wide window, with content behind it.
|
|
void main() {
|
|
Finder pill() => find.descendant(
|
|
of: find.byType(FloatingDestinationBar),
|
|
matching: find.byType(GlassPill),
|
|
);
|
|
|
|
Finder barText(String label) => find.descendant(
|
|
of: find.byType(FloatingDestinationBar),
|
|
matching: find.text(label),
|
|
);
|
|
|
|
Future<void> setSize(WidgetTester tester, Size size) async {
|
|
tester.view.physicalSize = size;
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.reset);
|
|
}
|
|
|
|
var taps = 0;
|
|
double? contentBottomPadding;
|
|
|
|
Widget shell({required bool cupertino}) {
|
|
final app = AdaptiveShell(
|
|
cupertino: cupertino,
|
|
destinationBodies: {
|
|
AppDestination.pipelines: (_) => Builder(
|
|
builder: (context) {
|
|
contentBottomPadding = MediaQuery.paddingOf(context).bottom;
|
|
return StatefulBuilder(
|
|
builder: (context, setState) => GestureDetector(
|
|
key: const Key('content'),
|
|
behavior: HitTestBehavior.opaque,
|
|
onTap: () => setState(() => taps++),
|
|
child: SizedBox.expand(child: Text('taps $taps')),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
},
|
|
);
|
|
return cupertino ? CupertinoApp(home: app) : MaterialApp(home: app);
|
|
}
|
|
|
|
for (final cupertino in [false, true]) {
|
|
final host = cupertino ? 'Cupertino' : 'Material';
|
|
|
|
testWidgets('$host: phone bar spans the width minus its margins', (
|
|
tester,
|
|
) async {
|
|
await setSize(tester, const Size(390, 844));
|
|
await tester.pumpWidget(shell(cupertino: cupertino));
|
|
final rect = tester.getRect(pill());
|
|
expect(rect.left, 16);
|
|
expect(rect.right, 390 - 16);
|
|
expect(rect.bottom, 844 - 16);
|
|
expect(find.byType(NavigationRail), findsNothing);
|
|
});
|
|
|
|
testWidgets('$host: wide bar hugs its tabs at the right edge, content '
|
|
'keeps the width and taps beside the bar reach it', (tester) async {
|
|
taps = 0;
|
|
await setSize(tester, const Size(1200, 800));
|
|
await tester.pumpWidget(shell(cupertino: cupertino));
|
|
final rect = tester.getRect(pill());
|
|
expect(rect.right, 1200 - 16);
|
|
expect(rect.bottom, 800 - 16);
|
|
expect(rect.width, lessThan(1200 * 0.6));
|
|
expect(rect.width, greaterThan(5 * 72));
|
|
// No rail or sidebar: the content starts at the left edge.
|
|
expect(find.byType(NavigationRail), findsNothing);
|
|
expect(find.byType(CupertinoListTile), findsNothing);
|
|
expect(tester.getRect(find.byKey(const Key('content'))).left, 0);
|
|
// Beside the bar, at the bar's height, the content takes the tap.
|
|
await tester.tapAt(Offset(rect.left - 40, rect.center.dy));
|
|
await tester.pump();
|
|
expect(taps, 1);
|
|
// On the bar, the tab takes it.
|
|
await tester.tap(find.byKey(const ValueKey('shell.destination.chat')));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Chat — Not implemented'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('$host: content learns the bar height as bottom padding', (
|
|
tester,
|
|
) async {
|
|
for (final size in const [Size(390, 844), Size(1200, 800)]) {
|
|
await setSize(tester, size);
|
|
await tester.pumpWidget(shell(cupertino: cupertino));
|
|
await tester.pump();
|
|
final rect = tester.getRect(pill());
|
|
// The content's bottom padding clears the whole bar and its margin.
|
|
expect(
|
|
contentBottomPadding,
|
|
moreOrLessEquals(size.height - rect.top, epsilon: 0.5),
|
|
reason: '$size',
|
|
);
|
|
}
|
|
});
|
|
|
|
testWidgets('$host: resizing moves the bar without remounting content', (
|
|
tester,
|
|
) async {
|
|
taps = 0;
|
|
await setSize(tester, const Size(390, 844));
|
|
await tester.pumpWidget(shell(cupertino: cupertino));
|
|
await tester.tap(find.byKey(const Key('content')));
|
|
await tester.pump();
|
|
expect(find.text('taps 1'), findsOneWidget);
|
|
final state = tester.state(find.byType(StatefulBuilder));
|
|
|
|
tester.view.physicalSize = const Size(1200, 800);
|
|
await tester.pump();
|
|
expect(tester.getRect(pill()).right, 1200 - 16);
|
|
expect(tester.getRect(pill()).width, lessThan(1200 * 0.6));
|
|
expect(tester.state(find.byType(StatefulBuilder)), same(state));
|
|
|
|
tester.view.physicalSize = const Size(390, 844);
|
|
await tester.pump();
|
|
expect(tester.getRect(pill()).width, 390 - 32);
|
|
expect(tester.state(find.byType(StatefulBuilder)), same(state));
|
|
});
|
|
|
|
testWidgets('$host: the bar respects the bottom safe area', (tester) async {
|
|
await setSize(tester, const Size(390, 844));
|
|
tester.view.padding = const FakeViewPadding(bottom: 34);
|
|
await tester.pumpWidget(shell(cupertino: cupertino));
|
|
expect(tester.getRect(pill()).bottom, 844 - 34);
|
|
});
|
|
|
|
testWidgets('$host: the selected tab is marked selected for assistive '
|
|
'technology', (tester) async {
|
|
final semantics = tester.ensureSemantics();
|
|
await setSize(tester, const Size(1200, 800));
|
|
await tester.pumpWidget(shell(cupertino: cupertino));
|
|
await tester.tap(find.byKey(const ValueKey('shell.destination.runs')));
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
tester.getSemantics(barText('Runs')),
|
|
isSemantics(isSelected: true),
|
|
);
|
|
expect(
|
|
tester.getSemantics(barText('Chat')),
|
|
isNot(isSemantics(isSelected: true)),
|
|
);
|
|
semantics.dispose();
|
|
});
|
|
}
|
|
|
|
testWidgets('Cupertino bar builds no Material widget', (tester) async {
|
|
await setSize(tester, const Size(1200, 800));
|
|
await tester.pumpWidget(shell(cupertino: true));
|
|
expect(
|
|
find.descendant(
|
|
of: find.byType(FloatingDestinationBar),
|
|
matching: find.byWidgetPredicate(
|
|
(widget) =>
|
|
widget is Material ||
|
|
widget is NavigationBar ||
|
|
widget is InkWell,
|
|
),
|
|
),
|
|
findsNothing,
|
|
);
|
|
});
|
|
|
|
testWidgets('phone at 320 with 2x text does not overflow', (tester) async {
|
|
for (final cupertino in [false, true]) {
|
|
await setSize(tester, const Size(320, 568));
|
|
tester.platformDispatcher.textScaleFactorTestValue = 2;
|
|
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
|
|
await tester.pumpWidget(shell(cupertino: cupertino));
|
|
await tester.pumpAndSettle();
|
|
expect(tester.takeException(), isNull);
|
|
expect(tester.getRect(pill()).width, 320 - 32);
|
|
}
|
|
});
|
|
}
|