Files
pipelines/app/test/features/pipelines/pipelines_screen_test.dart
T
alan a9fdedc1ea Pipeline page: Runs and Run as icon buttons; Runs works on phones
On a phone the pipeline detail was pushed above the shell, so Runs switched to
the Runs tab underneath it and seemed to do nothing; the detail now shows only
while the Pipelines tab is active. Runs (list) and Run (play) are icon-only
bar actions with their accessible names. Finishes run #230; adds a phone-width
regression test.
2026-11-01 20:41:34 +00:00

274 lines
9.5 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/shell/empty_detail_pane.dart';
import 'package:pipelines_app/ui/layout/app_list_row.dart';
import 'package:pipelines_app/features/pipelines/ui/run_pipeline_wording.dart';
import 'package:pipelines_app/core/api_gateway.dart';
import 'package:pipelines_app/features/pipelines/screen.dart';
import 'fixtures.dart';
import 'test_helpers.dart';
void main() {
testWidgets('list renders web wording, filters, opens detail and source', (
tester,
) async {
final fixture = PipelineFixture();
final gateway = gatewayFor(fixture);
await pumpWide(tester, gateway);
expect(find.text('Pipelines'), findsOneWidget);
expect(find.text('Alpha review'), findsOneWidget);
expect(find.text('2 stages · 1 schedule'), findsOneWidget);
// The row shows the last run's state and age; its number is in the detail.
expect(find.textContaining('run 42'), findsNothing);
// A pipeline that never ran shows its summary alone, with no status dot.
expect(find.text('no runs recorded'), findsNothing);
expect(
find.widgetWithText(
EmptyDetailPane,
'Select a pipeline to open it here.',
),
findsOneWidget,
);
await tester.tap(find.byKey(const Key('pipeline-row-1')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('pipeline-detail')), findsOneWidget);
expect(find.text('hash-alpha'), findsOneWidget);
expect(find.text('id 1 · v2 · 2 stages'), findsOneWidget);
expect(gateway.callsOf('get_pipeline').single.fields, {
'pipeline_id': 1,
'version': 2,
});
await tester.tap(find.byKey(const Key('pipeline-detail-tab-source')));
await tester.pump();
expect(
selectableText('name: Alpha review\nstages:\n review:\n type: model'),
findsOneWidget,
);
});
testWidgets('version rows select an exact version and return to latest', (
tester,
) async {
final fixture = PipelineFixture();
final gateway = gatewayFor(fixture);
await pumpWide(tester, gateway);
await tester.tap(find.byKey(const Key('pipeline-row-1')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('pipeline-version-1')), findsOneWidget);
expect(find.byKey(const Key('pipeline-version-2')), findsOneWidget);
await tester.tap(find.byKey(const Key('pipeline-version-1')));
await tester.pumpAndSettle();
expect(gateway.callsOf('get_pipeline').last.fields, {
'pipeline_id': 1,
'version': 1,
});
expect(find.text('Viewing v1 (latest v2).'), findsOneWidget);
await tester.tap(find.byKey(const Key('pipeline-detail-tab-source')));
await tester.pump();
expect(
selectableText(
'name: Alpha review\nstages:\n review:\n type: model\n'
'# selected version 1',
),
findsOneWidget,
);
await tester.tap(find.byKey(const Key('pipeline-detail-tab-summary')));
await tester.pump();
await tester.tap(find.byKey(const Key('pipeline-latest-version')));
await tester.pumpAndSettle();
expect(gateway.callsOf('get_pipeline').last.fields, {
'pipeline_id': 1,
'version': 0,
});
expect(find.text('Viewing v1 (latest v2).'), findsNothing);
});
testWidgets('detail Runs action names and opens that pipeline filter', (
tester,
) async {
final fixture = PipelineFixture();
final gateway = gatewayFor(fixture);
final opened = <int>[];
tester.view.physicalSize = const Size(1100, 900);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
MaterialApp(
home: PipelinesScreen(gateway: gateway, onViewPipelineRuns: opened.add),
),
);
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('pipeline-row-1')));
await tester.pumpAndSettle();
expect(find.bySemanticsLabel('View runs of Alpha review'), findsOneWidget);
// Run and Runs share the detail pane's actions pill at the top right,
// Runs before the primary Run; nothing floats over the content.
final runs = tester.getRect(find.byKey(const Key('pipeline-view-runs')));
final run = tester.getRect(find.byKey(runPipelineActionKey));
final screen = tester.view.physicalSize / tester.view.devicePixelRatio;
expect(runs.right, lessThanOrEqualTo(run.left));
expect((runs.center.dy - run.center.dy).abs(), lessThan(1));
expect(run.right, greaterThan(screen.width - 40));
expect(run.bottom, lessThan(screen.height / 4));
await tester.tap(find.byKey(const Key('pipeline-view-runs')));
expect(opened, [1]);
});
testWidgets('on a phone the pushed detail never covers another tab', (
tester,
) async {
// Runs switches tabs while the Pipelines screen stays mounted; its pushed
// detail used to stay on top, so tapping Runs seemed to do nothing.
tester.view.physicalSize = const Size(390, 844);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
final gateway = gatewayFor(PipelineFixture());
Widget host({required bool active}) => MaterialApp(
home: PipelinesScreen(
gateway: gateway,
active: active,
onViewPipelineRuns: (_) {},
),
);
await tester.pumpWidget(host(active: true));
await tester.pumpAndSettle();
await tester.tap(find.byKey(const Key('pipeline-row-1')));
await tester.pumpAndSettle();
expect(find.byKey(const Key('pipeline-view-runs')), findsOneWidget);
await tester.pumpWidget(host(active: false));
await tester.pumpAndSettle();
expect(find.byKey(const Key('pipeline-view-runs')), findsNothing);
});
testWidgets('refresh keeps the selected row and its detail', (tester) async {
final fixture = PipelineFixture();
final gateway = gatewayFor(fixture);
await pumpWide(tester, gateway);
await tester.tap(find.byKey(const Key('pipeline-row-1')));
await tester.pumpAndSettle();
await tester.tap(find.byTooltip('Refresh'));
await tester.pumpAndSettle();
final row = tester.widget<AppListRow>(
find.byKey(const Key('pipeline-row-1')),
);
expect(row.selected, isTrue);
expect(find.byKey(const Key('pipeline-detail')), findsOneWidget);
expect(gateway.callsOf('get_pipeline').length, greaterThanOrEqualTo(2));
});
testWidgets('refresh token keeps the visible pipeline position', (
tester,
) async {
final fixture = PipelineFixture();
final summaries = List.generate(
40,
(index) => pipelineSummary(id: index + 1, name: 'Pipeline ${index + 1}'),
);
final gateway = gatewayFor(fixture, summaries: summaries);
tester.view.physicalSize = const Size(500, 600);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
Future<void> pump(int token) => tester.pumpWidget(
MaterialApp(
home: PipelinesScreen(gateway: gateway, syncToken: token),
),
);
await pump(0);
await tester.pumpAndSettle();
await tester.drag(
find.byKey(const Key('pipeline-list')),
const Offset(0, -600),
);
await tester.pumpAndSettle();
final list = tester.state<ScrollableState>(
find.descendant(
of: find.byKey(const Key('pipeline-list')),
matching: find.byType(Scrollable),
),
);
final offset = list.position.pixels;
await pump(1);
await tester.pumpAndSettle();
final refreshedList = tester.state<ScrollableState>(
find.descendant(
of: find.byKey(const Key('pipeline-list')),
matching: find.byType(Scrollable),
),
);
expect(refreshedList.position.pixels, offset);
expect(find.byKey(const Key('pipeline-row-1')), findsNothing);
});
testWidgets('initial loading is shown until both list reads settle', (
tester,
) async {
final fixture = PipelineFixture();
final list = Completer<JsonMap>();
final runs = Completer<JsonMap>();
final gateway = FakeGateway(
(type, fields) => switch (type) {
'list_pipelines' => list.future,
'list_runs' => runs.future,
_ => errorReply('unexpected $type'),
},
);
await tester.pumpWidget(
MaterialApp(home: PipelinesScreen(gateway: gateway)),
);
await tester.pump();
expect(find.text('Loading pipelines…'), findsOneWidget);
list.complete(pipelineListReply(fixture.summaries));
runs.complete(runListReply(fixture.runs));
await tester.pumpAndSettle();
expect(find.text('Alpha review'), findsOneWidget);
});
testWidgets('embedded framing adds no bar and keeps a content refresh', (
tester,
) async {
final fixture = PipelineFixture();
final gateway = gatewayFor(fixture);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Host bar')),
body: PipelinesScreen(gateway: gateway, embedded: true),
),
),
);
await tester.pumpAndSettle();
expect(find.byType(AppBar), findsOneWidget);
expect(find.text('Host bar'), findsOneWidget);
expect(find.text('Pipelines'), findsNothing);
expect(find.text('Alpha review'), findsOneWidget);
final lists = gateway.callsOf('list_pipelines').length;
await tester.tap(find.byTooltip('Refresh'));
await tester.pumpAndSettle();
expect(gateway.callsOf('list_pipelines').length, lists + 1);
});
}