4c4dcbbd14
Rows lead with a circular harness avatar, put the time beside the title, collapse metadata into one muted model · folder line and trail the actions menu. Unread chats are bold with an accent time and dot, running chats badge their avatar, and Star moves into the menu.
279 lines
11 KiB
Dart
279 lines
11 KiB
Dart
import 'dart:ui' show Tristate;
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:pipelines_app/features/chat/screen.dart';
|
|
import 'package:pipelines_app/features/pipelines/screen.dart';
|
|
import 'package:pipelines_app/features/runs/screen.dart';
|
|
import 'package:pipelines_app/shell/adaptive_shell.dart';
|
|
import 'package:pipelines_app/shell/destination.dart';
|
|
import 'package:pipelines_app/ui/theme/app_theme.dart';
|
|
|
|
import '../features/pipelines/fixtures.dart';
|
|
|
|
void main() {
|
|
for (final cupertino in [false, true]) {
|
|
for (final brightness in Brightness.values) {
|
|
for (final width in [640.0, 840.0, 1280.0]) {
|
|
for (final scale in [1.0, 2.0]) {
|
|
testWidgets('shared body-priority panes and selected rows: $cupertino '
|
|
'$brightness at $width @${scale}x', (tester) async {
|
|
SharedPreferences.setMockInitialValues({});
|
|
tester.view.physicalSize = Size(width, 900);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.reset);
|
|
tester.platformDispatcher.textScaleFactorTestValue = scale;
|
|
addTearDown(
|
|
tester.platformDispatcher.clearTextScaleFactorTestValue,
|
|
);
|
|
final fixture = PipelineFixture();
|
|
final gateway = FakeGateway(
|
|
(type, fields) => switch (type) {
|
|
'list_pipelines' => pipelineListReply(fixture.summaries),
|
|
'get_pipeline' => pipelineDetailReply(
|
|
fixture.detailFor(
|
|
fields['pipeline_id'] as int,
|
|
fields['version'] as int,
|
|
)!,
|
|
),
|
|
'list_runs' => {
|
|
'runs': [
|
|
for (final id in [1, 2])
|
|
{
|
|
'id': id,
|
|
'title': 'Run item $id',
|
|
'status': 'succeeded',
|
|
},
|
|
],
|
|
},
|
|
'get_run' => {
|
|
'run_detail': {
|
|
'id': fields['run_id'],
|
|
'title': 'Run item ${fields['run_id']}',
|
|
'status': 'succeeded',
|
|
'input': {'prompt': 'Recorded input'},
|
|
},
|
|
},
|
|
'chat_sessions' => {
|
|
'chat_sessions': [
|
|
{
|
|
'id': 'a',
|
|
'title': 'Chat item a',
|
|
'backend': 'claude',
|
|
'model': 'claude-opus',
|
|
'mode': 'auto',
|
|
'mode_name': 'Auto',
|
|
},
|
|
{
|
|
'id': 'b',
|
|
'title': 'Chat item b',
|
|
'backend': 'claude',
|
|
'model': 'claude-opus',
|
|
'mode': 'auto',
|
|
'mode_name': 'Auto',
|
|
},
|
|
],
|
|
},
|
|
'chat_messages' => {
|
|
'chat_history': {'messages': []},
|
|
},
|
|
_ => {},
|
|
},
|
|
);
|
|
final shell = AdaptiveShell(
|
|
cupertino: cupertino,
|
|
destinationBodies: {
|
|
AppDestination.pipelines: (_) =>
|
|
PipelinesScreen(gateway: gateway, embedded: true),
|
|
AppDestination.runs: (_) => RunsScreen(gateway: gateway),
|
|
AppDestination.chat: (_) => ChatScreen(gateway: gateway),
|
|
},
|
|
);
|
|
await tester.pumpWidget(
|
|
cupertino
|
|
? CupertinoApp(
|
|
theme: CupertinoThemeData(brightness: brightness),
|
|
home: shell,
|
|
)
|
|
: MaterialApp(
|
|
theme: brightness == Brightness.dark
|
|
? appDarkTheme()
|
|
: appLightTheme(),
|
|
home: shell,
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
final paneWidths = <double>[];
|
|
final bodyWidths = <double>[];
|
|
for (final destination in ['Pipelines', 'Runs', 'Chat']) {
|
|
if (destination != 'Pipelines') {
|
|
await tester.tap(find.text(destination).first);
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
tester.takeException(),
|
|
isNull,
|
|
reason: '$destination list',
|
|
);
|
|
}
|
|
final list = find.byKey(const ValueKey('list-detail-list'));
|
|
final detail = find.byKey(const ValueKey('list-detail-body'));
|
|
expect(list, findsOneWidget);
|
|
expect(detail, findsOneWidget);
|
|
final before = tester.getSize(list).width;
|
|
final bodyBefore = tester.getSize(detail).width;
|
|
paneWidths.add(before);
|
|
bodyWidths.add(bodyBefore);
|
|
expect(bodyBefore, greaterThanOrEqualTo(width * 0.5));
|
|
expect(bodyBefore, lessThanOrEqualTo(width * 0.6));
|
|
expect(bodyBefore, greaterThan(before));
|
|
final rowKeys = switch (destination) {
|
|
'Pipelines' => ['pipeline-row-1', 'pipeline-row-2'],
|
|
'Runs' => ['run-row-1', 'run-row-2'],
|
|
_ => ['chat-row-a', 'chat-row-b'],
|
|
};
|
|
for (final key in rowKeys) {
|
|
final target = find.byKey(ValueKey(key));
|
|
// In a narrow Cupertino list the row center can be a star/menu
|
|
// control. Open the chat through its title, not a trailing action.
|
|
final opener = destination == 'Chat'
|
|
? find.descendant(
|
|
of: target,
|
|
matching: find.text('Chat item ${key.split('-').last}'),
|
|
)
|
|
: target;
|
|
await tester.ensureVisible(opener);
|
|
await tester.tap(opener);
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
tester.takeException(),
|
|
isNull,
|
|
reason: '$destination after opening $key',
|
|
);
|
|
expect(tester.getSize(list).width, closeTo(before, 0.01));
|
|
expect(tester.getSize(detail).width, closeTo(bodyBefore, 0.01));
|
|
expect(
|
|
tester.state<NavigatorState>(find.byType(Navigator)).canPop(),
|
|
isFalse,
|
|
);
|
|
for (final rowKey in rowKeys) {
|
|
final row = find.byKey(ValueKey(rowKey));
|
|
expect(
|
|
row,
|
|
findsOneWidget,
|
|
reason: 'the list must remain visible',
|
|
);
|
|
final selected = rowKey == key;
|
|
expect(
|
|
tester.getSemantics(row).flagsCollection.isSelected ==
|
|
Tristate.isTrue,
|
|
selected,
|
|
reason: '$destination: $rowKey after opening $key',
|
|
);
|
|
final context = tester.element(row);
|
|
if (cupertino) {
|
|
final color = destination == 'Runs'
|
|
? tester.widget<CupertinoButton>(row).color
|
|
: tester.widget<CupertinoListTile>(row).backgroundColor;
|
|
expect(
|
|
color,
|
|
selected
|
|
? CupertinoColors.tertiarySystemFill.resolveFrom(
|
|
context,
|
|
)
|
|
: isNull,
|
|
);
|
|
} else if (destination == 'Runs') {
|
|
final id = rowKey.split('-').last;
|
|
expect(
|
|
tester
|
|
.widget<Material>(
|
|
find.byKey(ValueKey('run-row-surface-$id')),
|
|
)
|
|
.color,
|
|
selected
|
|
? Theme.of(context).colorScheme.secondaryContainer
|
|
: Colors.transparent,
|
|
);
|
|
} else {
|
|
final tile = tester.widget<ListTile>(row);
|
|
expect(tile.selected, selected);
|
|
expect(
|
|
tile.selectedTileColor,
|
|
Theme.of(context).colorScheme.secondaryContainer,
|
|
);
|
|
}
|
|
}
|
|
}
|
|
if (destination == 'Chat') {
|
|
// Starring lives in the row's actions menu.
|
|
final menu = find.byKey(const Key('chat-actions-b'));
|
|
await tester.ensureVisible(menu);
|
|
await tester.tap(menu);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.text('Star'));
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
gateway
|
|
.callsOf('chat_star')
|
|
.last
|
|
.fields['chat_query']['session_id'],
|
|
'b',
|
|
);
|
|
final actions = find.byKey(const Key('chat-actions-b'));
|
|
await tester.ensureVisible(actions);
|
|
await tester.tap(actions);
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Rename…'), findsOneWidget);
|
|
await tester.binding.handlePopRoute();
|
|
await tester.pumpAndSettle();
|
|
}
|
|
// A phone still uses stock page navigation; returning to a wide
|
|
// window must keep the selected item without clearing its route.
|
|
tester.view.physicalSize = const Size(390, 900);
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
tester.state<NavigatorState>(find.byType(Navigator)).canPop(),
|
|
isTrue,
|
|
reason: '$destination should push its selected item on a phone',
|
|
);
|
|
expect(
|
|
find.byKey(const ValueKey('list-detail-list')),
|
|
findsNothing,
|
|
);
|
|
tester.view.physicalSize = Size(width, 900);
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
tester.state<NavigatorState>(find.byType(Navigator)).canPop(),
|
|
isFalse,
|
|
);
|
|
expect(tester.getSize(list).width, closeTo(before, 0.01));
|
|
expect(
|
|
tester
|
|
.getSemantics(find.byKey(ValueKey(rowKeys.last)))
|
|
.flagsCollection
|
|
.isSelected,
|
|
Tristate.isTrue,
|
|
);
|
|
}
|
|
expect(
|
|
paneWidths,
|
|
everyElement(closeTo(paneWidths.first, 0.01)),
|
|
reason: 'Pipelines, Runs and Chat must use identical pane widths',
|
|
);
|
|
expect(tester.takeException(), isNull);
|
|
expect(
|
|
bodyWidths,
|
|
everyElement(closeTo(bodyWidths.first, 0.01)),
|
|
reason:
|
|
'Every destination must share the body-priority sizing policy',
|
|
);
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|