Skip to content

Commit

Permalink
Add widget tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ulusoyca committed Aug 11, 2024
1 parent 2d1c40c commit 81a0ac3
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions test/wolt_modal_sheet_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -277,5 +277,45 @@ void main() {
equals(const Size(524.0, 86.0)),
);
});

testWidgets('getters return the correct page, page index and list of pages',
(tester) async {
const page1Id = 'page1';
const page2Id = 'page2';
final page1 =
WoltModalSheetPage(child: const Text('Page 1'), id: page1Id);
final page2 =
WoltModalSheetPage(child: const Text('Page 2'), id: page2Id);

await tester.pumpWidget(buildSheetWithShow(
pageListBuilder: (_) => [page1, page2],
));

await tester.tap(find.text('Open sheet'));
await tester.pumpAndSettle();

final WoltModalSheetState modal =
WoltModalSheet.of(tester.element(find.text('Page 1')));

expect(modal.pages.length, 2);
expect(modal.pages[0].id, page1Id);
expect(modal.pages[1].id, page2Id);
expect(modal.currentPage, page1);
expect(modal.currentPageIndex, 0);
expect(modal.isAtFirstPage, isTrue);
expect(modal.isAtLastPage, isFalse);

// Go to next page
modal.showNext();
await tester.pumpAndSettle();

expect(modal.pages.length, 2);
expect(modal.pages[0].id, page1Id);
expect(modal.pages[1].id, page2Id);
expect(modal.currentPage, page2);
expect(modal.currentPageIndex, 1);
expect(modal.isAtFirstPage, isFalse);
expect(modal.isAtLastPage, isTrue);
});
});
}

0 comments on commit 81a0ac3

Please sign in to comment.