Skip to content

Commit

Permalink
Add unit testing workflow (#34)
Browse files Browse the repository at this point in the history
Closes #33.
  • Loading branch information
fujidaiti authored Feb 22, 2024
1 parent 3fa8352 commit 7f6dcbb
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
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,
);
});
});
}

0 comments on commit 7f6dcbb

Please sign in to comment.