test(app): cover the pipeline graph tab expand entry
This commit is contained in:
@@ -0,0 +1,161 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/graph/viewport/graph_expanded_view.dart';
|
||||
import 'package:pipelines_app/features/graph/viewport/graph_viewport.dart';
|
||||
import 'package:pipelines_app/features/graph/widgets/definition_graph_view.dart';
|
||||
import 'package:pipelines_app/features/graph/widgets/graph_stage_node.dart';
|
||||
import 'package:pipelines_app/features/graph/widgets/stage_definition_view.dart';
|
||||
import 'package:pipelines_app/features/pipelines/screen.dart';
|
||||
import 'package:pipelines_app/features/pipelines/widgets/pipeline_graph_tab.dart';
|
||||
|
||||
import 'fixtures.dart';
|
||||
import 'test_helpers.dart';
|
||||
|
||||
Finder _node(String key) => find.byWidgetPredicate(
|
||||
(widget) => widget is GraphStageNode && widget.node.key == key,
|
||||
);
|
||||
|
||||
Finder _inExpanded(Finder finder) =>
|
||||
find.descendant(of: find.byType(GraphExpandedView), matching: finder);
|
||||
|
||||
/// Taps a node, panning the stock canvas first when the node starts offscreen.
|
||||
Future<void> _tapNode(WidgetTester tester, Finder node) async {
|
||||
final viewport = tester.getRect(find.byType(InteractiveViewer));
|
||||
final rect = tester.getRect(node);
|
||||
if (!viewport.contains(rect.center)) {
|
||||
await tester.drag(
|
||||
find.byType(InteractiveViewer),
|
||||
viewport.center - rect.center,
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
await tester.tap(node);
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
Future<void> _pumpScreen(WidgetTester tester) async {
|
||||
tester.view.physicalSize = const Size(1100, 900);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(home: PipelinesScreen(gateway: gatewayFor(PipelineFixture()))),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Future<void> _openGraphTab(WidgetTester tester, int pipelineId) async {
|
||||
await tester.tap(find.byKey(Key('pipeline-row-$pipelineId')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.ensureVisible(find.text('Graph'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Graph'));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
/// Selects the stage the detail panel keeps for the pinned graph.
|
||||
Future<void> _selectInline(WidgetTester tester, String key) async {
|
||||
await _tapNode(tester, _node(key));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(StageDefinitionView), findsOneWidget);
|
||||
await tester.pageBack();
|
||||
await tester.pumpAndSettle();
|
||||
expect(tester.widget<GraphStageNode>(_node(key)).selected, isTrue);
|
||||
}
|
||||
|
||||
GraphViewport _inlineViewport(WidgetTester tester) =>
|
||||
tester.widget<GraphViewport>(
|
||||
find.descendant(
|
||||
of: find.byType(PipelineGraphTab),
|
||||
matching: find.byType(GraphViewport),
|
||||
),
|
||||
);
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'expand opens the measured canvas with the pinned graph and selection',
|
||||
(tester) async {
|
||||
await _pumpScreen(tester);
|
||||
await _openGraphTab(tester, 1);
|
||||
await _selectInline(tester, 'review');
|
||||
|
||||
final inline = _inlineViewport(tester);
|
||||
await tester.tap(find.byKey(const Key('graph-expand')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(GraphExpandedView), findsOneWidget);
|
||||
final expanded = tester.widget<GraphExpandedView>(
|
||||
find.byType(GraphExpandedView),
|
||||
);
|
||||
expect(expanded.contentSize, inline.contentSize);
|
||||
expect(expanded.selectedStage, 'review');
|
||||
expect(find.text(definitionGraphExpandedTitle), findsOneWidget);
|
||||
// Both stages of the pinned reply are drawn full screen, with the
|
||||
// tab's selection still marked.
|
||||
expect(_inExpanded(_node('review')), findsOneWidget);
|
||||
expect(_inExpanded(_node('publish')), findsOneWidget);
|
||||
expect(
|
||||
tester.widget<GraphStageNode>(_inExpanded(_node('review'))).selected,
|
||||
isTrue,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('a tap in the expanded canvas updates the returned selection', (
|
||||
tester,
|
||||
) async {
|
||||
await _pumpScreen(tester);
|
||||
await _openGraphTab(tester, 1);
|
||||
await _selectInline(tester, 'review');
|
||||
|
||||
await tester.tap(find.byKey(const Key('graph-expand')));
|
||||
await tester.pumpAndSettle();
|
||||
await _tapNode(tester, _inExpanded(_node('publish')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// The pinned definition page opens for the node activated full screen.
|
||||
expect(
|
||||
tester
|
||||
.widget<StageDefinitionView>(find.byType(StageDefinitionView))
|
||||
.stageKey,
|
||||
'publish',
|
||||
);
|
||||
await tester.pageBack();
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
tester.widget<GraphStageNode>(_inExpanded(_node('publish'))).selected,
|
||||
isTrue,
|
||||
);
|
||||
|
||||
await tester.tap(find.byKey(const Key('graph-expanded-close')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(GraphExpandedView), findsNothing);
|
||||
expect(tester.widget<GraphStageNode>(_node('publish')).selected, isTrue);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
|
||||
testWidgets('closing leaves the inline graph where it was', (tester) async {
|
||||
await _pumpScreen(tester);
|
||||
await _openGraphTab(tester, 1);
|
||||
await _selectInline(tester, 'publish');
|
||||
|
||||
final inlineController = tester
|
||||
.widget<InteractiveViewer>(find.byType(InteractiveViewer))
|
||||
.transformationController!;
|
||||
final before = Matrix4.copy(inlineController.value);
|
||||
final inlineRect = tester.getRect(_node('publish'));
|
||||
|
||||
await tester.tap(find.byKey(const Key('graph-expand')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('graph-expanded-close')));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(GraphExpandedView), findsNothing);
|
||||
expect(tester.widget<GraphStageNode>(_node('publish')).selected, isTrue);
|
||||
expect(tester.getRect(_node('publish')), inlineRect);
|
||||
expect(inlineController.value.storage, orderedEquals(before.storage));
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user