From fd0d67762ed013047b4ade7605c167d50838b581 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Thu, 22 Oct 2026 23:46:37 +0100 Subject: [PATCH] test(app): preserve list position on refresh --- .../pipelines/pipelines_screen_test.dart | 47 +++++++++++++++++++ .../runs/ui/runs_list_refresh_test.dart | 38 +++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/app/test/features/pipelines/pipelines_screen_test.dart b/app/test/features/pipelines/pipelines_screen_test.dart index a4ccc60b..c563040e 100644 --- a/app/test/features/pipelines/pipelines_screen_test.dart +++ b/app/test/features/pipelines/pipelines_screen_test.dart @@ -128,6 +128,53 @@ void main() { expect(gateway.callsOf('get_pipeline').length, greaterThanOrEqualTo(2)); }); + testWidgets('refresh token keeps the visible pipeline position', ( + tester, + ) async { + final fixture = PipelineFixture(); + final summaries = List.generate( + 40, + (index) => pipelineSummary(id: index + 1, name: 'Pipeline ${index + 1}'), + ); + final gateway = gatewayFor(fixture, summaries: summaries); + tester.view.physicalSize = const Size(500, 600); + tester.view.devicePixelRatio = 1; + addTearDown(tester.view.resetPhysicalSize); + addTearDown(tester.view.resetDevicePixelRatio); + + Future pump(int token) => tester.pumpWidget( + MaterialApp( + home: PipelinesScreen(gateway: gateway, syncToken: token), + ), + ); + + await pump(0); + await tester.pumpAndSettle(); + await tester.drag( + find.byKey(const Key('pipeline-list')), + const Offset(0, -600), + ); + await tester.pumpAndSettle(); + final list = tester.state( + find.descendant( + of: find.byKey(const Key('pipeline-list')), + matching: find.byType(Scrollable), + ), + ); + final offset = list.position.pixels; + await pump(1); + await tester.pumpAndSettle(); + + final refreshedList = tester.state( + find.descendant( + of: find.byKey(const Key('pipeline-list')), + matching: find.byType(Scrollable), + ), + ); + expect(refreshedList.position.pixels, offset); + expect(find.byKey(const Key('pipeline-row-1')), findsNothing); + }); + testWidgets('initial loading is shown until both list reads settle', ( tester, ) async { diff --git a/app/test/features/runs/ui/runs_list_refresh_test.dart b/app/test/features/runs/ui/runs_list_refresh_test.dart index c523e4c1..6dd1f192 100644 --- a/app/test/features/runs/ui/runs_list_refresh_test.dart +++ b/app/test/features/runs/ui/runs_list_refresh_test.dart @@ -67,4 +67,42 @@ void main() { expect(gateway.listRequests, hasLength(2)); expect(gateway.detailRequests, isEmpty); }); + + testWidgets('refresh keeps the visible run position', (tester) async { + final gateway = _Gateway(); + final runs = List.generate( + 40, + (index) => { + 'id': index + 1, + 'title': 'Run ${index + 1}', + 'status': 'succeeded', + 'created_at': '2026-10-20T12:00:00', + }, + ); + await tester.pumpWidget(_screen(gateway, 0)); + gateway.listRequests.single.complete({'runs': runs}); + await tester.pumpAndSettle(); + + await tester.drag(find.byType(ListView), const Offset(0, -600)); + await tester.pumpAndSettle(); + final list = tester.state( + find.descendant( + of: find.byType(ListView), + matching: find.byType(Scrollable), + ), + ); + final offset = list.position.pixels; + await tester.pumpWidget(_screen(gateway, 1)); + gateway.listRequests.last.complete({'runs': runs}); + await tester.pumpAndSettle(); + + final refreshedList = tester.state( + find.descendant( + of: find.byType(ListView), + matching: find.byType(Scrollable), + ), + ); + expect(refreshedList.position.pixels, offset); + expect(find.text('Run 1'), findsNothing); + }); }