192 lines
6.0 KiB
Dart
192 lines
6.0 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
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/changes/changes.dart';
|
|
import 'package:pipelines_app/features/changes/widgets/visit_pager.dart';
|
|
import 'package:pipelines_app/features/runs/data/runs_repository.dart';
|
|
import 'package:pipelines_app/features/runs/ui/run_detail_view.dart';
|
|
import 'package:pipelines_app/features/runs/ui/runs_controller.dart';
|
|
|
|
import '../../changes/fixtures.dart';
|
|
|
|
enum _Platform { material, cupertino }
|
|
|
|
class _FakeGateway implements ApiGateway {
|
|
_FakeGateway(this.detail);
|
|
final JsonMap detail;
|
|
|
|
@override
|
|
Stream<JsonMap> get frames => const Stream<JsonMap>.empty();
|
|
|
|
@override
|
|
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
|
if (type != 'get_run') throw UnsupportedError(type);
|
|
return Future.value({'run_detail': detail});
|
|
}
|
|
}
|
|
|
|
JsonMap _run({
|
|
JsonMap? fileChanges,
|
|
String status = 'succeeded',
|
|
String stepStatus = 'completed',
|
|
}) => {
|
|
'id': 9,
|
|
'title': 'Wiring run',
|
|
'name': 'release',
|
|
'status': status,
|
|
'steps': [
|
|
stepFixture(
|
|
stage: 'implementer',
|
|
sequence: 1,
|
|
status: stepStatus,
|
|
fileChanges: fileChanges,
|
|
),
|
|
stepFixture(
|
|
stage: 'reviewer',
|
|
sequence: 2,
|
|
status: stepStatus,
|
|
fileChanges: null,
|
|
),
|
|
],
|
|
};
|
|
|
|
Future<void> _pumpDetail(
|
|
WidgetTester tester,
|
|
_Platform platform,
|
|
RunsController controller,
|
|
ApiGateway gateway,
|
|
) async {
|
|
tester.view.physicalSize = const Size(500, 1200);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.reset);
|
|
final view = RunDetailView(
|
|
controller: controller,
|
|
gateway: gateway,
|
|
onBack: () {},
|
|
);
|
|
await tester.pumpWidget(
|
|
platform == _Platform.material
|
|
? MaterialApp(home: Scaffold(body: view))
|
|
: CupertinoApp(
|
|
// The real host chooses Cupertino on iOS/macOS; state that platform
|
|
// without mutating the global debug override, as the Changes tests do.
|
|
builder: (context, app) => Theme(
|
|
data: ThemeData(platform: TargetPlatform.iOS),
|
|
child: app!,
|
|
),
|
|
home: CupertinoPageScaffold(child: view),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
void main() {
|
|
for (final platform in _Platform.values) {
|
|
testWidgets(
|
|
'${platform.name}: Changes opens the recorded files, diff and returns',
|
|
(tester) async {
|
|
final gateway = _FakeGateway(
|
|
_run(
|
|
fileChanges: captureFixture(
|
|
files: [
|
|
fileChangeFixture(
|
|
path: 'lib/feature.dart',
|
|
patch: multiHunkPatch,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
final controller = RunsController(RunsRepository(gateway));
|
|
addTearDown(controller.dispose);
|
|
await controller.select(9);
|
|
await _pumpDetail(tester, platform, controller, gateway);
|
|
|
|
await tester.ensureVisible(
|
|
find.byKey(const ValueKey('run-detail-tab-changes')),
|
|
);
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.tap(find.byKey(const ValueKey('run-detail-tab-changes')));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('Changes'), findsOneWidget);
|
|
expect(find.text('lib/feature.dart'), findsOneWidget);
|
|
expect(
|
|
find.text('1 file changed · +2 -2 · capture incomplete'),
|
|
findsOneWidget,
|
|
);
|
|
// The tab is the final state: each path once, no visit pages.
|
|
expect(find.byKey(ChangesVisitPager.nextKey), findsNothing);
|
|
|
|
await tester.tap(
|
|
find.byKey(const ValueKey('change-final-lib/feature.dart')),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
final rendered = tester
|
|
.widgetList<RichText>(find.byType(RichText))
|
|
.map((rich) => rich.text.toPlainText())
|
|
.join('\n');
|
|
expect(rendered, contains('+ added line'));
|
|
expect(rendered, contains('- removed line'));
|
|
|
|
if (platform == _Platform.material) {
|
|
await tester.tap(find.byTooltip('Close diff'));
|
|
} else {
|
|
await tester.tap(find.byIcon(CupertinoIcons.xmark));
|
|
}
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('lib/feature.dart'), findsOneWidget);
|
|
|
|
// Changes is a tab: Summary is one tap away and the run stays open.
|
|
final summaryTab = find.byKey(const ValueKey('run-detail-tab-summary'));
|
|
await tester.ensureVisible(summaryTab);
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(summaryTab);
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Wiring run'), findsOneWidget);
|
|
expect(
|
|
find.byKey(const ValueKey('run-detail-tab-changes')),
|
|
findsOneWidget,
|
|
);
|
|
expect(find.text('lib/feature.dart'), findsNothing);
|
|
},
|
|
);
|
|
|
|
testWidgets(
|
|
'${platform.name}: an unavailable capture keeps its gap wording',
|
|
(tester) async {
|
|
final diagnostic =
|
|
'Workspace snapshot unavailable; changes could not be compared.';
|
|
final gateway = _FakeGateway(
|
|
_run(
|
|
fileChanges: captureFixture(
|
|
status: 'unavailable',
|
|
diagnostic: diagnostic,
|
|
),
|
|
),
|
|
);
|
|
final controller = RunsController(RunsRepository(gateway));
|
|
addTearDown(controller.dispose);
|
|
await controller.select(9);
|
|
await _pumpDetail(tester, platform, controller, gateway);
|
|
|
|
await tester.ensureVisible(
|
|
find.byKey(const ValueKey('run-detail-tab-changes')),
|
|
);
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.tap(find.byKey(const ValueKey('run-detail-tab-changes')));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Changes · capture unavailable'), findsOneWidget);
|
|
expect(find.text(diagnostic), findsWidgets);
|
|
expect(find.text(emptyCaptureDetail), findsNothing);
|
|
expect(find.text('No changes observed'), findsNothing);
|
|
},
|
|
);
|
|
}
|
|
}
|