Skip to content

Commit

Permalink
Find relevant scrollable and add nested test (preliminary)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmolnar committed Jan 17, 2025
1 parent a3dc413 commit 7f6f623
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 6 deletions.
18 changes: 13 additions & 5 deletions lib/src/act/act.dart
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ class Act {
final WidgetSelector<Scrollable> scrollable =
spot<Scrollable>().withChild(dragStart).last();

final scrollableElement = scrollable.snapshotElement();

// Every scrollable contains a Listener handling the touch events.
// We only care about the size and location of the RenderObject.
final scrollableSizedRenderBox =
Expand Down Expand Up @@ -416,13 +418,19 @@ class Act {
dragCount++;
}

// Take scrollable where element is scrollable element
// TODO Handle case when this is null
final scrollableWidget = spot<Scrollable>()
.snapshot()
.discovered
.firstOrNullWhere((e) => e.element == scrollableElement)
?.element
.widget;

// found the widget in the tree, now do a final drag to make sure it is
// within the scrollable's viewport entirely
final spotScrollableBoundsAfterDrag = spot<Scrollable>()
.withChild(dragTarget)
.last()
.spot<Listener>()
.first();
final spotScrollableBoundsAfterDrag = spotWidget(scrollableWidget!);

final scrollableSizedRenderBoxAfterDrag =
spotScrollableBoundsAfterDrag.snapshotRenderBox();
final viewportGlobalPosition =
Expand Down
41 changes: 40 additions & 1 deletion test/act/act_drag_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/widgets.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:spot/spot.dart';

Expand Down Expand Up @@ -98,6 +99,44 @@ void dragTests() {
secondItem.doesNotExist();
},
);

testWidgets(
'Finds and taps widget in nested Column',
(tester) async {
timeline.mode = TimelineMode.always;
await tester.pumpWidget(
const MaterialApp(
localizationsDelegates: [
DefaultMaterialLocalizations.delegate,
DefaultCupertinoLocalizations.delegate,
DefaultWidgetsLocalizations.delegate,
],
home: DragUntilVisibleInDialogWidget(),
),
);

final dialogButton = spotText('Open Dialog')..existsOnce();
await act.tap(dialogButton);

await tester.pump(const Duration(milliseconds: 500));
await tester.pump(const Duration(milliseconds: 500));
await tester.pump(const Duration(milliseconds: 500));
await tester.pumpAndSettle();

final firstItem =
spotText('ParentIndex: 0, Item at index: 3', exact: true);
final secondItem =
spotText('ParentIndex: 2, Item at index: 4', exact: true);
await act.dragUntilVisible(
dragStart: firstItem,
dragTarget: secondItem,
);
await tester.pump(const Duration(milliseconds: 500));
await tester.pump(const Duration(milliseconds: 500));
await tester.pumpAndSettle();
await act.tap(secondItem);
},
);
});

group('Horizontal Drag', () {
Expand Down

0 comments on commit 7f6f623

Please sign in to comment.