From f804bafe63c206c60cdabe4ecc8c2bd3a9c555b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Duarte?= Date: Thu, 10 Aug 2023 15:29:34 +0100 Subject: [PATCH 01/13] Update flutter and dart versions and update mockito --- .../controller/local_storage/app_bus_stop_database.dart | 3 +-- uni/lib/view/bug_report/widgets/form.dart | 6 +++--- uni/lib/view/exams/widgets/exam_page_title.dart | 4 ++-- uni/lib/view/restaurant/restaurant_page_view.dart | 4 ++-- uni/lib/view/useful_info/widgets/other_links_card.dart | 6 ++---- uni/lib/view/useful_info/widgets/sigarra_links_card.dart | 4 ++-- uni/pubspec.yaml | 7 ++++--- 7 files changed, 16 insertions(+), 18 deletions(-) diff --git a/uni/lib/controller/local_storage/app_bus_stop_database.dart b/uni/lib/controller/local_storage/app_bus_stop_database.dart index a62476004..fa87d324d 100644 --- a/uni/lib/controller/local_storage/app_bus_stop_database.dart +++ b/uni/lib/controller/local_storage/app_bus_stop_database.dart @@ -38,8 +38,7 @@ class AppBusStopDatabase extends AppDatabase { } final stops = {}; - groupBy(buses, (stop) => (stop! as Map)['stopCode']) - .forEach( + groupBy(buses, (stop) => stop['stopCode']).forEach( (stopCode, busCodeList) => stops[stopCode as String] = BusStopData( configuredBuses: Set.from( busCodeList.map((busEntry) => busEntry['busCode']), diff --git a/uni/lib/view/bug_report/widgets/form.dart b/uni/lib/view/bug_report/widgets/form.dart index ba6748cb6..7a7c0757a 100644 --- a/uni/lib/view/bug_report/widgets/form.dart +++ b/uni/lib/view/bug_report/widgets/form.dart @@ -117,9 +117,9 @@ class BugReportFormState extends State { Widget bugReportTitle(BuildContext context) { return Container( margin: const EdgeInsets.symmetric(vertical: 10), - child: Row( + child: const Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: const [ + children: [ Icon(Icons.bug_report, size: 40), PageTitle(name: 'Bugs e Sugestões', center: false), Icon(Icons.bug_report, size: 40), @@ -172,7 +172,7 @@ class BugReportFormState extends State { value: _selectedBug, onChanged: (value) { setState(() { - _selectedBug = value! as int; + _selectedBug = value!; }); }, isExpanded: true, diff --git a/uni/lib/view/exams/widgets/exam_page_title.dart b/uni/lib/view/exams/widgets/exam_page_title.dart index 2e8592bc4..1ffac8819 100644 --- a/uni/lib/view/exams/widgets/exam_page_title.dart +++ b/uni/lib/view/exams/widgets/exam_page_title.dart @@ -10,9 +10,9 @@ class ExamPageTitle extends StatelessWidget { return Container( padding: const EdgeInsets.fromLTRB(20, 20, 20, 10), alignment: Alignment.center, - child: Row( + child: const Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: const [ + children: [ PageTitle(name: 'Exames', center: false, pad: false), Material(child: ExamFilterMenu()), ], diff --git a/uni/lib/view/restaurant/restaurant_page_view.dart b/uni/lib/view/restaurant/restaurant_page_view.dart index 55b7ad0e7..e45d20730 100644 --- a/uni/lib/view/restaurant/restaurant_page_view.dart +++ b/uni/lib/view/restaurant/restaurant_page_view.dart @@ -134,9 +134,9 @@ class RestaurantDay extends StatelessWidget { return Container( margin: const EdgeInsets.only(top: 10, bottom: 5), key: Key('restaurant-page-day-column-$day'), - child: Column( + child: const Column( mainAxisSize: MainAxisSize.min, - children: const [ + children: [ SizedBox(height: 10), Center( child: Text('Não há informação disponível sobre refeições'), diff --git a/uni/lib/view/useful_info/widgets/other_links_card.dart b/uni/lib/view/useful_info/widgets/other_links_card.dart index 651d614db..ca2051d39 100644 --- a/uni/lib/view/useful_info/widgets/other_links_card.dart +++ b/uni/lib/view/useful_info/widgets/other_links_card.dart @@ -9,10 +9,8 @@ class OtherLinksCard extends GenericExpansionCard { @override Widget buildCardContent(BuildContext context) { - return Column( - children: const [ - LinkButton(title: 'Impressão', link: 'https://print.up.pt') - ], + return const Column( + children: [LinkButton(title: 'Impressão', link: 'https://print.up.pt')], ); } diff --git a/uni/lib/view/useful_info/widgets/sigarra_links_card.dart b/uni/lib/view/useful_info/widgets/sigarra_links_card.dart index 48b5fbe3a..c5e7dcd5b 100644 --- a/uni/lib/view/useful_info/widgets/sigarra_links_card.dart +++ b/uni/lib/view/useful_info/widgets/sigarra_links_card.dart @@ -9,8 +9,8 @@ class SigarraLinksCard extends GenericExpansionCard { @override Widget buildCardContent(BuildContext context) { - return Column( - children: const [ + return const Column( + children: [ LinkButton( title: 'Notícias', link: 'https://sigarra.up.pt/feup/pt/noticias_geral.lista_noticias', diff --git a/uni/pubspec.yaml b/uni/pubspec.yaml index fea80f960..b1a32d213 100644 --- a/uni/pubspec.yaml +++ b/uni/pubspec.yaml @@ -10,8 +10,8 @@ publish_to: 'none' # We do not publish to pub.dev version: 1.5.46+164 environment: - sdk: ">=2.17.1 <3.0.0" - flutter: 3.7.2 + sdk: '>=3.0.0 <4.0.0' + flutter: 3.10.6 # Dependencies specify other packages that the application needs in order to work. # Major versions and critical security upgrades are managed by dependabot, and @@ -59,10 +59,11 @@ dependencies: dev_dependencies: + build_runner: ^2.4.6 flutter_launcher_icons: ^0.13.1 flutter_test: sdk: flutter - mockito: ^5.2.0 + mockito: ^5.4.2 test: any very_good_analysis: ^4.0.0+1 From 1d8aae8fe984c0570f0046a076d2209e0bf141a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Duarte?= Date: Thu, 10 Aug 2023 15:38:49 +0100 Subject: [PATCH 02/13] apply dart fix --- uni/lib/model/providers/lazy/bus_stop_provider.dart | 2 +- uni/lib/model/providers/lazy/lecture_provider.dart | 2 +- uni/lib/view/bug_report/widgets/form.dart | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/uni/lib/model/providers/lazy/bus_stop_provider.dart b/uni/lib/model/providers/lazy/bus_stop_provider.dart index 1c3b81a61..6df3626c1 100644 --- a/uni/lib/model/providers/lazy/bus_stop_provider.dart +++ b/uni/lib/model/providers/lazy/bus_stop_provider.dart @@ -51,7 +51,7 @@ class BusStopProvider extends StateProviderNotifier { Future addUserBusStop(String stopCode, BusStopData stopData) async { if (_configuredBusStops.containsKey(stopCode)) { - (_configuredBusStops[stopCode]!.configuredBuses).clear(); + _configuredBusStops[stopCode]!.configuredBuses.clear(); _configuredBusStops[stopCode]! .configuredBuses .addAll(stopData.configuredBuses); diff --git a/uni/lib/model/providers/lazy/lecture_provider.dart b/uni/lib/model/providers/lazy/lecture_provider.dart index 101e70022..a9f832a5f 100644 --- a/uni/lib/model/providers/lazy/lecture_provider.dart +++ b/uni/lib/model/providers/lazy/lecture_provider.dart @@ -63,7 +63,7 @@ class LectureProvider extends StateProviderNotifier { Session session, Profile profile, ) => - (fetcher?.getLectures(session, profile)) ?? getLectures(session, profile); + fetcher?.getLectures(session, profile) ?? getLectures(session, profile); Future> getLectures(Session session, Profile profile) { return ScheduleFetcherApi() diff --git a/uni/lib/view/bug_report/widgets/form.dart b/uni/lib/view/bug_report/widgets/form.dart index 7a7c0757a..dfa6d8041 100644 --- a/uni/lib/view/bug_report/widgets/form.dart +++ b/uni/lib/view/bug_report/widgets/form.dart @@ -61,7 +61,7 @@ class BugReportFormState extends State { bugDescriptions.forEach( (int key, Tuple2 tup) => - {bugList.add(DropdownMenuItem(value: key, child: Text(tup.item1)))}, + bugList.add(DropdownMenuItem(value: key, child: Text(tup.item1))), ); } From 84e12a3f55362aec3ed921ecad42377a3bfb2341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Duarte?= Date: Thu, 10 Aug 2023 22:03:35 +0100 Subject: [PATCH 03/13] make build.yaml --- build.yaml | 7 + uni/test/integration/src/exams_page_test.dart | 8 +- .../src/exams_page_test.mocks.dart | 382 +++++++++++ .../integration/src/schedule_page_test.dart | 14 +- .../src/schedule_page_test.mocks.dart | 599 ++++++++++++++++++ 5 files changed, 996 insertions(+), 14 deletions(-) create mode 100644 build.yaml create mode 100644 uni/test/integration/src/exams_page_test.mocks.dart create mode 100644 uni/test/integration/src/schedule_page_test.mocks.dart diff --git a/build.yaml b/build.yaml new file mode 100644 index 000000000..3fd1459f9 --- /dev/null +++ b/build.yaml @@ -0,0 +1,7 @@ +targets: + $default: + builders: + mockito|mockBuilder: + options: + build_extensions: + '^test/{{}}.dart': 'test/mocks/{{}}.mocks.dart' \ No newline at end of file diff --git a/uni/test/integration/src/exams_page_test.dart b/uni/test/integration/src/exams_page_test.dart index c57ff9199..34d57802c 100644 --- a/uni/test/integration/src/exams_page_test.dart +++ b/uni/test/integration/src/exams_page_test.dart @@ -1,10 +1,9 @@ -// @dart=2.10 - import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:http/http.dart' as http; +import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'package:provider/provider.dart'; import 'package:tuple/tuple.dart'; @@ -20,10 +19,7 @@ import 'package:uni/view/exams/exams.dart'; import '../../test_widget.dart'; -class MockClient extends Mock implements http.Client {} - -class MockResponse extends Mock implements http.Response {} - +@GenerateNiceMocks([MockSpec(), MockSpec()]) void main() { group('ExamsPage Integration Tests', () { final mockClient = MockClient(); diff --git a/uni/test/integration/src/exams_page_test.mocks.dart b/uni/test/integration/src/exams_page_test.mocks.dart new file mode 100644 index 000000000..71a69a4fa --- /dev/null +++ b/uni/test/integration/src/exams_page_test.mocks.dart @@ -0,0 +1,382 @@ +// Mocks generated by Mockito 5.4.2 from annotations +// in uni/test/integration/src/exams_page_test.dart. +// Do not manually edit this file. + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:async' as _i3; +import 'dart:convert' as _i4; +import 'dart:typed_data' as _i5; + +import 'package:http/http.dart' as _i2; +import 'package:mockito/mockito.dart' as _i1; + +// ignore_for_file: type=lint +// ignore_for_file: avoid_redundant_argument_values +// ignore_for_file: avoid_setters_without_getters +// ignore_for_file: comment_references +// ignore_for_file: implementation_imports +// ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: prefer_const_constructors +// ignore_for_file: unnecessary_parenthesis +// ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class + +class _FakeResponse_0 extends _i1.SmartFake implements _i2.Response { + _FakeResponse_0( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeStreamedResponse_1 extends _i1.SmartFake + implements _i2.StreamedResponse { + _FakeStreamedResponse_1( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +/// A class which mocks [Client]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockClient extends _i1.Mock implements _i2.Client { + @override + _i3.Future<_i2.Response> head( + Uri? url, { + Map? headers, + }) => + (super.noSuchMethod( + Invocation.method( + #head, + [url], + {#headers: headers}, + ), + returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #head, + [url], + {#headers: headers}, + ), + )), + returnValueForMissingStub: + _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #head, + [url], + {#headers: headers}, + ), + )), + ) as _i3.Future<_i2.Response>); + @override + _i3.Future<_i2.Response> get( + Uri? url, { + Map? headers, + }) => + (super.noSuchMethod( + Invocation.method( + #get, + [url], + {#headers: headers}, + ), + returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #get, + [url], + {#headers: headers}, + ), + )), + returnValueForMissingStub: + _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #get, + [url], + {#headers: headers}, + ), + )), + ) as _i3.Future<_i2.Response>); + @override + _i3.Future<_i2.Response> post( + Uri? url, { + Map? headers, + Object? body, + _i4.Encoding? encoding, + }) => + (super.noSuchMethod( + Invocation.method( + #post, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #post, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + returnValueForMissingStub: + _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #post, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + ) as _i3.Future<_i2.Response>); + @override + _i3.Future<_i2.Response> put( + Uri? url, { + Map? headers, + Object? body, + _i4.Encoding? encoding, + }) => + (super.noSuchMethod( + Invocation.method( + #put, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #put, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + returnValueForMissingStub: + _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #put, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + ) as _i3.Future<_i2.Response>); + @override + _i3.Future<_i2.Response> patch( + Uri? url, { + Map? headers, + Object? body, + _i4.Encoding? encoding, + }) => + (super.noSuchMethod( + Invocation.method( + #patch, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #patch, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + returnValueForMissingStub: + _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #patch, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + ) as _i3.Future<_i2.Response>); + @override + _i3.Future<_i2.Response> delete( + Uri? url, { + Map? headers, + Object? body, + _i4.Encoding? encoding, + }) => + (super.noSuchMethod( + Invocation.method( + #delete, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #delete, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + returnValueForMissingStub: + _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #delete, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + ) as _i3.Future<_i2.Response>); + @override + _i3.Future read( + Uri? url, { + Map? headers, + }) => + (super.noSuchMethod( + Invocation.method( + #read, + [url], + {#headers: headers}, + ), + returnValue: _i3.Future.value(''), + returnValueForMissingStub: _i3.Future.value(''), + ) as _i3.Future); + @override + _i3.Future<_i5.Uint8List> readBytes( + Uri? url, { + Map? headers, + }) => + (super.noSuchMethod( + Invocation.method( + #readBytes, + [url], + {#headers: headers}, + ), + returnValue: _i3.Future<_i5.Uint8List>.value(_i5.Uint8List(0)), + returnValueForMissingStub: + _i3.Future<_i5.Uint8List>.value(_i5.Uint8List(0)), + ) as _i3.Future<_i5.Uint8List>); + @override + _i3.Future<_i2.StreamedResponse> send(_i2.BaseRequest? request) => + (super.noSuchMethod( + Invocation.method( + #send, + [request], + ), + returnValue: + _i3.Future<_i2.StreamedResponse>.value(_FakeStreamedResponse_1( + this, + Invocation.method( + #send, + [request], + ), + )), + returnValueForMissingStub: + _i3.Future<_i2.StreamedResponse>.value(_FakeStreamedResponse_1( + this, + Invocation.method( + #send, + [request], + ), + )), + ) as _i3.Future<_i2.StreamedResponse>); + @override + void close() => super.noSuchMethod( + Invocation.method( + #close, + [], + ), + returnValueForMissingStub: null, + ); +} + +/// A class which mocks [Response]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockResponse extends _i1.Mock implements _i2.Response { + @override + _i5.Uint8List get bodyBytes => (super.noSuchMethod( + Invocation.getter(#bodyBytes), + returnValue: _i5.Uint8List(0), + returnValueForMissingStub: _i5.Uint8List(0), + ) as _i5.Uint8List); + @override + String get body => (super.noSuchMethod( + Invocation.getter(#body), + returnValue: '', + returnValueForMissingStub: '', + ) as String); + @override + int get statusCode => (super.noSuchMethod( + Invocation.getter(#statusCode), + returnValue: 0, + returnValueForMissingStub: 0, + ) as int); + @override + Map get headers => (super.noSuchMethod( + Invocation.getter(#headers), + returnValue: {}, + returnValueForMissingStub: {}, + ) as Map); + @override + bool get isRedirect => (super.noSuchMethod( + Invocation.getter(#isRedirect), + returnValue: false, + returnValueForMissingStub: false, + ) as bool); + @override + bool get persistentConnection => (super.noSuchMethod( + Invocation.getter(#persistentConnection), + returnValue: false, + returnValueForMissingStub: false, + ) as bool); +} diff --git a/uni/test/integration/src/schedule_page_test.dart b/uni/test/integration/src/schedule_page_test.dart index c01bf08e2..35b26e166 100644 --- a/uni/test/integration/src/schedule_page_test.dart +++ b/uni/test/integration/src/schedule_page_test.dart @@ -1,11 +1,10 @@ -// @dart=2.10 - import 'dart:convert'; import 'dart:io'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:http/http.dart' as http; +import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'package:provider/provider.dart'; import 'package:tuple/tuple.dart'; @@ -20,12 +19,6 @@ import 'package:uni/view/schedule/schedule.dart'; import '../../test_widget.dart'; import '../../unit/view/Widgets/schedule_slot_test.dart'; -class MockClient extends Mock implements http.Client {} - -class MockResponse extends Mock implements http.Response {} - -class MockSessionProvider extends Mock implements SessionProvider {} - class UriMatcher extends CustomMatcher { UriMatcher(Matcher matcher) : super('Uri that has', 'string', matcher); @@ -33,6 +26,11 @@ class UriMatcher extends CustomMatcher { Object featureValueOf(dynamic actual) => (actual as Uri).toString(); } +@GenerateNiceMocks([ + MockSpec(), + MockSpec(), + MockSpec() +]) void main() { group('SchedulePage Integration Tests', () { final mockClient = MockClient(); diff --git a/uni/test/integration/src/schedule_page_test.mocks.dart b/uni/test/integration/src/schedule_page_test.mocks.dart new file mode 100644 index 000000000..4a53b12f6 --- /dev/null +++ b/uni/test/integration/src/schedule_page_test.mocks.dart @@ -0,0 +1,599 @@ +// Mocks generated by Mockito 5.4.2 from annotations +// in uni/test/integration/src/schedule_page_test.dart. +// Do not manually edit this file. + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:async' as _i4; +import 'dart:convert' as _i5; +import 'dart:typed_data' as _i6; +import 'dart:ui' as _i11; + +import 'package:flutter/material.dart' as _i10; +import 'package:http/http.dart' as _i2; +import 'package:mockito/mockito.dart' as _i1; +import 'package:uni/model/entities/profile.dart' as _i9; +import 'package:uni/model/entities/session.dart' as _i3; +import 'package:uni/model/providers/startup/session_provider.dart' as _i7; +import 'package:uni/model/request_status.dart' as _i8; + +// ignore_for_file: type=lint +// ignore_for_file: avoid_redundant_argument_values +// ignore_for_file: avoid_setters_without_getters +// ignore_for_file: comment_references +// ignore_for_file: implementation_imports +// ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: prefer_const_constructors +// ignore_for_file: unnecessary_parenthesis +// ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class + +class _FakeResponse_0 extends _i1.SmartFake implements _i2.Response { + _FakeResponse_0( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeStreamedResponse_1 extends _i1.SmartFake + implements _i2.StreamedResponse { + _FakeStreamedResponse_1( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeSession_2 extends _i1.SmartFake implements _i3.Session { + _FakeSession_2( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +/// A class which mocks [Client]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockClient extends _i1.Mock implements _i2.Client { + @override + _i4.Future<_i2.Response> head( + Uri? url, { + Map? headers, + }) => + (super.noSuchMethod( + Invocation.method( + #head, + [url], + {#headers: headers}, + ), + returnValue: _i4.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #head, + [url], + {#headers: headers}, + ), + )), + returnValueForMissingStub: + _i4.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #head, + [url], + {#headers: headers}, + ), + )), + ) as _i4.Future<_i2.Response>); + @override + _i4.Future<_i2.Response> get( + Uri? url, { + Map? headers, + }) => + (super.noSuchMethod( + Invocation.method( + #get, + [url], + {#headers: headers}, + ), + returnValue: _i4.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #get, + [url], + {#headers: headers}, + ), + )), + returnValueForMissingStub: + _i4.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #get, + [url], + {#headers: headers}, + ), + )), + ) as _i4.Future<_i2.Response>); + @override + _i4.Future<_i2.Response> post( + Uri? url, { + Map? headers, + Object? body, + _i5.Encoding? encoding, + }) => + (super.noSuchMethod( + Invocation.method( + #post, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + returnValue: _i4.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #post, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + returnValueForMissingStub: + _i4.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #post, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + ) as _i4.Future<_i2.Response>); + @override + _i4.Future<_i2.Response> put( + Uri? url, { + Map? headers, + Object? body, + _i5.Encoding? encoding, + }) => + (super.noSuchMethod( + Invocation.method( + #put, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + returnValue: _i4.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #put, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + returnValueForMissingStub: + _i4.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #put, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + ) as _i4.Future<_i2.Response>); + @override + _i4.Future<_i2.Response> patch( + Uri? url, { + Map? headers, + Object? body, + _i5.Encoding? encoding, + }) => + (super.noSuchMethod( + Invocation.method( + #patch, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + returnValue: _i4.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #patch, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + returnValueForMissingStub: + _i4.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #patch, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + ) as _i4.Future<_i2.Response>); + @override + _i4.Future<_i2.Response> delete( + Uri? url, { + Map? headers, + Object? body, + _i5.Encoding? encoding, + }) => + (super.noSuchMethod( + Invocation.method( + #delete, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + returnValue: _i4.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #delete, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + returnValueForMissingStub: + _i4.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #delete, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + ) as _i4.Future<_i2.Response>); + @override + _i4.Future read( + Uri? url, { + Map? headers, + }) => + (super.noSuchMethod( + Invocation.method( + #read, + [url], + {#headers: headers}, + ), + returnValue: _i4.Future.value(''), + returnValueForMissingStub: _i4.Future.value(''), + ) as _i4.Future); + @override + _i4.Future<_i6.Uint8List> readBytes( + Uri? url, { + Map? headers, + }) => + (super.noSuchMethod( + Invocation.method( + #readBytes, + [url], + {#headers: headers}, + ), + returnValue: _i4.Future<_i6.Uint8List>.value(_i6.Uint8List(0)), + returnValueForMissingStub: + _i4.Future<_i6.Uint8List>.value(_i6.Uint8List(0)), + ) as _i4.Future<_i6.Uint8List>); + @override + _i4.Future<_i2.StreamedResponse> send(_i2.BaseRequest? request) => + (super.noSuchMethod( + Invocation.method( + #send, + [request], + ), + returnValue: + _i4.Future<_i2.StreamedResponse>.value(_FakeStreamedResponse_1( + this, + Invocation.method( + #send, + [request], + ), + )), + returnValueForMissingStub: + _i4.Future<_i2.StreamedResponse>.value(_FakeStreamedResponse_1( + this, + Invocation.method( + #send, + [request], + ), + )), + ) as _i4.Future<_i2.StreamedResponse>); + @override + void close() => super.noSuchMethod( + Invocation.method( + #close, + [], + ), + returnValueForMissingStub: null, + ); +} + +/// A class which mocks [Response]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockResponse extends _i1.Mock implements _i2.Response { + @override + _i6.Uint8List get bodyBytes => (super.noSuchMethod( + Invocation.getter(#bodyBytes), + returnValue: _i6.Uint8List(0), + returnValueForMissingStub: _i6.Uint8List(0), + ) as _i6.Uint8List); + @override + String get body => (super.noSuchMethod( + Invocation.getter(#body), + returnValue: '', + returnValueForMissingStub: '', + ) as String); + @override + int get statusCode => (super.noSuchMethod( + Invocation.getter(#statusCode), + returnValue: 0, + returnValueForMissingStub: 0, + ) as int); + @override + Map get headers => (super.noSuchMethod( + Invocation.getter(#headers), + returnValue: {}, + returnValueForMissingStub: {}, + ) as Map); + @override + bool get isRedirect => (super.noSuchMethod( + Invocation.getter(#isRedirect), + returnValue: false, + returnValueForMissingStub: false, + ) as bool); + @override + bool get persistentConnection => (super.noSuchMethod( + Invocation.getter(#persistentConnection), + returnValue: false, + returnValueForMissingStub: false, + ) as bool); +} + +/// A class which mocks [SessionProvider]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockSessionProvider extends _i1.Mock implements _i7.SessionProvider { + @override + _i3.Session get session => (super.noSuchMethod( + Invocation.getter(#session), + returnValue: _FakeSession_2( + this, + Invocation.getter(#session), + ), + returnValueForMissingStub: _FakeSession_2( + this, + Invocation.getter(#session), + ), + ) as _i3.Session); + @override + bool get dependsOnSession => (super.noSuchMethod( + Invocation.getter(#dependsOnSession), + returnValue: false, + returnValueForMissingStub: false, + ) as bool); + @override + set dependsOnSession(bool? _dependsOnSession) => super.noSuchMethod( + Invocation.setter( + #dependsOnSession, + _dependsOnSession, + ), + returnValueForMissingStub: null, + ); + @override + set cacheDuration(Duration? _cacheDuration) => super.noSuchMethod( + Invocation.setter( + #cacheDuration, + _cacheDuration, + ), + returnValueForMissingStub: null, + ); + @override + _i8.RequestStatus get status => (super.noSuchMethod( + Invocation.getter(#status), + returnValue: _i8.RequestStatus.none, + returnValueForMissingStub: _i8.RequestStatus.none, + ) as _i8.RequestStatus); + @override + bool get hasListeners => (super.noSuchMethod( + Invocation.getter(#hasListeners), + returnValue: false, + returnValueForMissingStub: false, + ) as bool); + @override + _i4.Future loadFromStorage() => (super.noSuchMethod( + Invocation.method( + #loadFromStorage, + [], + ), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); + @override + _i4.Future loadFromRemote( + _i3.Session? session, + _i9.Profile? profile, + ) => + (super.noSuchMethod( + Invocation.method( + #loadFromRemote, + [ + session, + profile, + ], + ), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); + @override + void restoreSession( + String? username, + String? password, + List? faculties, + ) => + super.noSuchMethod( + Invocation.method( + #restoreSession, + [ + username, + password, + faculties, + ], + ), + returnValueForMissingStub: null, + ); + @override + _i4.Future postAuthentication( + String? username, + String? password, + List? faculties, { + required bool? persistentSession, + }) => + (super.noSuchMethod( + Invocation.method( + #postAuthentication, + [ + username, + password, + faculties, + ], + {#persistentSession: persistentSession}, + ), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); + @override + void markAsNotInitialized() => super.noSuchMethod( + Invocation.method( + #markAsNotInitialized, + [], + ), + returnValueForMissingStub: null, + ); + @override + void updateStatus(_i8.RequestStatus? status) => super.noSuchMethod( + Invocation.method( + #updateStatus, + [status], + ), + returnValueForMissingStub: null, + ); + @override + _i4.Future forceRefresh(_i10.BuildContext? context) => + (super.noSuchMethod( + Invocation.method( + #forceRefresh, + [context], + ), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); + @override + _i4.Future ensureInitialized(_i10.BuildContext? context) => + (super.noSuchMethod( + Invocation.method( + #ensureInitialized, + [context], + ), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); + @override + _i4.Future ensureInitializedFromRemote(_i10.BuildContext? context) => + (super.noSuchMethod( + Invocation.method( + #ensureInitializedFromRemote, + [context], + ), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); + @override + _i4.Future ensureInitializedFromStorage() => (super.noSuchMethod( + Invocation.method( + #ensureInitializedFromStorage, + [], + ), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); + @override + void addListener(_i11.VoidCallback? listener) => super.noSuchMethod( + Invocation.method( + #addListener, + [listener], + ), + returnValueForMissingStub: null, + ); + @override + void removeListener(_i11.VoidCallback? listener) => super.noSuchMethod( + Invocation.method( + #removeListener, + [listener], + ), + returnValueForMissingStub: null, + ); + @override + void dispose() => super.noSuchMethod( + Invocation.method( + #dispose, + [], + ), + returnValueForMissingStub: null, + ); + @override + void notifyListeners() => super.noSuchMethod( + Invocation.method( + #notifyListeners, + [], + ), + returnValueForMissingStub: null, + ); +} From 70eecde7d3454809ddbf06f9cc221e475a03c33a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Duarte?= Date: Mon, 21 Aug 2023 16:36:44 +0100 Subject: [PATCH 04/13] tests running in null safe mode --- build.yaml => uni/build.yaml | 0 uni/pubspec.yaml | 7 +- uni/test/analysis_options.yaml | 5 - uni/test/integration/src/exams_page_test.dart | 1 + .../integration/src/schedule_page_test.dart | 1 + .../src/exams_page_test.mocks.dart | 4 +- .../src/schedule_page_test.mocks.dart | 4 +- .../providers/exams_provider_test.mocks.dart | 419 ++++++++++++++++ .../lecture_provider_test.mocks.dart | 452 ++++++++++++++++++ .../unit/providers/exams_provider_test.dart | 14 +- .../unit/providers/lecture_provider_test.dart | 21 +- uni/test/unit/providers/mocks.dart | 12 - 12 files changed, 909 insertions(+), 31 deletions(-) rename build.yaml => uni/build.yaml (100%) delete mode 100644 uni/test/analysis_options.yaml rename uni/test/{ => mocks}/integration/src/exams_page_test.mocks.dart (98%) rename uni/test/{ => mocks}/integration/src/schedule_page_test.mocks.dart (99%) create mode 100644 uni/test/mocks/unit/providers/exams_provider_test.mocks.dart create mode 100644 uni/test/mocks/unit/providers/lecture_provider_test.mocks.dart delete mode 100644 uni/test/unit/providers/mocks.dart diff --git a/build.yaml b/uni/build.yaml similarity index 100% rename from build.yaml rename to uni/build.yaml diff --git a/uni/pubspec.yaml b/uni/pubspec.yaml index f35c056f3..8cfffa705 100644 --- a/uni/pubspec.yaml +++ b/uni/pubspec.yaml @@ -63,7 +63,12 @@ dev_dependencies: flutter_launcher_icons: ^0.13.1 flutter_test: sdk: flutter - mockito: ^5.4.2 + # FIXME(luisd): Update mockito to a release version when 5.4.3 or above + # is launched + mockito: + git: + url: https://github.com/dart-lang/mockito.git + ref: "e54a006" test: any very_good_analysis: ^4.0.0+1 diff --git a/uni/test/analysis_options.yaml b/uni/test/analysis_options.yaml deleted file mode 100644 index 36d4692d5..000000000 --- a/uni/test/analysis_options.yaml +++ /dev/null @@ -1,5 +0,0 @@ -include: ../analysis_options.yaml - -linter: - rules: - enable_null_safety: false \ No newline at end of file diff --git a/uni/test/integration/src/exams_page_test.dart b/uni/test/integration/src/exams_page_test.dart index 34d57802c..44622790c 100644 --- a/uni/test/integration/src/exams_page_test.dart +++ b/uni/test/integration/src/exams_page_test.dart @@ -17,6 +17,7 @@ import 'package:uni/model/entities/session.dart'; import 'package:uni/model/providers/lazy/exam_provider.dart'; import 'package:uni/view/exams/exams.dart'; +import '../../mocks/integration/src/exams_page_test.mocks.dart'; import '../../test_widget.dart'; @GenerateNiceMocks([MockSpec(), MockSpec()]) diff --git a/uni/test/integration/src/schedule_page_test.dart b/uni/test/integration/src/schedule_page_test.dart index 35b26e166..823690a33 100644 --- a/uni/test/integration/src/schedule_page_test.dart +++ b/uni/test/integration/src/schedule_page_test.dart @@ -16,6 +16,7 @@ import 'package:uni/model/providers/lazy/lecture_provider.dart'; import 'package:uni/model/providers/startup/session_provider.dart'; import 'package:uni/view/schedule/schedule.dart'; +import '../../mocks/integration/src/schedule_page_test.mocks.dart'; import '../../test_widget.dart'; import '../../unit/view/Widgets/schedule_slot_test.dart'; diff --git a/uni/test/integration/src/exams_page_test.mocks.dart b/uni/test/mocks/integration/src/exams_page_test.mocks.dart similarity index 98% rename from uni/test/integration/src/exams_page_test.mocks.dart rename to uni/test/mocks/integration/src/exams_page_test.mocks.dart index 71a69a4fa..e28b49f59 100644 --- a/uni/test/integration/src/exams_page_test.mocks.dart +++ b/uni/test/mocks/integration/src/exams_page_test.mocks.dart @@ -1,4 +1,4 @@ -// Mocks generated by Mockito 5.4.2 from annotations +// Mocks generated by Mockito 5.4.3-wip from annotations // in uni/test/integration/src/exams_page_test.dart. // Do not manually edit this file. @@ -14,6 +14,8 @@ import 'package:mockito/mockito.dart' as _i1; // ignore_for_file: avoid_redundant_argument_values // ignore_for_file: avoid_setters_without_getters // ignore_for_file: comment_references +// ignore_for_file: deprecated_member_use +// ignore_for_file: deprecated_member_use_from_same_package // ignore_for_file: implementation_imports // ignore_for_file: invalid_use_of_visible_for_testing_member // ignore_for_file: prefer_const_constructors diff --git a/uni/test/integration/src/schedule_page_test.mocks.dart b/uni/test/mocks/integration/src/schedule_page_test.mocks.dart similarity index 99% rename from uni/test/integration/src/schedule_page_test.mocks.dart rename to uni/test/mocks/integration/src/schedule_page_test.mocks.dart index 4a53b12f6..c3259a73a 100644 --- a/uni/test/integration/src/schedule_page_test.mocks.dart +++ b/uni/test/mocks/integration/src/schedule_page_test.mocks.dart @@ -1,4 +1,4 @@ -// Mocks generated by Mockito 5.4.2 from annotations +// Mocks generated by Mockito 5.4.3-wip from annotations // in uni/test/integration/src/schedule_page_test.dart. // Do not manually edit this file. @@ -20,6 +20,8 @@ import 'package:uni/model/request_status.dart' as _i8; // ignore_for_file: avoid_redundant_argument_values // ignore_for_file: avoid_setters_without_getters // ignore_for_file: comment_references +// ignore_for_file: deprecated_member_use +// ignore_for_file: deprecated_member_use_from_same_package // ignore_for_file: implementation_imports // ignore_for_file: invalid_use_of_visible_for_testing_member // ignore_for_file: prefer_const_constructors diff --git a/uni/test/mocks/unit/providers/exams_provider_test.mocks.dart b/uni/test/mocks/unit/providers/exams_provider_test.mocks.dart new file mode 100644 index 000000000..fd78853db --- /dev/null +++ b/uni/test/mocks/unit/providers/exams_provider_test.mocks.dart @@ -0,0 +1,419 @@ +// Mocks generated by Mockito 5.4.3-wip from annotations +// in uni/test/unit/providers/exams_provider_test.dart. +// Do not manually edit this file. + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:async' as _i3; +import 'dart:convert' as _i4; +import 'dart:typed_data' as _i5; + +import 'package:http/http.dart' as _i2; +import 'package:mockito/mockito.dart' as _i1; +import 'package:uni/controller/parsers/parser_exams.dart' as _i6; +import 'package:uni/model/entities/course.dart' as _i8; +import 'package:uni/model/entities/exam.dart' as _i7; + +// ignore_for_file: type=lint +// ignore_for_file: avoid_redundant_argument_values +// ignore_for_file: avoid_setters_without_getters +// ignore_for_file: comment_references +// ignore_for_file: deprecated_member_use +// ignore_for_file: deprecated_member_use_from_same_package +// ignore_for_file: implementation_imports +// ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: prefer_const_constructors +// ignore_for_file: unnecessary_parenthesis +// ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class + +class _FakeResponse_0 extends _i1.SmartFake implements _i2.Response { + _FakeResponse_0( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeStreamedResponse_1 extends _i1.SmartFake + implements _i2.StreamedResponse { + _FakeStreamedResponse_1( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +/// A class which mocks [Client]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockClient extends _i1.Mock implements _i2.Client { + @override + _i3.Future<_i2.Response> head( + Uri? url, { + Map? headers, + }) => + (super.noSuchMethod( + Invocation.method( + #head, + [url], + {#headers: headers}, + ), + returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #head, + [url], + {#headers: headers}, + ), + )), + returnValueForMissingStub: + _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #head, + [url], + {#headers: headers}, + ), + )), + ) as _i3.Future<_i2.Response>); + @override + _i3.Future<_i2.Response> get( + Uri? url, { + Map? headers, + }) => + (super.noSuchMethod( + Invocation.method( + #get, + [url], + {#headers: headers}, + ), + returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #get, + [url], + {#headers: headers}, + ), + )), + returnValueForMissingStub: + _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #get, + [url], + {#headers: headers}, + ), + )), + ) as _i3.Future<_i2.Response>); + @override + _i3.Future<_i2.Response> post( + Uri? url, { + Map? headers, + Object? body, + _i4.Encoding? encoding, + }) => + (super.noSuchMethod( + Invocation.method( + #post, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #post, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + returnValueForMissingStub: + _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #post, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + ) as _i3.Future<_i2.Response>); + @override + _i3.Future<_i2.Response> put( + Uri? url, { + Map? headers, + Object? body, + _i4.Encoding? encoding, + }) => + (super.noSuchMethod( + Invocation.method( + #put, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #put, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + returnValueForMissingStub: + _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #put, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + ) as _i3.Future<_i2.Response>); + @override + _i3.Future<_i2.Response> patch( + Uri? url, { + Map? headers, + Object? body, + _i4.Encoding? encoding, + }) => + (super.noSuchMethod( + Invocation.method( + #patch, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #patch, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + returnValueForMissingStub: + _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #patch, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + ) as _i3.Future<_i2.Response>); + @override + _i3.Future<_i2.Response> delete( + Uri? url, { + Map? headers, + Object? body, + _i4.Encoding? encoding, + }) => + (super.noSuchMethod( + Invocation.method( + #delete, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + returnValue: _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #delete, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + returnValueForMissingStub: + _i3.Future<_i2.Response>.value(_FakeResponse_0( + this, + Invocation.method( + #delete, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + ) as _i3.Future<_i2.Response>); + @override + _i3.Future read( + Uri? url, { + Map? headers, + }) => + (super.noSuchMethod( + Invocation.method( + #read, + [url], + {#headers: headers}, + ), + returnValue: _i3.Future.value(''), + returnValueForMissingStub: _i3.Future.value(''), + ) as _i3.Future); + @override + _i3.Future<_i5.Uint8List> readBytes( + Uri? url, { + Map? headers, + }) => + (super.noSuchMethod( + Invocation.method( + #readBytes, + [url], + {#headers: headers}, + ), + returnValue: _i3.Future<_i5.Uint8List>.value(_i5.Uint8List(0)), + returnValueForMissingStub: + _i3.Future<_i5.Uint8List>.value(_i5.Uint8List(0)), + ) as _i3.Future<_i5.Uint8List>); + @override + _i3.Future<_i2.StreamedResponse> send(_i2.BaseRequest? request) => + (super.noSuchMethod( + Invocation.method( + #send, + [request], + ), + returnValue: + _i3.Future<_i2.StreamedResponse>.value(_FakeStreamedResponse_1( + this, + Invocation.method( + #send, + [request], + ), + )), + returnValueForMissingStub: + _i3.Future<_i2.StreamedResponse>.value(_FakeStreamedResponse_1( + this, + Invocation.method( + #send, + [request], + ), + )), + ) as _i3.Future<_i2.StreamedResponse>); + @override + void close() => super.noSuchMethod( + Invocation.method( + #close, + [], + ), + returnValueForMissingStub: null, + ); +} + +/// A class which mocks [ParserExams]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockParserExams extends _i1.Mock implements _i6.ParserExams { + @override + String getExamSeasonAbbr(String? seasonStr) => (super.noSuchMethod( + Invocation.method( + #getExamSeasonAbbr, + [seasonStr], + ), + returnValue: '', + returnValueForMissingStub: '', + ) as String); + @override + _i3.Future> parseExams( + _i2.Response? response, + _i8.Course? course, + ) => + (super.noSuchMethod( + Invocation.method( + #parseExams, + [ + response, + course, + ], + ), + returnValue: _i3.Future>.value(<_i7.Exam>{}), + returnValueForMissingStub: + _i3.Future>.value(<_i7.Exam>{}), + ) as _i3.Future>); +} + +/// A class which mocks [Response]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockResponse extends _i1.Mock implements _i2.Response { + @override + _i5.Uint8List get bodyBytes => (super.noSuchMethod( + Invocation.getter(#bodyBytes), + returnValue: _i5.Uint8List(0), + returnValueForMissingStub: _i5.Uint8List(0), + ) as _i5.Uint8List); + @override + String get body => (super.noSuchMethod( + Invocation.getter(#body), + returnValue: '', + returnValueForMissingStub: '', + ) as String); + @override + int get statusCode => (super.noSuchMethod( + Invocation.getter(#statusCode), + returnValue: 0, + returnValueForMissingStub: 0, + ) as int); + @override + Map get headers => (super.noSuchMethod( + Invocation.getter(#headers), + returnValue: {}, + returnValueForMissingStub: {}, + ) as Map); + @override + bool get isRedirect => (super.noSuchMethod( + Invocation.getter(#isRedirect), + returnValue: false, + returnValueForMissingStub: false, + ) as bool); + @override + bool get persistentConnection => (super.noSuchMethod( + Invocation.getter(#persistentConnection), + returnValue: false, + returnValueForMissingStub: false, + ) as bool); +} diff --git a/uni/test/mocks/unit/providers/lecture_provider_test.mocks.dart b/uni/test/mocks/unit/providers/lecture_provider_test.mocks.dart new file mode 100644 index 000000000..3fd2208a6 --- /dev/null +++ b/uni/test/mocks/unit/providers/lecture_provider_test.mocks.dart @@ -0,0 +1,452 @@ +// Mocks generated by Mockito 5.4.3-wip from annotations +// in uni/test/unit/providers/lecture_provider_test.dart. +// Do not manually edit this file. + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:async' as _i4; +import 'dart:convert' as _i8; +import 'dart:typed_data' as _i9; + +import 'package:http/http.dart' as _i3; +import 'package:mockito/mockito.dart' as _i1; +import 'package:uni/controller/fetchers/schedule_fetcher/schedule_fetcher.dart' + as _i2; +import 'package:uni/model/entities/lecture.dart' as _i5; +import 'package:uni/model/entities/profile.dart' as _i7; +import 'package:uni/model/entities/session.dart' as _i6; + +// ignore_for_file: type=lint +// ignore_for_file: avoid_redundant_argument_values +// ignore_for_file: avoid_setters_without_getters +// ignore_for_file: comment_references +// ignore_for_file: deprecated_member_use +// ignore_for_file: deprecated_member_use_from_same_package +// ignore_for_file: implementation_imports +// ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: prefer_const_constructors +// ignore_for_file: unnecessary_parenthesis +// ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class + +class _FakeDates_0 extends _i1.SmartFake implements _i2.Dates { + _FakeDates_0( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeResponse_1 extends _i1.SmartFake implements _i3.Response { + _FakeResponse_1( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakeStreamedResponse_2 extends _i1.SmartFake + implements _i3.StreamedResponse { + _FakeStreamedResponse_2( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +/// A class which mocks [ScheduleFetcher]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockScheduleFetcher extends _i1.Mock implements _i2.ScheduleFetcher { + @override + _i4.Future> getLectures( + _i6.Session? session, + _i7.Profile? profile, + ) => + (super.noSuchMethod( + Invocation.method( + #getLectures, + [ + session, + profile, + ], + ), + returnValue: _i4.Future>.value(<_i5.Lecture>[]), + returnValueForMissingStub: + _i4.Future>.value(<_i5.Lecture>[]), + ) as _i4.Future>); + @override + _i2.Dates getDates() => (super.noSuchMethod( + Invocation.method( + #getDates, + [], + ), + returnValue: _FakeDates_0( + this, + Invocation.method( + #getDates, + [], + ), + ), + returnValueForMissingStub: _FakeDates_0( + this, + Invocation.method( + #getDates, + [], + ), + ), + ) as _i2.Dates); + @override + List getEndpoints(_i6.Session? session) => (super.noSuchMethod( + Invocation.method( + #getEndpoints, + [session], + ), + returnValue: [], + returnValueForMissingStub: [], + ) as List); +} + +/// A class which mocks [Client]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockClient extends _i1.Mock implements _i3.Client { + @override + _i4.Future<_i3.Response> head( + Uri? url, { + Map? headers, + }) => + (super.noSuchMethod( + Invocation.method( + #head, + [url], + {#headers: headers}, + ), + returnValue: _i4.Future<_i3.Response>.value(_FakeResponse_1( + this, + Invocation.method( + #head, + [url], + {#headers: headers}, + ), + )), + returnValueForMissingStub: + _i4.Future<_i3.Response>.value(_FakeResponse_1( + this, + Invocation.method( + #head, + [url], + {#headers: headers}, + ), + )), + ) as _i4.Future<_i3.Response>); + @override + _i4.Future<_i3.Response> get( + Uri? url, { + Map? headers, + }) => + (super.noSuchMethod( + Invocation.method( + #get, + [url], + {#headers: headers}, + ), + returnValue: _i4.Future<_i3.Response>.value(_FakeResponse_1( + this, + Invocation.method( + #get, + [url], + {#headers: headers}, + ), + )), + returnValueForMissingStub: + _i4.Future<_i3.Response>.value(_FakeResponse_1( + this, + Invocation.method( + #get, + [url], + {#headers: headers}, + ), + )), + ) as _i4.Future<_i3.Response>); + @override + _i4.Future<_i3.Response> post( + Uri? url, { + Map? headers, + Object? body, + _i8.Encoding? encoding, + }) => + (super.noSuchMethod( + Invocation.method( + #post, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + returnValue: _i4.Future<_i3.Response>.value(_FakeResponse_1( + this, + Invocation.method( + #post, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + returnValueForMissingStub: + _i4.Future<_i3.Response>.value(_FakeResponse_1( + this, + Invocation.method( + #post, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + ) as _i4.Future<_i3.Response>); + @override + _i4.Future<_i3.Response> put( + Uri? url, { + Map? headers, + Object? body, + _i8.Encoding? encoding, + }) => + (super.noSuchMethod( + Invocation.method( + #put, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + returnValue: _i4.Future<_i3.Response>.value(_FakeResponse_1( + this, + Invocation.method( + #put, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + returnValueForMissingStub: + _i4.Future<_i3.Response>.value(_FakeResponse_1( + this, + Invocation.method( + #put, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + ) as _i4.Future<_i3.Response>); + @override + _i4.Future<_i3.Response> patch( + Uri? url, { + Map? headers, + Object? body, + _i8.Encoding? encoding, + }) => + (super.noSuchMethod( + Invocation.method( + #patch, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + returnValue: _i4.Future<_i3.Response>.value(_FakeResponse_1( + this, + Invocation.method( + #patch, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + returnValueForMissingStub: + _i4.Future<_i3.Response>.value(_FakeResponse_1( + this, + Invocation.method( + #patch, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + ) as _i4.Future<_i3.Response>); + @override + _i4.Future<_i3.Response> delete( + Uri? url, { + Map? headers, + Object? body, + _i8.Encoding? encoding, + }) => + (super.noSuchMethod( + Invocation.method( + #delete, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + returnValue: _i4.Future<_i3.Response>.value(_FakeResponse_1( + this, + Invocation.method( + #delete, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + returnValueForMissingStub: + _i4.Future<_i3.Response>.value(_FakeResponse_1( + this, + Invocation.method( + #delete, + [url], + { + #headers: headers, + #body: body, + #encoding: encoding, + }, + ), + )), + ) as _i4.Future<_i3.Response>); + @override + _i4.Future read( + Uri? url, { + Map? headers, + }) => + (super.noSuchMethod( + Invocation.method( + #read, + [url], + {#headers: headers}, + ), + returnValue: _i4.Future.value(''), + returnValueForMissingStub: _i4.Future.value(''), + ) as _i4.Future); + @override + _i4.Future<_i9.Uint8List> readBytes( + Uri? url, { + Map? headers, + }) => + (super.noSuchMethod( + Invocation.method( + #readBytes, + [url], + {#headers: headers}, + ), + returnValue: _i4.Future<_i9.Uint8List>.value(_i9.Uint8List(0)), + returnValueForMissingStub: + _i4.Future<_i9.Uint8List>.value(_i9.Uint8List(0)), + ) as _i4.Future<_i9.Uint8List>); + @override + _i4.Future<_i3.StreamedResponse> send(_i3.BaseRequest? request) => + (super.noSuchMethod( + Invocation.method( + #send, + [request], + ), + returnValue: + _i4.Future<_i3.StreamedResponse>.value(_FakeStreamedResponse_2( + this, + Invocation.method( + #send, + [request], + ), + )), + returnValueForMissingStub: + _i4.Future<_i3.StreamedResponse>.value(_FakeStreamedResponse_2( + this, + Invocation.method( + #send, + [request], + ), + )), + ) as _i4.Future<_i3.StreamedResponse>); + @override + void close() => super.noSuchMethod( + Invocation.method( + #close, + [], + ), + returnValueForMissingStub: null, + ); +} + +/// A class which mocks [Response]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockResponse extends _i1.Mock implements _i3.Response { + @override + _i9.Uint8List get bodyBytes => (super.noSuchMethod( + Invocation.getter(#bodyBytes), + returnValue: _i9.Uint8List(0), + returnValueForMissingStub: _i9.Uint8List(0), + ) as _i9.Uint8List); + @override + String get body => (super.noSuchMethod( + Invocation.getter(#body), + returnValue: '', + returnValueForMissingStub: '', + ) as String); + @override + int get statusCode => (super.noSuchMethod( + Invocation.getter(#statusCode), + returnValue: 0, + returnValueForMissingStub: 0, + ) as int); + @override + Map get headers => (super.noSuchMethod( + Invocation.getter(#headers), + returnValue: {}, + returnValueForMissingStub: {}, + ) as Map); + @override + bool get isRedirect => (super.noSuchMethod( + Invocation.getter(#isRedirect), + returnValue: false, + returnValueForMissingStub: false, + ) as bool); + @override + bool get persistentConnection => (super.noSuchMethod( + Invocation.getter(#persistentConnection), + returnValue: false, + returnValueForMissingStub: false, + ) as bool); +} diff --git a/uni/test/unit/providers/exams_provider_test.dart b/uni/test/unit/providers/exams_provider_test.dart index 2ac9bf387..2f4c33ddd 100644 --- a/uni/test/unit/providers/exams_provider_test.dart +++ b/uni/test/unit/providers/exams_provider_test.dart @@ -1,9 +1,10 @@ -// @dart=2.10 - import 'package:flutter_test/flutter_test.dart'; +import 'package:http/http.dart'; +import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'package:tuple/tuple.dart'; import 'package:uni/controller/networking/network_router.dart'; +import 'package:uni/controller/parsers/parser_exams.dart'; import 'package:uni/model/entities/course.dart'; import 'package:uni/model/entities/course_units/course_unit.dart'; import 'package:uni/model/entities/exam.dart'; @@ -12,12 +13,15 @@ import 'package:uni/model/entities/session.dart'; import 'package:uni/model/providers/lazy/exam_provider.dart'; import 'package:uni/model/request_status.dart'; -import 'mocks.dart'; +import '../../mocks/unit/providers/exams_provider_test.mocks.dart'; +@GenerateNiceMocks( + [MockSpec(), MockSpec(), MockSpec()], +) void main() { group('ExamProvider', () { final mockClient = MockClient(); - final parserExams = ParserExamsMock(); + final parserExams = MockParserExams(); final mockResponse = MockResponse(); final sopeCourseUnit = CourseUnit( @@ -68,7 +72,7 @@ void main() { .thenAnswer((_) async => mockResponse); when(mockResponse.statusCode).thenReturn(200); - ExamProvider provider; + late ExamProvider provider; setUp(() { provider = ExamProvider(); diff --git a/uni/test/unit/providers/lecture_provider_test.dart b/uni/test/unit/providers/lecture_provider_test.dart index 2f77e9acf..8498f01c2 100644 --- a/uni/test/unit/providers/lecture_provider_test.dart +++ b/uni/test/unit/providers/lecture_provider_test.dart @@ -1,8 +1,9 @@ -// @dart=2.10 - import 'package:flutter_test/flutter_test.dart'; +import 'package:http/http.dart'; +import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'package:tuple/tuple.dart'; +import 'package:uni/controller/fetchers/schedule_fetcher/schedule_fetcher.dart'; import 'package:uni/controller/networking/network_router.dart'; import 'package:uni/model/entities/course.dart'; import 'package:uni/model/entities/lecture.dart'; @@ -11,11 +12,14 @@ import 'package:uni/model/entities/session.dart'; import 'package:uni/model/providers/lazy/lecture_provider.dart'; import 'package:uni/model/request_status.dart'; -import 'mocks.dart'; +import '../../mocks/unit/providers/lecture_provider_test.mocks.dart'; +@GenerateNiceMocks( + [MockSpec(), MockSpec(), MockSpec()], +) void main() { group('Schedule Action Creator', () { - final fetcherMock = ScheduleFetcherMock(); + final fetcherMock = MockScheduleFetcher(); final mockClient = MockClient(); final mockResponse = MockResponse(); const userPersistentInfo = Tuple2('', ''); @@ -51,7 +55,7 @@ void main() { .thenAnswer((_) async => mockResponse); when(mockResponse.statusCode).thenReturn(200); - LectureProvider provider; + late LectureProvider provider; setUp(() { provider = LectureProvider(); expect(provider.status, RequestStatus.busy); @@ -76,7 +80,12 @@ void main() { when(fetcherMock.getLectures(any, any)) .thenAnswer((_) async => throw Exception('💥')); - await provider.fetchUserLectures(userPersistentInfo, session, profile); + await provider.fetchUserLectures( + userPersistentInfo, + session, + profile, + fetcher: fetcherMock, + ); expect(provider.status, RequestStatus.failed); }); diff --git a/uni/test/unit/providers/mocks.dart b/uni/test/unit/providers/mocks.dart deleted file mode 100644 index edbe8cc80..000000000 --- a/uni/test/unit/providers/mocks.dart +++ /dev/null @@ -1,12 +0,0 @@ -import 'package:http/http.dart' as http; -import 'package:mockito/mockito.dart'; -import 'package:uni/controller/fetchers/schedule_fetcher/schedule_fetcher.dart'; -import 'package:uni/controller/parsers/parser_exams.dart'; - -class MockClient extends Mock implements http.Client {} - -class MockResponse extends Mock implements http.Response {} - -class ParserExamsMock extends Mock implements ParserExams {} - -class ScheduleFetcherMock extends Mock implements ScheduleFetcher {} From 574cc12d00e32fcffe2db4b94bce8bfc13625f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Duarte?= Date: Mon, 21 Aug 2023 16:40:15 +0100 Subject: [PATCH 05/13] Update flutter CI version --- .github/workflows/format_lint_test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/format_lint_test.yaml b/.github/workflows/format_lint_test.yaml index 34f752778..9b4b9055b 100644 --- a/.github/workflows/format_lint_test.yaml +++ b/.github/workflows/format_lint_test.yaml @@ -4,7 +4,7 @@ on: branches: [master, develop] env: - FLUTTER_VERSION: 3.7.2 + FLUTTER_VERSION: 3.10.6 JAVA_VERSION: 11.x jobs: From 2a38386f91606545c28d905c6275ffc48319a08d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Duarte?= Date: Mon, 21 Aug 2023 17:03:36 +0100 Subject: [PATCH 06/13] Fix linting --- uni/lib/view/login/login.dart | 2 +- uni/lib/view/login/widgets/inputs.dart | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/uni/lib/view/login/login.dart b/uni/lib/view/login/login.dart index 06d56819b..f1cae2116 100644 --- a/uni/lib/view/login/login.dart +++ b/uni/lib/view/login/login.dart @@ -87,7 +87,7 @@ class LoginPageViewState extends State { /// Tracks if the user wants to keep signed in (has a /// checkmark on the button). - void _setKeepSignedIn(bool? value) { + void _setKeepSignedIn({bool? value}) { if (value == null) return; setState(() { _keepSignedIn = value; diff --git a/uni/lib/view/login/widgets/inputs.dart b/uni/lib/view/login/widgets/inputs.dart index d42b805b2..a123af1c3 100644 --- a/uni/lib/view/login/widgets/inputs.dart +++ b/uni/lib/view/login/widgets/inputs.dart @@ -68,12 +68,12 @@ Widget createPasswordInput( /// Creates the widget for the user to keep signed in (save his data). Widget createSaveDataCheckBox( - void Function(bool?)? setKeepSignedIn, { + void Function({bool? value})? setKeepSignedIn, { required bool keepSignedIn, }) { return CheckboxListTile( value: keepSignedIn, - onChanged: setKeepSignedIn, + onChanged: (value) => setKeepSignedIn?.call(value: value), title: const Text( 'Manter sessão iniciada', textAlign: TextAlign.center, From 0c848c7e28b2a5527038587aa271b79e3ae90a36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Duarte?= Date: Tue, 22 Aug 2023 16:51:19 +0100 Subject: [PATCH 07/13] Update deploy.yaml --- .github/workflows/deploy.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index 94a4a6309..2017cb745 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -40,7 +40,7 @@ jobs: env: PROPERTIES_PATH: "android/key.properties" JAVA_VERSION: "11.x" - FLUTTER_VERSION: "3.7.2" + FLUTTER_VERSION: "3.10.6" defaults: run: working-directory: ./uni From fa2a3edc33667f8a03d6df68d17dbf7d879e9aaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Duarte?= Date: Tue, 22 Aug 2023 19:56:21 +0100 Subject: [PATCH 08/13] fix linting --- uni/lib/view/useful_info/widgets/other_links_card.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uni/lib/view/useful_info/widgets/other_links_card.dart b/uni/lib/view/useful_info/widgets/other_links_card.dart index 6ed1bf9fb..a1a43bf48 100644 --- a/uni/lib/view/useful_info/widgets/other_links_card.dart +++ b/uni/lib/view/useful_info/widgets/other_links_card.dart @@ -9,8 +9,8 @@ class OtherLinksCard extends GenericExpansionCard { @override Widget buildCardContent(BuildContext context) { - return Column( - children: const [ + return const Column( + children: [ // LinkButton(title: 'Impressão', link: 'https://print.up.pt'), // TODO(Process-ing): Get fixed link LinkButton( From d96185f6acc687e633186720b22a9770ee3bbc3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Duarte?= Date: Thu, 24 Aug 2023 21:19:11 +0100 Subject: [PATCH 09/13] update readme to accomodate generated files --- uni/README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/uni/README.md b/uni/README.md index f9d2ee3c1..e718bd0fe 100644 --- a/uni/README.md +++ b/uni/README.md @@ -30,6 +30,34 @@ In order to remove it, is it as simple as running the following command, from th rm .git/hooks/pre-commit ``` +### Generated files + +Flutter doesn't support runtime reflection, in order to circumvent these limitations, we use **automatic code generation** or **static metaprogramming** for things like **mocks** and other possible usecases. By convention, you should **always commit** the generated `.dart` files into the repository. + +Dart leverages annotations to signal the `build_runner` that it should generate some code. They look something like this: +```dart + import 'package:mockito/annotations.dart' + + class Cat{ + } + + @GenerateNiceMocks([MockSpec()]) + void main(){ + + } +``` +In this case, `build_runner` will dectect that `GenerateNiceMocks` is a generator function from `mockito` and will generate code to a different file. + +In order to run the `build_runner` once: +```sh +dart run build_runner build +``` + +But you can also watch for changes in `.dart` files and automatically run the `build_runner` on those file changes (useful if you find yourself need to generate code very frequently): +```sh +dart run build_runner watch +``` + ## Project structure ### Overview From 46c06b024b8764b3231f3563b1cd5406646aac48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Duarte?= Date: Thu, 24 Aug 2023 21:20:11 +0100 Subject: [PATCH 10/13] Exclude mock files from being formatted or linted --- .github/workflows/format_lint_test.yaml | 2 +- uni/analysis_options.yaml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/format_lint_test.yaml b/.github/workflows/format_lint_test.yaml index 9b4b9055b..0fb4e2d6d 100644 --- a/.github/workflows/format_lint_test.yaml +++ b/.github/workflows/format_lint_test.yaml @@ -20,7 +20,7 @@ jobs: with: flutter-version: ${{ env.FLUTTER_VERSION }} - - run: dart format $(find . -type f -name "*.dart" -a -not -name "*.g.dart") --set-exit-if-changed + - run: dart format $(find . -type f -name "*.dart" -a -not -name "*.g.dart" -a -not -name "*.mocks.dart") --set-exit-if-changed lint: name: "Lint" diff --git a/uni/analysis_options.yaml b/uni/analysis_options.yaml index 92d895f92..6acf469de 100644 --- a/uni/analysis_options.yaml +++ b/uni/analysis_options.yaml @@ -4,6 +4,7 @@ analyzer: # Exclude auto-generated files from dart analysis exclude: - "**.g.dart" + - "**.mocks.dart" # Custom linter rules. A list of all rules can be found at # https://dart-lang.github.io/linter/lints/options/options.html From 7a44a0041a00862178b06d8451043b0f1a3c213e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Duarte?= Date: Thu, 24 Aug 2023 21:30:14 +0100 Subject: [PATCH 11/13] make pre-commit hook not format mock files --- pre-commit-hook.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pre-commit-hook.sh b/pre-commit-hook.sh index 838253711..c8f93c62b 100755 --- a/pre-commit-hook.sh +++ b/pre-commit-hook.sh @@ -3,7 +3,7 @@ mkdir -p .git/hooks #it seems that are some cases where git will not create a ho tee .git/hooks/pre-commit << EOF #!/bin/sh -FILES="\$(git diff --name-only --cached | grep .*\.dart | grep -v .*\.g\.dart)" +FILES="\$(git diff --name-only --cached | grep .*\.dart | grep -v .*\.g\.dart | grep -v .*\.mocks\.dart)" [ -z "\$FILES" ] && exit 0 From 1142b57f12731d82552874452d3c3ae44c9a61de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Duarte?= Date: Fri, 25 Aug 2023 16:21:29 +0100 Subject: [PATCH 12/13] Update README.md grammer --- uni/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/uni/README.md b/uni/README.md index e718bd0fe..b6c91e4eb 100644 --- a/uni/README.md +++ b/uni/README.md @@ -32,7 +32,7 @@ In order to remove it, is it as simple as running the following command, from th ### Generated files -Flutter doesn't support runtime reflection, in order to circumvent these limitations, we use **automatic code generation** or **static metaprogramming** for things like **mocks** and other possible usecases. By convention, you should **always commit** the generated `.dart` files into the repository. +Flutter doesn't support runtime reflection. In order to circumvent these limitations, we use **automatic code generation** or **static metaprogramming** for things like **mocks** and other possible usecases. By convention, you should **always commit** the generated `.dart` files into the repository. Dart leverages annotations to signal the `build_runner` that it should generate some code. They look something like this: ```dart @@ -46,14 +46,14 @@ Dart leverages annotations to signal the `build_runner` that it should generate } ``` -In this case, `build_runner` will dectect that `GenerateNiceMocks` is a generator function from `mockito` and will generate code to a different file. +In this case, `build_runner` will detect that `GenerateNiceMocks` is a generator function from `mockito` and will generate code to a different file. In order to run the `build_runner` once: ```sh dart run build_runner build ``` -But you can also watch for changes in `.dart` files and automatically run the `build_runner` on those file changes (useful if you find yourself need to generate code very frequently): +But you can also watch for changes in `.dart` files and automatically run the `build_runner` on those file changes (useful if you find yourself in need to generate code very frequently): ```sh dart run build_runner watch ``` From 006e281e7efb0bee529327f2f438edd5b13212ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Duarte?= Date: Thu, 31 Aug 2023 23:06:19 +0100 Subject: [PATCH 13/13] fix tests --- uni/test/test_widget.dart | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/uni/test/test_widget.dart b/uni/test/test_widget.dart index c8430b967..3171ad692 100644 --- a/uni/test/test_widget.dart +++ b/uni/test/test_widget.dart @@ -1,13 +1,20 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import 'package:uni/model/providers/startup/profile_provider.dart'; +import 'package:uni/model/providers/startup/session_provider.dart'; Widget testableWidget( Widget widget, { List providers = const [], }) { - if (providers.isEmpty) return wrapWidget(widget); - - return MultiProvider(providers: providers, child: wrapWidget(widget)); + return MultiProvider( + providers: [ + ChangeNotifierProvider(create: (context) => SessionProvider()), + ChangeNotifierProvider(create: (context) => ProfileProvider()), + ...providers + ], + child: wrapWidget(widget), + ); } Widget wrapWidget(Widget widget) {