9532ecddcf
The run-wide header, note, filter and matched-path counter still describe every visit; below them Previous/Next move through the recorded visits in run order without wrapping, and the shown visit keeps its own stage and Visit N heading. A single recorded visit renders no pager.
498 lines
16 KiB
Dart
498 lines
16 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/features/changes/changes.dart';
|
|
import 'package:pipelines_app/features/changes/widgets/visit_pager.dart';
|
|
|
|
import 'fixtures.dart';
|
|
import 'widget_hosts.dart';
|
|
|
|
void main() {
|
|
testWidgets(
|
|
'a missing capture is an evidence gap, not an observed no-change',
|
|
(tester) async {
|
|
await tester.pumpWidget(
|
|
materialHost(ChangesViewer(steps: [stepFixture(fileChanges: null)])),
|
|
);
|
|
expect(find.text('Changes · not recorded for this run'), findsOneWidget);
|
|
expect(find.text('Capture unavailable'), findsOneWidget);
|
|
expect(find.text(missingCaptureDetail), findsOneWidget);
|
|
expect(find.text(emptyCaptureDetail), findsNothing);
|
|
expect(find.text('No changes observed'), findsNothing);
|
|
},
|
|
);
|
|
|
|
testWidgets('a running step with no capture is pending, not unavailable', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(
|
|
materialHost(
|
|
ChangesViewer(
|
|
steps: [stepFixture(status: 'running', fileChanges: null)],
|
|
),
|
|
),
|
|
);
|
|
expect(find.text('Changes · capture pending'), findsOneWidget);
|
|
expect(find.text('Capture pending'), findsOneWidget);
|
|
expect(find.text(pendingCaptureDetail), findsOneWidget);
|
|
expect(find.text('Capture unavailable'), findsNothing);
|
|
});
|
|
|
|
testWidgets('a differently cased running status agrees with the header', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(
|
|
materialHost(
|
|
ChangesViewer(
|
|
steps: [stepFixture(status: 'Running', fileChanges: null)],
|
|
),
|
|
),
|
|
);
|
|
expect(find.text('Changes · capture pending'), findsOneWidget);
|
|
expect(find.text('Capture pending'), findsOneWidget);
|
|
expect(find.text('Capture unavailable'), findsNothing);
|
|
});
|
|
|
|
testWidgets('an empty complete capture says the workspace was unchanged', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(
|
|
materialHost(
|
|
ChangesViewer(steps: [stepFixture(fileChanges: captureFixture())]),
|
|
),
|
|
);
|
|
expect(find.text('Changes · no changes observed'), findsOneWidget);
|
|
expect(find.text('No changes observed'), findsOneWidget);
|
|
expect(find.text(emptyCaptureDetail), findsOneWidget);
|
|
expect(find.text(missingCaptureDetail), findsNothing);
|
|
});
|
|
|
|
testWidgets('an unavailable capture never claims there were no changes', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(
|
|
materialHost(
|
|
ChangesViewer(
|
|
steps: [
|
|
stepFixture(
|
|
fileChanges: captureFixture(
|
|
status: 'unavailable',
|
|
diagnostic:
|
|
'Workspace snapshot unavailable; changes could not be '
|
|
'compared.',
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
expect(find.text('Changes · capture unavailable'), findsOneWidget);
|
|
expect(find.textContaining('Workspace snapshot unavailable'), findsWidgets);
|
|
expect(find.text(emptyCaptureDetail), findsNothing);
|
|
});
|
|
|
|
testWidgets('stage/visit pages keep partial status, counters and scope', (
|
|
tester,
|
|
) async {
|
|
final diagnostic = 'Excluded protected files.';
|
|
await tester.pumpWidget(
|
|
materialHost(
|
|
ChangesViewer(
|
|
steps: [
|
|
stepFixture(
|
|
stage: 'implementer',
|
|
fileChanges: captureFixture(
|
|
status: 'partial',
|
|
skipped: 1,
|
|
omitted: 2,
|
|
diagnostic: diagnostic,
|
|
files: [
|
|
fileChangeFixture(path: 'lib/a.dart', patch: multiHunkPatch),
|
|
],
|
|
),
|
|
),
|
|
stepFixture(
|
|
stage: 'reviewer',
|
|
sequence: 2,
|
|
status: 'failed',
|
|
fileChanges: null,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
// The run-wide aggregate still counts the file this visit recorded.
|
|
expect(find.textContaining('1 file changed'), findsOneWidget);
|
|
expect(find.text('implementer'), findsOneWidget);
|
|
expect(find.text('Visit 1 · completed'), findsOneWidget);
|
|
expect(
|
|
find.text(
|
|
'partial (1 files), 1 skipped, 2 omitted · Excluded protected files.',
|
|
),
|
|
findsOneWidget,
|
|
);
|
|
expect(
|
|
find.text('Scope: Git tracked and nonignored files in the run directory'),
|
|
findsOneWidget,
|
|
);
|
|
// The second visit is its own page, not a second section.
|
|
expect(find.text('reviewer'), findsNothing);
|
|
expect(find.text(missingCaptureDetail), findsNothing);
|
|
|
|
await tester.tap(find.byKey(ChangesVisitPager.nextKey));
|
|
await tester.pump();
|
|
|
|
expect(find.text('implementer'), findsNothing);
|
|
expect(find.text('reviewer'), findsOneWidget);
|
|
// The reviewer's first visit is Visit 1, not the run-wide step ordinal 2.
|
|
expect(find.text('Visit 1 · failed'), findsOneWidget);
|
|
expect(find.text('Visit 2 · failed'), findsNothing);
|
|
expect(find.text(missingCaptureDetail), findsOneWidget);
|
|
});
|
|
|
|
testWidgets(
|
|
'repeated stages number their own visits and honour control.visit',
|
|
(tester) async {
|
|
await tester.pumpWidget(
|
|
materialHost(
|
|
ChangesViewer(
|
|
steps: [
|
|
stepFixture(
|
|
stage: 'implementer',
|
|
sequence: 1,
|
|
fileChanges: captureFixture(),
|
|
),
|
|
stepFixture(
|
|
stage: 'reviewer',
|
|
sequence: 2,
|
|
fileChanges: captureFixture(),
|
|
),
|
|
stepFixture(
|
|
stage: 'implementer',
|
|
sequence: 3,
|
|
fileChanges: captureFixture(),
|
|
),
|
|
stepFixture(
|
|
stage: 'reviewer',
|
|
sequence: 4,
|
|
visit: 6,
|
|
fileChanges: captureFixture(),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
// Pages are in run order; each stage numbers its own visits, so the
|
|
// run-wide step ordinals (1-4) must not leak into the label.
|
|
expect(find.text('Visit 1 · completed'), findsOneWidget);
|
|
expect(find.text('Visit 2 · completed'), findsNothing);
|
|
expect(find.text('Visit 6 · completed'), findsNothing);
|
|
|
|
await tester.tap(find.byKey(ChangesVisitPager.nextKey));
|
|
await tester.pump();
|
|
// The reviewer's first recorded visit is Visit 1 too.
|
|
expect(find.text('reviewer'), findsOneWidget);
|
|
expect(find.text('Visit 1 · completed'), findsOneWidget);
|
|
|
|
await tester.tap(find.byKey(ChangesVisitPager.nextKey));
|
|
await tester.pump();
|
|
expect(find.text('implementer'), findsOneWidget);
|
|
expect(find.text('Visit 2 · completed'), findsOneWidget);
|
|
|
|
await tester.tap(find.byKey(ChangesVisitPager.nextKey));
|
|
await tester.pump();
|
|
// The resumed reviewer visit records control.visit 6.
|
|
expect(find.text('reviewer'), findsOneWidget);
|
|
expect(find.text('Visit 6 · completed'), findsOneWidget);
|
|
expect(find.text('Visit 3 · completed'), findsNothing);
|
|
expect(find.text('Visit 4 · completed'), findsNothing);
|
|
},
|
|
);
|
|
|
|
testWidgets('filtering changed filenames keeps matching rows and says so', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(
|
|
materialHost(
|
|
ChangesViewer(
|
|
steps: [
|
|
stepFixture(
|
|
fileChanges: captureFixture(
|
|
files: [
|
|
fileChangeFixture(path: 'assets/logo.bin', binary: true),
|
|
fileChangeFixture(
|
|
path: 'lib/feature.dart',
|
|
patch: multiHunkPatch,
|
|
),
|
|
fileChangeFixture(
|
|
path: 'docs/notes.md',
|
|
kind: 'added',
|
|
patch: '@@ -0,0 +1 @@\n+x',
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
expect(find.text('assets/logo.bin'), findsOneWidget);
|
|
expect(find.text('lib/feature.dart'), findsOneWidget);
|
|
|
|
await tester.enterText(find.byType(TextField), 'feature');
|
|
await tester.pump();
|
|
expect(find.text('lib/feature.dart'), findsOneWidget);
|
|
expect(find.text('assets/logo.bin'), findsNothing);
|
|
expect(find.text('docs/notes.md'), findsNothing);
|
|
expect(find.text('1 of 3 changed paths match'), findsOneWidget);
|
|
|
|
await tester.enterText(find.byType(TextField), 'nothing-here');
|
|
await tester.pump();
|
|
expect(
|
|
find.text('No changed filenames match "nothing-here".'),
|
|
findsOneWidget,
|
|
);
|
|
|
|
await tester.enterText(find.byType(TextField), '');
|
|
await tester.pump();
|
|
expect(find.text('assets/logo.bin'), findsOneWidget);
|
|
expect(find.textContaining('changed files match'), findsNothing);
|
|
});
|
|
|
|
testWidgets(
|
|
'opening a file shows the rendered patch and copies exact bytes',
|
|
(tester) async {
|
|
final calls = <MethodCall>[];
|
|
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(SystemChannels.platform, (call) async {
|
|
if (call.method == 'Clipboard.setData') calls.add(call);
|
|
return null;
|
|
});
|
|
addTearDown(
|
|
() => TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
|
.setMockMethodCallHandler(SystemChannels.platform, null),
|
|
);
|
|
await tester.pumpWidget(
|
|
materialHost(
|
|
ChangesViewer(
|
|
steps: [
|
|
stepFixture(
|
|
fileChanges: captureFixture(
|
|
files: [
|
|
fileChangeFixture(
|
|
path: 'lib/feature.dart',
|
|
patch: multiHunkPatch,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
|
|
await tester.tap(find.byKey(const ValueKey('change-1-lib/feature.dart')));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(Dialog), findsOneWidget);
|
|
expect(find.text('Rendered'), findsOneWidget);
|
|
expect(find.text('Raw patch'), findsOneWidget);
|
|
final rendered = tester
|
|
.widgetList<RichText>(find.byType(RichText))
|
|
.map((rich) => rich.text.toPlainText())
|
|
.join('\n');
|
|
expect(rendered, contains('+ new line'));
|
|
expect(rendered, contains('- old line'));
|
|
expect(rendered, contains('@@ -20,3 +21,2 @@'));
|
|
|
|
await tester.tap(find.text('Raw patch'));
|
|
await tester.pumpAndSettle();
|
|
final raw = tester.widget<Text>(find.text(multiHunkPatch));
|
|
expect(raw.data, multiHunkPatch);
|
|
expect(raw.softWrap, isFalse);
|
|
|
|
await tester.tap(find.text('Copy patch'));
|
|
await tester.pump();
|
|
expect(calls, hasLength(1));
|
|
expect(calls.single.arguments, {'text': multiHunkPatch});
|
|
expect(find.text('Copied'), findsOneWidget);
|
|
|
|
await tester.tap(find.byTooltip('Close diff'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(Dialog), findsNothing);
|
|
},
|
|
);
|
|
|
|
testWidgets('binary, truncated and mode-only entries explain the missing diff', (
|
|
tester,
|
|
) async {
|
|
await tester.pumpWidget(
|
|
materialHost(
|
|
SingleChildScrollView(
|
|
child: Column(
|
|
children: [
|
|
SizedBox(
|
|
height: 300,
|
|
child: FileDiffViewer(
|
|
file: FileChange(
|
|
path: 'assets/logo.bin',
|
|
kind: ChangeKind.modified,
|
|
binary: true,
|
|
),
|
|
),
|
|
),
|
|
SizedBox(
|
|
height: 300,
|
|
child: FileDiffViewer(
|
|
file: FileChange(
|
|
path: 'logs/build.log',
|
|
kind: ChangeKind.modified,
|
|
patch: '@@ -1 +1 @@\n-a\n+b',
|
|
truncated: true,
|
|
),
|
|
),
|
|
),
|
|
SizedBox(
|
|
height: 300,
|
|
child: FileDiffViewer(
|
|
file: FileChange(
|
|
path: 'scripts/run.sh',
|
|
kind: ChangeKind.modified,
|
|
beforeMode: '0644',
|
|
afterMode: '0755',
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
expect(find.text(binaryDiffMessage), findsOneWidget);
|
|
expect(find.text(truncatedPatchNote), findsOneWidget);
|
|
expect(
|
|
find.text(
|
|
"Only the file's mode changed (0644→0755); the server recorded no text "
|
|
'diff.',
|
|
),
|
|
findsOneWidget,
|
|
);
|
|
final copyButtons = <TextButton>[];
|
|
for (var index = 0; index < 3; index++) {
|
|
final button = find
|
|
.ancestor(
|
|
of: find.text('Copy patch').at(index),
|
|
matching: find.byWidgetPredicate((widget) => widget is TextButton),
|
|
)
|
|
.first;
|
|
copyButtons.add(tester.widget<TextButton>(button));
|
|
}
|
|
// Binary and mode-only have nothing to copy; the truncated patch still can.
|
|
expect(
|
|
copyButtons.where((button) => button.onPressed == null),
|
|
hasLength(2),
|
|
);
|
|
expect(
|
|
copyButtons.where((button) => button.onPressed != null),
|
|
hasLength(1),
|
|
);
|
|
});
|
|
|
|
testWidgets(
|
|
'Cupertino uses native list tiles, search field and segmented control',
|
|
(tester) async {
|
|
await tester.pumpWidget(
|
|
cupertinoHost(
|
|
ChangesViewer(
|
|
steps: [
|
|
stepFixture(
|
|
fileChanges: captureFixture(
|
|
files: [
|
|
fileChangeFixture(
|
|
path: 'lib/feature.dart',
|
|
patch: multiHunkPatch,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
expect(find.byType(CupertinoListTile), findsOneWidget);
|
|
expect(find.byType(CupertinoSearchTextField), findsOneWidget);
|
|
expect(find.byType(TextField), findsNothing);
|
|
|
|
await tester.tap(find.byKey(const ValueKey('change-1-lib/feature.dart')));
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
find.byType(CupertinoSlidingSegmentedControl<DiffForm>),
|
|
findsOneWidget,
|
|
);
|
|
expect(find.text('Rendered'), findsOneWidget);
|
|
expect(find.text('Raw patch'), findsOneWidget);
|
|
|
|
await tester.tap(find.byIcon(CupertinoIcons.xmark));
|
|
await tester.pumpAndSettle();
|
|
expect(
|
|
find.byType(CupertinoSlidingSegmentedControl<DiffForm>),
|
|
findsNothing,
|
|
);
|
|
},
|
|
);
|
|
|
|
testWidgets('narrow viewport and large text keep every control reachable', (
|
|
tester,
|
|
) async {
|
|
tester.view.physicalSize = const Size(320, 720);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.reset);
|
|
await tester.pumpWidget(
|
|
materialHost(
|
|
ChangesViewer(
|
|
steps: [
|
|
stepFixture(
|
|
fileChanges: captureFixture(
|
|
files: [
|
|
fileChangeFixture(
|
|
path: 'lib/a_rather_long_feature_file_name.dart',
|
|
patch: multiHunkPatch,
|
|
),
|
|
fileChangeFixture(path: 'assets/logo.bin', binary: true),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
scaler: const TextScaler.linear(2),
|
|
),
|
|
);
|
|
expect(tester.takeException(), isNull);
|
|
expect(
|
|
find.text('lib/a_rather_long_feature_file_name.dart'),
|
|
findsOneWidget,
|
|
);
|
|
|
|
// The viewer itself at the same narrow width and 2x text: every action
|
|
// stays on screen and the patch body scrolls instead of overflowing.
|
|
await tester.pumpWidget(
|
|
materialHost(
|
|
FileDiffViewer(
|
|
file: FileChange(
|
|
path: 'lib/a_rather_long_feature_file_name.dart',
|
|
kind: ChangeKind.modified,
|
|
patch: multiHunkPatch,
|
|
),
|
|
),
|
|
scaler: const TextScaler.linear(2),
|
|
),
|
|
);
|
|
expect(tester.takeException(), isNull);
|
|
// The host is too narrow for a two-segment control at 2x, so the same form
|
|
// selection is offered through the native menu instead.
|
|
expect(find.byTooltip('Diff form'), findsOneWidget);
|
|
expect(find.text('Copy patch'), findsOneWidget);
|
|
expect(find.byTooltip('Close diff'), findsOneWidget);
|
|
});
|
|
}
|