From 63d75136f6dd7733a3d16dadc10d71a0c4bb0c13 Mon Sep 17 00:00:00 2001 From: Seungbin Oh Date: Sun, 3 Nov 2024 22:10:59 +0900 Subject: [PATCH] chore: add unit test to improve coverage --- lib/providers/info_model.dart | 13 ++++++++++++- lib/providers/timetable_model.dart | 9 ++++++++- test/pages/pump_test.dart | 13 ++++++++++--- test/utils/extensions.dart | 4 ++++ test/widgets/pump_test.dart | 28 +++++++++++++++++++++++++--- 5 files changed, 59 insertions(+), 8 deletions(-) diff --git a/lib/providers/info_model.dart b/lib/providers/info_model.dart index 97ab2093..96529257 100644 --- a/lib/providers/info_model.dart +++ b/lib/providers/info_model.dart @@ -46,7 +46,18 @@ class InfoModel extends ChangeNotifier { myTimetableLectures: [], reviewWritableLectures: [], reviews: []); - _semesters = []; + _semesters = [ + Semester( + year: 2000, + semester: 1, + beginning: DateTime(2000), + end: DateTime(2001)) + ]; + _currentSchedule = { + "semester": _semesters.first, + "name": 'home.schedule.beginning', + "time": DateTime.now() + }; } } diff --git a/lib/providers/timetable_model.dart b/lib/providers/timetable_model.dart index 42997abc..10f0922b 100644 --- a/lib/providers/timetable_model.dart +++ b/lib/providers/timetable_model.dart @@ -54,11 +54,18 @@ class TimetableModel extends ChangeNotifier { myTimetableLectures: [], reviewWritableLectures: [], reviews: []); - _semesters = []; + _semesters = [ + Semester( + year: 2024, + semester: 3, + beginning: DateTime.now(), + end: DateTime.now()), + ]; _timetables = [ Timetable(id: 0, lectures: []), Timetable(id: 1, lectures: []) ]; + _selectedSemesterIndex = 0; } } diff --git a/test/pages/pump_test.dart b/test/pages/pump_test.dart index bde13210..78ab4f5d 100644 --- a/test/pages/pump_test.dart +++ b/test/pages/pump_test.dart @@ -5,12 +5,16 @@ import 'package:otlplus/pages/course_detail_page.dart'; import 'package:otlplus/pages/course_search_page.dart'; import 'package:otlplus/pages/lecture_detail_page.dart'; import 'package:otlplus/pages/lecture_search_page.dart'; +import 'package:otlplus/pages/main_page.dart'; +import 'package:otlplus/pages/my_review_page.dart'; import 'package:otlplus/pages/people_page.dart'; import 'package:otlplus/pages/privacy_page.dart'; import 'package:otlplus/pages/settings_page.dart'; import 'package:otlplus/pages/timetable_page.dart'; +import 'package:otlplus/pages/user_page.dart'; import 'package:otlplus/providers/course_detail_model.dart'; import 'package:otlplus/providers/course_search_model.dart'; +import 'package:otlplus/providers/info_model.dart'; import 'package:otlplus/providers/lecture_detail_model.dart'; import 'package:otlplus/providers/lecture_search_model.dart'; import 'package:otlplus/providers/settings_model.dart'; @@ -59,11 +63,14 @@ void main() { }); testWidgets("pump MainPage", (WidgetTester tester) async { - // tester.pumpWidget(MainPage().materialAndNotifier(InfoModel())); + tester.pumpWidget(MainPage( + changeIndex: (int index) {}, + ).materialAndNotifier(InfoModel(forTest: true))); }); testWidgets("pump MyReviewPage", (WidgetTester tester) async { - // tester.pumpWidget(MyReviewPage().materialAndNotifier(InfoModel(forTest: true))); + tester.pumpWidget( + MyReviewPage().materialAndNotifier(InfoModel(forTest: true))); }); testWidgets("pump PeoplePage", (WidgetTester tester) async { @@ -88,6 +95,6 @@ void main() { }); testWidgets("pump UserPage", (WidgetTester tester) async { - // tester.pumpWidget(UserPage().materialAndNotifier(InfoModel())); + tester.pumpWidget(UserPage().materialAndNotifier(InfoModel(forTest: true))); }); } diff --git a/test/utils/extensions.dart b/test/utils/extensions.dart index 3a319c4d..796c40c4 100644 --- a/test/utils/extensions.dart +++ b/test/utils/extensions.dart @@ -21,6 +21,10 @@ extension WidgetForTest on Widget { ), ); + Widget get inScrollView => SingleChildScrollView( + child: this, + ); + Widget materialAndNotifier(T model) { return ChangeNotifierProvider( create: (_) => model, child: MaterialApp(home: this)); diff --git a/test/widgets/pump_test.dart b/test/widgets/pump_test.dart index 7772cefc..0039bf2f 100644 --- a/test/widgets/pump_test.dart +++ b/test/widgets/pump_test.dart @@ -4,12 +4,16 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:otlplus/providers/lecture_search_model.dart'; import 'package:otlplus/providers/timetable_model.dart'; import 'package:otlplus/widgets/course_block.dart'; +import 'package:otlplus/widgets/dropdown.dart'; +import 'package:otlplus/widgets/expandable_text.dart'; import 'package:otlplus/widgets/lecture_group_block.dart'; import 'package:otlplus/widgets/lecture_group_block_row.dart'; import 'package:otlplus/widgets/lecture_group_simple_block.dart'; import 'package:otlplus/widgets/lecture_search.dart'; import 'package:otlplus/widgets/lecture_simple_block.dart'; import 'package:otlplus/widgets/review_write_block.dart'; +import 'package:otlplus/widgets/semester_picker.dart'; +import 'package:otlplus/widgets/timetable.dart'; import 'package:otlplus/widgets/timetable_block.dart'; import 'package:otlplus/widgets/timetable_summary.dart'; import 'package:otlplus/widgets/timetable_tabs.dart'; @@ -29,6 +33,20 @@ void main() { await tester.pumpWidget(CourseBlock(course: SampleCourse.shared).material); }); + testWidgets('pump Dropdown', (WidgetTester tester) async { + await tester.pumpWidget(Dropdown( + customButton: Text('Dropdown'), + items: [ + ItemData(value: 1, text: 'Item 1'), + ], + onChanged: (_) {}, + ).scaffold); + }); + + testWidgets('pump ExpandableText', (WidgetTester tester) async { + await tester.pumpWidget(ExpandableText('text').material); + }); + testWidgets('pump LectureGroupBlockRow', (WidgetTester tester) async { await tester.pumpWidget(LectureGroupBlockRow(lecture: SampleLecture.shared) .materialAndNotifier(TimetableModel(forTest: true))); @@ -64,8 +82,8 @@ void main() { }); testWidgets('pump SemesterPicker', (WidgetTester tester) async { - // await tester - // .pumpWidget(SemesterPicker(onSemesterChanged: () => null).scaffoldAndNotifier(TimetableModel())); + await tester.pumpWidget(SemesterPicker(onSemesterChanged: () => null) + .scaffoldAndNotifier(TimetableModel(forTest: true))); }); testWidgets('pump TimetableBlock', (WidgetTester tester) async { @@ -89,7 +107,11 @@ void main() { }); testWidgets('pump Timetable', (WidgetTester tester) async { - // await tester.pumpWidget(widget.Timetable(lectures: [], builder: (lecture,_)=> TimetableBlock(lecture: lecture)).scaffold); + await tester.pumpWidget(Timetable( + lectures: [], + builder: (lecture, _, __) => TimetableBlock(lecture: lecture)) + .inScrollView + .material); }); testWidgets('pump TodayTimetable', (WidgetTester tester) async {