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 unit testing workflow #34

Merged
merged 6 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions .github/workflows/code_check.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Code Checking
on:
push:
branches: main
pull_request:
paths:
- "**.dart"

jobs:
code-check:
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/unit_testing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Unit Testing

on:
pull_request:
paths:
- "package/lib/**"
- "package/test/**"

jobs:
test:
name: Unit Tests
runs-on: ubuntu-latest
permissions:
contents: read
actions: read
checks: write
defaults:
run:
working-directory: package/
env:
FLUTTER_TEST_REPORT: ${{github.workspace}}/flutter-test-report.json
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
channel: stable
flutter-version: 3.x

- name: Flutter version
run: flutter --version

- name: Get dependencies
run: flutter pub get

- name: Run unit tests
run: flutter test --file-reporter="json:${{ env.FLUTTER_TEST_REPORT }}"

- name: Write test report
uses: dorny/test-reporter@v1
if: success() || failure()
with:
name: Test Report
path: ${{ env.FLUTTER_TEST_REPORT }}
reporter: flutter-json
55 changes: 55 additions & 0 deletions package/test/foundation/sheet_physics_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,59 @@ void main() {
);
});
});

group('$SnapToNearestEdge', () {
late SnapToNearestEdge behaviorUnderTest;

setUp(() {
behaviorUnderTest = const SnapToNearestEdge(minFlingSpeed: 50);
});

test('snaps to the nearest edge if the velocity is small enough', () {
final positionAtNearTopEdge = _referenceSheetMetrics.copyWith(
pixels: _referenceSheetMetrics.maxPixels - 50,
);
final positionAtNearBottomEdge = _referenceSheetMetrics.copyWith(
pixels: _referenceSheetMetrics.minPixels + 50,
);

expect(
behaviorUnderTest.findSnapPixels(0, positionAtNearTopEdge),
moreOrLessEquals(_referenceSheetMetrics.maxPixels),
);
expect(
behaviorUnderTest.findSnapPixels(0, positionAtNearBottomEdge),
moreOrLessEquals(_referenceSheetMetrics.minPixels),
);
});

test('is aware of fling gesture direction', () {
expect(
behaviorUnderTest.findSnapPixels(50, _positionAtBottomEdge),
moreOrLessEquals(_referenceSheetMetrics.maxPixels),
);
expect(
behaviorUnderTest.findSnapPixels(-50, _positionAtTopEdge),
moreOrLessEquals(_referenceSheetMetrics.minPixels),
);
});

test('is disabled if position is out of bounds', () {
final overDraggedPosition = _referenceSheetMetrics.copyWith(
pixels: _referenceSheetMetrics.maxPixels + 10,
);
final underDraggedPosition = _referenceSheetMetrics.copyWith(
pixels: _referenceSheetMetrics.minPixels - 10,
);

expect(
behaviorUnderTest.findSnapPixels(0, overDraggedPosition),
isNull,
);
expect(
behaviorUnderTest.findSnapPixels(0, underDraggedPosition),
isNull,
);
});
});
}