Skip to content

Commit

Permalink
Add PopScope tests (#236)
Browse files Browse the repository at this point in the history
## Description

Added regression tests for #233 and pinned Flutter version to v3.22.3
for development and CI. This downgrade was necessary as tests fail with
Flutter 3.24+ due to a [breaking
change](https://docs.flutter.dev/release/breaking-changes/popscope-with-result),
which caused that issue.

The fix for #233 is not included here as it requires Flutter 3.24+,
while the main branch will use v3.22.3 post-merge. To accommodate this
version disparity, the fix will be implemented in a separate branch,
providing distinct solutions for users of Flutter 3.24+ and 3.22.3 or
earlier.

## Summary (check all that apply)

- [ ] Modified / added code
- [x] Modified / added tests
- [ ] Modified / added examples
- [x] Modified / added others (pubspec.yaml, workflows, etc...)
- [ ] Updated README
- [ ] Contains breaking changes
  - [ ] Created / updated migration guide
- [ ] Incremented version number
  - [ ] Updated CHANGELOG
  • Loading branch information
fujidaiti authored Aug 31, 2024
1 parent 2e98dc0 commit 362f2fd
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .fvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"flutter": "3.22.3"
}
29 changes: 13 additions & 16 deletions .github/workflows/code_check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ jobs:
pull-requests: read
outputs:
flutter-file-changed: ${{ steps.filter.outputs.flutter-file-changed }}
lowest-flutter-version: ${{ steps.flutter-version-constraint.outputs.lowest }}
highest-flutter-version: ${{ steps.flutter-version-constraint.outputs.highest }}
flutter-lower-bound: ${{ steps.flutter-version-constraint.outputs.lower-bound }}
flutter-upper-bound: ${{ steps.flutter-version-constraint.outputs.upper-bound }}
steps:
- uses: actions/checkout@v4

Expand All @@ -32,22 +32,19 @@ jobs:
- name: Get Flutter SDK version constraint
id: flutter-version-constraint
# Extract the lower bound from pubspec.yaml and the upper bound from .fvmrc
run: |
sdk_constraint=$(cat pubspec.yaml | yq .environment.flutter)
lowest=$(echo "$sdk_constraint" | grep -oP '(?<=\>=)[0-9]+\.[0-9]+\.[0-9]+' | head -1)
highest=$(echo "$sdk_constraint" | grep -oP '(?<=\<)[0-9]+\.[0-9]+\.[0-9]+' | head -1)
# If no upper bound is specified, default to 3.x
if [ -z "$highest" ]; then
highest="3.x"
fi
echo "lowest=$lowest" >> "$GITHUB_OUTPUT"
echo "highest=$highest" >> "$GITHUB_OUTPUT"
lower_bound=$(echo "$sdk_constraint" | grep -oP '(?<=\>=)[0-9]+\.[0-9]+\.[0-9]+' | head -1)
upper_bound=$(cat .fvmrc | jq -r .flutter)
echo "lower-bound=$lower_bound" >> "$GITHUB_OUTPUT"
echo "upper-bound=$upper_bound" >> "$GITHUB_OUTPUT"
- name: Print output values
run: |
echo "flutter-file-changed=${{ steps.filter.outputs.flutter-file-changed }}"
echo "lowest-flutter-version=${{ steps.flutter-version-constraint.outputs.lowest }}"
echo "highest-flutter-version=${{ steps.flutter-version-constraint.outputs.highest }}"
echo "flutter-lower-bound=${{ steps.flutter-version-constraint.outputs.lower-bound }}"
echo "flutter-upper-bound=${{ steps.flutter-version-constraint.outputs.upper-bound }}"
analysis:
needs: setup
Expand All @@ -56,8 +53,8 @@ jobs:
strategy:
matrix:
flutter-version:
- ${{ needs.setup.outputs.lowest-flutter-version }}
- ${{ needs.setup.outputs.highest-flutter-version }}
- ${{ needs.setup.outputs.flutter-lower-bound }}
- ${{ needs.setup.outputs.flutter-upper-bound }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -87,8 +84,8 @@ jobs:
strategy:
matrix:
flutter-version:
- ${{ needs.setup.outputs.lowest-flutter-version }}
- ${{ needs.setup.outputs.highest-flutter-version }}
- ${{ needs.setup.outputs.flutter-lower-bound }}
- ${{ needs.setup.outputs.flutter-upper-bound }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ migrate_working_dir/
.dart_tool/
.packages
build/

# FVM Version Cache
.fvm/
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dart.flutterSdkPath": ".fvm/versions/3.22.3"
}
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.9.3"
version: "0.9.4"
source_span:
dependency: transitive
description:
Expand Down
75 changes: 75 additions & 0 deletions test/modal/modal_sheet_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,79 @@ void main() {
},
);
});

// Regression test for https://github.com/fujidaiti/smooth_sheets/issues/233
group('PopScope test', () {
late bool isOnPopInvokedCalled;
late Widget testWidget;

setUp(() {
isOnPopInvokedCalled = false;
testWidget = MaterialApp(
home: Builder(
builder: (context) {
return Scaffold(
body: Center(
child: ElevatedButton(
onPressed: () {
Navigator.push(
context,
ModalSheetRoute<dynamic>(
swipeDismissible: true,
builder: (context) {
return DraggableSheet(
child: PopScope(
canPop: false,
onPopInvoked: (didPop) {
isOnPopInvokedCalled = true;
},
child: Container(
key: const Key('sheet'),
color: Colors.white,
width: double.infinity,
height: 200,
),
),
);
},
),
);
},
child: const Text('Open modal'),
),
),
);
},
),
);
});

testWidgets(
'PopScope.onPopInvoked should be called when tap on barrier',
(tester) async {
await tester.pumpWidget(testWidget);
await tester.tap(find.text('Open modal'));
await tester.pumpAndSettle();
await tester.tap(find.byType(AnimatedModalBarrier));
await tester.pumpAndSettle();
expect(isOnPopInvokedCalled, isTrue);
},
);

testWidgets(
'PopScope.onPopInvoked should be called when swipe to dismiss',
(tester) async {
await tester.pumpWidget(testWidget);
await tester.tap(find.text('Open modal'));
await tester.pumpAndSettle();
await tester.fling(
find.byKey(const Key('sheet')),
const Offset(0, 200),
2000,
);
await tester.pumpAndSettle();
expect(isOnPopInvokedCalled, isTrue);
},
);
});
}

0 comments on commit 362f2fd

Please sign in to comment.