Skip to content

Commit

Permalink
chore: add unit test to improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
sboh1214 committed Nov 3, 2024
1 parent 813212c commit 63d7513
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 8 deletions.
13 changes: 12 additions & 1 deletion lib/providers/info_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
}
}

Expand Down
9 changes: 8 additions & 1 deletion lib/providers/timetable_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
13 changes: 10 additions & 3 deletions test/pages/pump_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 {
Expand All @@ -88,6 +95,6 @@ void main() {
});

testWidgets("pump UserPage", (WidgetTester tester) async {
// tester.pumpWidget(UserPage().materialAndNotifier(InfoModel()));
tester.pumpWidget(UserPage().materialAndNotifier(InfoModel(forTest: true)));
});
}
4 changes: 4 additions & 0 deletions test/utils/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ extension WidgetForTest on Widget {
),
);

Widget get inScrollView => SingleChildScrollView(
child: this,
);

Widget materialAndNotifier<T extends ChangeNotifier>(T model) {
return ChangeNotifierProvider(
create: (_) => model, child: MaterialApp(home: this));
Expand Down
28 changes: 25 additions & 3 deletions test/widgets/pump_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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)));
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 63d7513

Please sign in to comment.