152 lines
5.4 KiB
Dart
152 lines
5.4 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/glass_pill.dart';
|
|
|
|
/// While a tab shows its list beside an open item, the shell's destination
|
|
/// bar floats over the list pane only: it never covers the item, and the
|
|
/// item's own bottom control (a composer) owns the pane's bottom edge.
|
|
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')),
|
|
],
|
|
),
|
|
);
|
|
|
|
Widget shell({
|
|
required bool cupertino,
|
|
bool split = true,
|
|
double textScale = 1,
|
|
}) {
|
|
final app = AdaptiveShell(
|
|
cupertino: cupertino,
|
|
destination: AppDestination.chat,
|
|
destinationBodies: {
|
|
AppDestination.chat: (_) => split
|
|
? ListDetailPanes(list: listBody(), detail: 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.byType(GlassPill),
|
|
)
|
|
.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 over the '
|
|
'list pane and the composer owns the detail bottom', (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);
|
|
expect(pill.right, lessThanOrEqualTo(list.right));
|
|
expect(pill.left, greaterThanOrEqualTo(list.left));
|
|
expect(pill.overlaps(body), isFalse, reason: 'no overlap with detail');
|
|
expect(pill.bottom, closeTo(800 - kFloatingBarMargin, 0.5));
|
|
|
|
// The detail keeps only the system inset (none here): its composer
|
|
// reaches the bottom edge, below the level of the shell's pill.
|
|
final composer = tester.getRect(find.byKey(const Key('composer')));
|
|
expect(composer.bottom, 800);
|
|
expect(composer.left, body.left);
|
|
expect(composer.top, greaterThan(pill.top));
|
|
|
|
// The list still clears the bar.
|
|
final listContext = tester.element(find.byKey(const Key('list')));
|
|
expect(
|
|
MediaQuery.paddingOf(listContext).bottom,
|
|
greaterThanOrEqualTo(pill.height),
|
|
);
|
|
});
|
|
}
|
|
|
|
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 spans the phone', (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.left, closeTo(kFloatingBarMargin, 0.5));
|
|
expect(pill.right, closeTo(390 - kFloatingBarMargin, 0.5));
|
|
});
|
|
|
|
for (final width in [600.0, 840.0]) {
|
|
testWidgets('$host $width split at 2x: the narrow list pane bar lays '
|
|
'out without overflow', (tester) async {
|
|
await setSize(tester, Size(width, 800));
|
|
await tester.pumpWidget(shell(cupertino: cupertino, textScale: 2));
|
|
await tester.pump();
|
|
await tester.pump();
|
|
expect(tester.takeException(), isNull);
|
|
final list = tester.getRect(
|
|
find.byKey(const ValueKey('list-detail-list')),
|
|
);
|
|
expect(destinationPill(tester).right, lessThanOrEqualTo(list.right));
|
|
});
|
|
}
|
|
}
|
|
}
|