Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some WoltModalSheet tests #35

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 128 additions & 1 deletion test/wolt_modal_sheet_test.dart
Original file line number Diff line number Diff line change
@@ -1 +1,128 @@
void main() {}
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:wolt_modal_sheet/wolt_modal_sheet.dart';

void main() {
group('Creating sheet', () {
testWidgets('WoltModalSheet.show opens a sheet', (tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Center(
child: Builder(
builder: (context) {
return ElevatedButton(
onPressed: () {
WoltModalSheet.show(
context: context,
pageListBuilder: (context) {
return <WoltModalSheetPage>[
WoltModalSheetPage.withSingleChild(
child: const Text('Wolt modal sheet page'),
),
];
},
);
},
child: const Text('Open sheet'),
);

}
),
)
),
),
);

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

expect(find.text('Wolt modal sheet page'), findsOneWidget);
});

testWidgets('Empty pageListBuilder throws an error', (tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Center(
child: Builder(
builder: (context) {
return ElevatedButton(
onPressed: () {
WoltModalSheet.show(
context: context,
pageListBuilder: (context) {
return <WoltModalSheetPage>[];
},
);
},
child: const Text('Open sheet'),
);
}
),
)
),
),
);

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

expect(tester.takeException(), isNotNull);
});
});

testWidgets('WoltModalSheet.modalTypeBuilder defaults', (tester) async {
const Size wideSize = Size(800.0, 600.0);
const Size narrowSize = Size(300.0, 600.0);

addTearDown(tester.view.reset);
tester.view.physicalSize = wideSize;
tester.view.devicePixelRatio = 1.0;

await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Center(
child: Builder(
builder: (context) {
return ElevatedButton(
onPressed: () {
WoltModalSheet.show(
context: context,
pageListBuilder: (context) {
return <WoltModalSheetPage>[
WoltModalSheetPage.withSingleChild(
child: const Text('Wolt modal sheet page'),
),
];
},
);
},
child: const Text('Open sheet'),
);
}
),
)
),
),
);

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

Finder sheetMaterial = find.byType(Material).last;

// The default modalTypeBuilder should be a dialog on wide screens.
expect(tester.getSize(sheetMaterial), const Size(320.0, 160.0));
expect(tester.getTopLeft(sheetMaterial), const Offset(240.0, 220.0));

// Configure to show the narrow layout.
tester.view.physicalSize = narrowSize;
await tester.pumpAndSettle();

// The default modalTypeBuilder should be a bottom sheet on narrow screens.
expect(tester.getSize(sheetMaterial), const Size(300.0, 160.0));
expect(tester.getTopLeft(sheetMaterial), const Offset(0.0, 440.0));
});
}