Files
pipelines/app/test/shell/split_destination_bar_test.dart
T
alan 377ff04aaf Show each floating tab as its own round glass button
Replace the single glass pill (host NavigationBar/CupertinoTabBar with one
gliding highlight) with a row of separate circular GlassPill buttons, 52/50 px
with 12/10 px gaps, at the same bottom-right place. The selected button fills
with the host selection tint and cross-fades; each button pops in on its own,
staggered, only when the bar appears or its tabs change; presses sink like the
top bar's. Tab semantics, keys, tooltips and badges are kept; the row shares
one BackdropGroup for its blurs.
2026-11-02 18:43:05 +00:00

227 lines
8.1 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/shell/list_detail.dart';
import 'package:pipelines_app/ui/adaptive/floating_bar_layout.dart';
import 'package:pipelines_app/ui/adaptive/floating_destination_bar.dart';
/// While a tab shows its list beside an open item, the shell's destination
/// bar keeps its place at the bottom right (near the thumb). The item's own
/// bottom control (its tabs, or a composer) floats above it with a gap, and
/// the item's content clears both.
void main() {
Future<void> setSize(WidgetTester tester, Size size) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
}
/// A detail whose composer sits at the bottom, padded by the media inset
/// the way the chat composer is.
Widget composerDetail() => Builder(
builder: (context) => Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: EdgeInsets.only(bottom: MediaQuery.paddingOf(context).bottom),
child: const SizedBox(
key: Key('composer'),
height: 56,
width: double.infinity,
),
),
),
);
Widget listBody() => Builder(
builder: (context) => ListView(
key: const Key('list'),
children: [
for (var index = 0; index < 40; index++)
SizedBox(height: 40, child: Text('row $index')),
],
),
);
/// A detail with its own floating tabs over a list, like run detail.
Widget tabsDetail(bool cupertino) => FloatingBarOverlay(
bar: KeyedSubtree(
key: const Key('detail-tabs'),
child: FloatingDestinationBar(
cupertino: cupertino,
currentIndex: 0,
onTap: (_) {},
items: const [
FloatingDestinationItem(icon: Icon(Icons.summarize), label: 'One'),
FloatingDestinationItem(icon: Icon(Icons.timeline), label: 'Two'),
FloatingDestinationItem(icon: Icon(Icons.inventory), label: 'Three'),
],
),
),
child: Builder(
builder: (context) => ListView(
key: const Key('detail-list'),
children: [
for (var index = 0; index < 40; index++)
SizedBox(height: 40, child: Text('item $index')),
],
),
),
);
Widget shell({
required bool cupertino,
bool split = true,
bool tabs = false,
double textScale = 1,
}) {
final app = AdaptiveShell(
cupertino: cupertino,
destination: AppDestination.chat,
destinationBodies: {
AppDestination.chat: (_) => split
? ListDetailPanes(
list: listBody(),
detail: tabs ? tabsDetail(cupertino) : composerDetail(),
)
: listBody(),
},
);
return MediaQuery(
data: MediaQueryData.fromView(
WidgetsBinding.instance.platformDispatcher.views.first,
).copyWith(textScaler: TextScaler.linear(textScale)),
child: cupertino ? CupertinoApp(home: app) : MaterialApp(home: app),
);
}
Rect destinationPill(WidgetTester tester) => tester.getRect(
find
.ancestor(
of: find.byKey(const ValueKey('shell.destination.chat')).first,
matching: find.byKey(FloatingDestinationBar.rowKey),
)
.first,
);
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
for (final width in [1200.0, 1600.0]) {
testWidgets('$host $width split: the destination bar stays bottom '
'right and the composer floats above it', (tester) async {
await setSize(tester, Size(width, 800));
await tester.pumpWidget(shell(cupertino: cupertino));
await tester.pump();
await tester.pump();
final list = tester.getRect(
find.byKey(const ValueKey('list-detail-list')),
);
final body = tester.getRect(
find.byKey(const ValueKey('list-detail-body')),
);
final pill = destinationPill(tester);
// Compact at the window's right edge, over the detail pane only.
expect(pill.right, closeTo(width - kFloatingBarMargin, 0.5));
expect(pill.bottom, closeTo(800 - kFloatingBarMargin, 0.5));
expect(pill.width, lessThan(body.width / 2));
expect(pill.overlaps(list), isFalse, reason: 'never over the list');
expect(pill.left, greaterThan(body.left));
// The composer's box starts a gap above the shell's pill (the real
// composer pads its pill by another 12 inside that box).
final composer = tester.getRect(find.byKey(const Key('composer')));
expect(composer.left, body.left);
expect(composer.overlaps(pill), isFalse);
expect(pill.top - composer.bottom, closeTo(kStackedBarGap, 0.5));
// The list is not under the bar: it clears only the system inset.
final listContext = tester.element(find.byKey(const Key('list')));
expect(MediaQuery.paddingOf(listContext).bottom, 0);
});
testWidgets('$host $width split: the item tabs float above the '
'destination bar with a gap, and its content clears both', (
tester,
) async {
await setSize(tester, Size(width, 800));
await tester.pumpWidget(shell(cupertino: cupertino, tabs: true));
await tester.pump();
await tester.pump();
final body = tester.getRect(
find.byKey(const ValueKey('list-detail-body')),
);
final pill = destinationPill(tester);
final tabs = tester.getRect(
find
.descendant(
of: find.byKey(const Key('detail-tabs')),
matching: find.byKey(FloatingDestinationBar.rowKey),
)
.first,
);
expect(pill.right, closeTo(width - kFloatingBarMargin, 0.5));
expect(tabs.right, closeTo(width - kFloatingBarMargin, 0.5));
expect(tabs.left, greaterThan(body.left));
expect(tabs.overlaps(pill), isFalse);
expect(pill.top - tabs.bottom, closeTo(kStackedBarGap, 0.5));
// The item's list pads its end clear of both pills.
final listContext = tester.element(
find.byKey(const Key('detail-list')),
);
expect(
MediaQuery.paddingOf(listContext).bottom,
closeTo(800 - tabs.top, 0.5),
);
});
}
testWidgets('$host 1200 unsplit: the bar is compact at the right edge', (
tester,
) async {
await setSize(tester, const Size(1200, 800));
await tester.pumpWidget(shell(cupertino: cupertino, split: false));
await tester.pump();
final pill = destinationPill(tester);
expect(pill.right, closeTo(1200 - kFloatingBarMargin, 0.5));
expect(pill.width, lessThan(1200 * 0.6));
});
testWidgets('$host 390: the bar hugs its tabs at the phone\'s bottom '
'right', (tester) async {
await setSize(tester, const Size(390, 844));
await tester.pumpWidget(shell(cupertino: cupertino, split: false));
await tester.pump();
final pill = destinationPill(tester);
expect(
pill.width,
FloatingDestinationBar.rowWidth(cupertino: cupertino, tabs: 4),
);
expect(pill.right, closeTo(390 - kFloatingBarMargin, 0.5));
});
for (final width in [600.0, 840.0]) {
testWidgets('$host $width split at 2x: both bars lay out over the '
'detail pane without overflow', (tester) async {
await setSize(tester, Size(width, 800));
await tester.pumpWidget(
shell(cupertino: cupertino, tabs: true, textScale: 2),
);
await tester.pump();
await tester.pump();
expect(tester.takeException(), isNull);
final body = tester.getRect(
find.byKey(const ValueKey('list-detail-body')),
);
final pill = destinationPill(tester);
expect(pill.left, greaterThanOrEqualTo(body.left));
expect(pill.right, closeTo(width - kFloatingBarMargin, 0.5));
});
}
}
}