diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..582deeb --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,29 @@ +name: Test + +on: + push: + branches: [ main ] + pull_request: + +permissions: + contents: read + +env: + FLUTTER_SDK_VERSION: '3.32.2' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dart-lang/setup-dart@v1 + with: + sdk: '3.7.0' + - uses: subosito/flutter-action@v2 + with: + cache: true + flutter-version: ${{ env.FLUTTER_SDK_VERSION }} + - name: Install dependencies + run: flutter pub get + - name: Run tests + run: flutter test --no-pub diff --git a/test/project_test.dart b/test/project_test.dart new file mode 100644 index 0000000..365f1a6 --- /dev/null +++ b/test/project_test.dart @@ -0,0 +1,42 @@ +import 'package:flutter_test/flutter_test.dart'; +import 'package:flutter_google_datastore/database.dart'; + +void main() { + group('Project model', () { + test('validRow returns true when required fields present', () { + final row = { + 'id': 1, + 'projectId': 'proj', + }; + expect(Project.validRow(row), isTrue); + }); + + test('validRow returns false when required fields missing', () { + final row = { + 'id': 1, + }; + expect(Project.validRow(row), isFalse); + }); + + test('fromRow maps values correctly', () { + final now = DateTime.now().toUtc(); + final row = { + 'id': 10, + 'created': now.toIso8601String(), + 'updated': now.toIso8601String(), + 'endpointUrl': 'http://localhost', + 'projectId': 'myproj', + 'authMode': 'none', + 'googleCliProfile': 'default', + }; + + final project = Project.fromRow(row); + expect(project.id, 10); + expect(project.endpointUrl, 'http://localhost'); + expect(project.projectId, 'myproj'); + expect(project.authMode, 'none'); + expect(project.googleCliProfile, 'default'); + expect(project.key, 'myproj @ http://localhost'); + }); + }); +} diff --git a/test/widget_test.dart b/test/widget_test.dart deleted file mode 100644 index 5b7df24..0000000 --- a/test/widget_test.dart +++ /dev/null @@ -1,30 +0,0 @@ -// This is a basic Flutter widget test. -// -// To perform an interaction with a widget in your test, use the WidgetTester -// utility in the flutter_test package. For example, you can send tap and scroll -// gestures. You can also use WidgetTester to find child widgets in the widget -// tree, read text, and verify that the values of widget properties are correct. - -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'package:flutter_google_datastore/main.dart'; - -void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { - // Build our app and trigger a frame. - await tester.pumpWidget(const MyApp()); - - // Verify that our counter starts at 0. - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); - - // Tap the '+' icon and trigger a frame. - await tester.tap(find.byIcon(Icons.add)); - await tester.pump(); - - // Verify that our counter has incremented. - expect(find.text('0'), findsNothing); - expect(find.text('1'), findsOneWidget); - }); -}