Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pante committed Nov 29, 2024
1 parent d2285c6 commit 7bb3062
Show file tree
Hide file tree
Showing 16 changed files with 215 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/pages/docs/overlay/popover.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const FPopover(
);
```

### `FPopover.tappable()`.
### `FPopover.tappable()`

```dart
const FPopover.tappable(
Expand Down
2 changes: 1 addition & 1 deletion forui/lib/src/widgets/sheet/sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class FSheetStyle with Diagnosticable {
/// Creates a [FSheetStyle].
const FSheetStyle({
required this.backgroundColor,
this.enterDuration = const Duration(milliseconds: 250),
this.enterDuration = const Duration(milliseconds: 200),
this.exitDuration = const Duration(milliseconds: 200),
this.flingVelocity = 700,
this.closeProgressThreshold = 0.5,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
105 changes: 105 additions & 0 deletions forui/test/src/widgets/sheet/modal_sheet_golden_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
@Tags(['golden'])
library;

import 'package:flutter/material.dart';

import 'package:flutter_test/flutter_test.dart';

import 'package:forui/forui.dart';
import '../../test_scaffold.dart';

void main() {
group('FModalSheet', () {
for (final side in Layout.values) {
testWidgets('default - $side', (tester) async {
await tester.pumpWidget(
TestScaffold.app(
child: Builder(
builder: (context) => FButton.icon(
child: FIcon(FAssets.icons.chevronRight),
onPress: () => showFModalSheet(
context: context,
side: side,
builder: (context) => Container(
height: double.infinity,
width: double.infinity,
color: context.theme.colorScheme.background,
child: const Center(child: Text('Sheet')),
),
),
),
),
),
);

await tester.tap(find.byType(FButton));
await tester.pumpAndSettle();

await expectLater(find.byType(TestScaffold), matchesGoldenFile('sheet/modal/default-$side.png'));
});

testWidgets('constrained - $side', (tester) async {
await tester.pumpWidget(
TestScaffold.app(
child: Builder(
builder: (context) => FButton.icon(
child: FIcon(FAssets.icons.chevronRight),
onPress: () => showFModalSheet(
context: context,
side: side,
constraints: const BoxConstraints(maxHeight: 200, maxWidth: 200),
builder: (context) => Container(
height: double.infinity,
width: double.infinity,
color: context.theme.colorScheme.background,
child: const Center(child: Text('Sheet')),
),
),
),
),
),
);

await tester.tap(find.byType(FButton));
await tester.pumpAndSettle();

await expectLater(find.byType(TestScaffold), matchesGoldenFile('sheet/modal/constrained-$side.png'));
});

testWidgets('scrollable - $side', (tester) async {
await tester.pumpWidget(
TestScaffold.app(
child: Builder(
builder: (context) => FButton.icon(
child: FIcon(FAssets.icons.chevronRight),
onPress: () => showFModalSheet(
context: context,
side: side,
mainAxisMaxRatio: null,
builder: (context) => Container(
height: double.infinity,
width: double.infinity,
color: context.theme.colorScheme.background,
child: ListView.builder(
scrollDirection: side.vertical ? Axis.vertical : Axis.horizontal,
itemBuilder: (context, index) => Padding(
padding: const EdgeInsets.all(8.0),
child: Text('Tile $index'),
),
itemCount: 20,
),
),
),
),
),
),
);

await tester.tap(find.byType(FButton));
await tester.pumpAndSettle();

await expectLater(find.byType(TestScaffold), matchesGoldenFile('sheet/modal/scrollable-$side.png'));
});
}
});
}
108 changes: 108 additions & 0 deletions forui/test/src/widgets/sheet/modal_sheet_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import 'package:flutter/material.dart';

import 'package:flutter_test/flutter_test.dart';

import 'package:forui/forui.dart';
import '../../test_scaffold.dart';

void main() {
group('FModalSheet', () {
testWidgets('tap on barrier dismisses', (tester) async {
await tester.pumpWidget(
TestScaffold.app(
child: Builder(
builder: (context) => FButton.icon(
child: FIcon(FAssets.icons.chevronRight),
onPress: () => showFModalSheet(
context: context,
side: Layout.btt,
builder: (context) => Container(
height: double.infinity,
width: double.infinity,
color: context.theme.colorScheme.background,
child: const Center(child: Text('sheet')),
),
),
),
),
),
);

await tester.tap(find.byType(FButton));
await tester.pumpAndSettle(const Duration(seconds: 1));
expect(find.text('sheet'), findsOne);

await tester.tapAt(const Offset(100, 100));
await tester.pumpAndSettle(const Duration(seconds: 1));
expect(find.text('sheet'), findsNothing);
});

for (final (side, offset) in [
(Layout.btt, const Offset(0, 300)),
(Layout.ttb, const Offset(0, -300)),
(Layout.ltr, const Offset(-300, 0)),
(Layout.rtl, const Offset(300, 0)),
]) {
testWidgets('drag to dismiss - $side', (tester) async {
await tester.pumpWidget(
TestScaffold.app(
child: Builder(
builder: (context) => FButton.icon(
child: FIcon(FAssets.icons.chevronRight),
onPress: () => showFModalSheet(
context: context,
side: side,
builder: (context) => Container(
height: double.infinity,
width: double.infinity,
color: context.theme.colorScheme.background,
child: const Center(child: Text('sheet')),
),
),
),
),
),
);

await tester.tap(find.byType(FButton));
await tester.pumpAndSettle(const Duration(seconds: 1));
expect(find.text('sheet'), findsOne);

await tester.drag(find.text('sheet'), offset);
await tester.pumpAndSettle(const Duration(seconds: 1));
expect(find.text('sheet'), findsNothing);
});

testWidgets('drag to dismiss on non-draggable - $side', (tester) async {
await tester.pumpWidget(
TestScaffold.app(
child: Builder(
builder: (context) => FButton.icon(
child: FIcon(FAssets.icons.chevronRight),
onPress: () => showFModalSheet(
context: context,
side: side,
draggable: false,
builder: (context) => Container(
height: double.infinity,
width: double.infinity,
color: context.theme.colorScheme.background,
child: const Center(child: Text('sheet')),
),
),
),
),
),
);

await tester.tap(find.byType(FButton));
await tester.pumpAndSettle(const Duration(seconds: 1));
expect(find.text('sheet'), findsOne);

await tester.drag(find.text('sheet'), offset);
await tester.pumpAndSettle(const Duration(seconds: 1));
expect(find.text('sheet'), findsOne);
});
}
});
}

0 comments on commit 7bb3062

Please sign in to comment.