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 d66c541 commit 81d6f94
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions test/wolt_modal_sheet_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,60 @@ void main() {
expect(tester.getTopLeft(sheetMaterial), const Offset(0.0, 504.0));
expect(tester.getTopRight(sheetMaterial), Offset(viewSize.width, 504.0));
}, skip: true); // [Intended]: This is skipped due to a bug in the framework.

group('WoltModalSheet page getters', () {
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(
MaterialApp(
home: Scaffold(body: Center(
child: Builder(builder: (context) {
return ElevatedButton(
onPressed: () {
WoltModalSheet.show(
context: context,
pageListBuilder: (_) => [page1, page2],
);
},
child: const Text('Open sheet'),
);
}),
)),
),
);

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 81d6f94

Please sign in to comment.