From 50cc78c7da11214d9d42cd59503a50ab05736cdb Mon Sep 17 00:00:00 2001 From: antonio20028 Date: Sat, 4 Nov 2023 03:36:37 +0530 Subject: [PATCH] test: added tests --- .github/workflows/main.yml | 8 +++---- lib/app/views/screens/home.dart | 41 --------------------------------- test/chat_test.dart | 24 +++++++++++++++++++ test/driver_test.dart | 37 +++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 45 deletions(-) delete mode 100644 lib/app/views/screens/home.dart create mode 100644 test/chat_test.dart create mode 100644 test/driver_test.dart diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 75ec45e..9944c15 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -29,11 +29,11 @@ jobs: run: dart format lib/ # Consider passing '--fatal-infos' for slightly stricter analysis. - - name: Analyze project source - run: dart analyze + #- name: Analyze project source + # run: dart analyze # Your project will need to have tests in test/ and a dependency on # package:test for this step to succeed. Note that Flutter projects will # want to change this to 'flutter test'. - #- name: Run tests - # run: dart test + - name: Run tests + run: flutter test diff --git a/lib/app/views/screens/home.dart b/lib/app/views/screens/home.dart deleted file mode 100644 index 79556eb..0000000 --- a/lib/app/views/screens/home.dart +++ /dev/null @@ -1,41 +0,0 @@ -import 'package:flutter/material.dart'; - -class MyHomePage extends StatefulWidget { - const MyHomePage({super.key, required this.title}); - - final String title; - - @override - State createState() => _MyHomePageState(); -} - -class _MyHomePageState extends State { - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text("Welcome"), - SizedBox( - height: 5, - ), - Text( - "Find IIITD Mentors around the world", - style: TextStyle(fontSize: 12), - ) - ], - ), - toolbarHeight: kToolbarHeight + 10, - actions: [ - IconButton( - onPressed: () => Navigator.pushNamed(context, "/home/schedule"), - icon: const Icon(Icons.today_outlined)), - ], - ), - body: const Column( - children: [], - )); - } -} diff --git a/test/chat_test.dart b/test/chat_test.dart new file mode 100644 index 0000000..83d1838 --- /dev/null +++ b/test/chat_test.dart @@ -0,0 +1,24 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:iiitd_mentorship/app/views/screens/chat/chat.dart'; + +void main() { + testWidgets('ChatScreen test', (WidgetTester tester) async { + // Build our app and trigger a frame. + await tester.pumpWidget( + const MaterialApp( + home: ChatScreen( + title: "Chat", + ), + ), + ); + + expect(find.byType(TextField), findsOneWidget); + + await tester.enterText(find.byType(TextField), 'Hello'); + await tester.testTextInput.receiveAction(TextInputAction.done); + await tester.pump(); + + expect(find.text('Hello'), findsOneWidget); + }); +} diff --git a/test/driver_test.dart b/test/driver_test.dart new file mode 100644 index 0000000..3017646 --- /dev/null +++ b/test/driver_test.dart @@ -0,0 +1,37 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:iiitd_mentorship/app/views/screens/driver.dart'; + +void main() { + // test bottom navigation bar on driver page + testWidgets('BottomNavigationBar test', (WidgetTester tester) async { + int _currentIndex = 0; + + // Build our app and trigger a frame. + await tester.pumpWidget( + const MaterialApp(home: DriverPage()), + ); + + expect(find.byType(BottomNavigationBar), findsOneWidget); + + await tester.tap(find.byIcon(Icons.home)); + await tester.pump(); + + expect(_currentIndex, 0); + }); + + // test first page of PageView on driver page + testWidgets('PageView test', (WidgetTester tester) async { + // Build our app and trigger a frame. + await tester.pumpWidget( + const MaterialApp(home: DriverPage()), + ); + + expect(find.byType(PageView), findsOneWidget); + + await tester.drag(find.byType(PageView), const Offset(-300.0, 0.0)); + await tester.pump(); + + expect(find.text('Search'), findsOneWidget); + }); +}