Files
pipelines/app/test/features/pipelines/pipelines_screen_test.dart
T

157 lines
5.1 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.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('id 1 · v2 · 2 stages'), findsOneWidget);
expect(find.text('updated 17 Oct 21:26'), findsOneWidget);
expect(find.text('1 schedule'), findsOneWidget);
expect(find.textContaining('run 42'), findsOneWidget);
expect(find.text('no runs recorded'), findsOneWidget);
expect(find.text('Select a pipeline.'), 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'), findsNWidgets(2));
expect(gateway.callsOf('get_pipeline').single.fields, {
'pipeline_id': 1,
'version': 2,
});
await tester.tap(find.text('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.text('v1'), findsOneWidget);
expect(find.text('v2'), findsNWidgets(2));
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.text('Source'));
await tester.pump();
expect(
selectableText(
'name: Alpha review\nstages:\n review:\n type: model\n'
'# selected version 1',
),
findsOneWidget,
);
await tester.tap(find.text('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('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<ListTile>(
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('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);
});
}