Skip to content

Commit

Permalink
Merge pull request #159 from DislikesSchool/improve-coverage
Browse files Browse the repository at this point in the history
Improve coverage
  • Loading branch information
vyPal authored Mar 11, 2024
2 parents a3efd57 + bd29140 commit c516640
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 25 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/test-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@ jobs:
test/**
integration_test/**
build:
runs-on: macos-latest
runs-on: ubuntu-latest
needs: check_changes
if: needs.check_changes.outputs.run_build == 'true'
steps:
- name: Enable KVM group perms
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- uses: actions/checkout@v3
with:
fetch-depth: 0
Expand Down
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ android {
versionName flutterVersionName
targetSdkVersion 33
minSdkVersion 21
compileSdkVersion 33
compileSdkVersion 34
multiDexEnabled true
}

Expand Down
71 changes: 66 additions & 5 deletions integration_test/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@ void main() {
String? password = const String.fromEnvironment("PASSWORD");
String? name = const String.fromEnvironment("NAME");

String token = "";

testWidgets('Run app and login', (tester) async {
await prep(tester, username, password, name);
await prep(tester, username, password, name, true, "https://ep2.vypal.me",
false, "");
SharedPreferences prefs = await SharedPreferences.getInstance();
token = prefs.getString("token") ?? "";
expect(find.text(name), findsWidgets);
expect(find.text("Username"), findsNothing);
});

testWidgets('Test TimeTable page', (tester) async {
await prep(tester, username, password, name);
await prep(tester, username, password, name, false, "", false, token);

await tester.pump(const Duration(seconds: 1));

Expand All @@ -43,7 +49,7 @@ void main() {
});

testWidgets('Test TimeTable page scroll', (tester) async {
await prep(tester, username, password, name);
await prep(tester, username, password, name, false, "", true, token);

await tester.tap(find.byType(NavigationDestination).at(1));
await tester.pump(const Duration(seconds: 1));
Expand All @@ -65,12 +71,67 @@ void main() {
await pumpUntilFound(tester, find.textContaining("$day $month"));
expect(find.textContaining("$day $month"), findsWidgets);
});

testWidgets('Test Messages page', (tester) async {
await prep(tester, username, password, name, false, "", true, token);

await tester.tap(find.byType(NavigationDestination).at(2));
await tester.pump(const Duration(seconds: 1));

await pumpUntilFound(tester, find.text("Messages"));
expect(find.text("Messages"), findsWidgets);
expect(find.byType(Card), findsWidgets);
});
testWidgets('Test Message page', (tester) async {
await prep(tester, username, password, name, false, "", false, "");

await tester.tap(find.byType(NavigationDestination).at(2));

await pumpUntilFound(tester, find.text("Messages"));
expect(find.text("Messages"), findsWidgets);
Finder f = find.byWidgetPredicate((widget) =>
widget is Icon &&
widget.size == 18 &&
widget.icon == Icons.arrow_right_rounded);
await pumpUntilFound(tester, f);
expect(f, findsWidgets);

await tester.tap(f.at(0));
await tester.pump(const Duration(seconds: 1));

await pumpUntilFound(tester, f);
expect(f, findsOneWidget);
expect(find.byType(Card), findsWidgets);
});

testWidgets('Test Homework page', (tester) async {
await prep(tester, username, password, name, false, "", true, token);

await tester.tap(find.byType(NavigationDestination).at(3));
await tester.pump(const Duration(seconds: 1));

await pumpUntilFound(tester, find.text("Homework"));
expect(find.text("Homework"), findsWidgets);
expect(find.byType(Card), findsWidgets);
});
});
}

Future<void> prep(
WidgetTester tester, String username, String password, String name) async {
SharedPreferences.setMockInitialValues({});
WidgetTester tester,
String username,
String password,
String name,
bool enableiCanteen,
String customEndPoint,
bool quickstart,
String token) async {
SharedPreferences.setMockInitialValues({
"ice": enableiCanteen,
"customEndpoint": customEndPoint,
"quickstart": quickstart,
"token": token
});
final FlutterExceptionHandler? originalOnError = FlutterError.onError;
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
Expand Down
18 changes: 0 additions & 18 deletions lib/load.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:async';
import 'package:eduapge2/api.dart';
import 'package:eduapge2/login.dart';
import 'package:eduapge2/main.dart';
import 'package:firebase_remote_config/firebase_remote_config.dart';
import 'package:flutter/material.dart';
import 'package:flutter_session_manager/flutter_session_manager.dart';
import 'package:shared_preferences/shared_preferences.dart';
Expand All @@ -29,12 +28,8 @@ class LoadingScreenState extends BaseState<LoadingScreen> {
double progress = 0.0;
String loaderText = "Loading...";

String baseUrl = FirebaseRemoteConfig.instance.getString("testUrl");

late AppLocalizations? local;

late bool quickstart;

@override
void initState() {
super.initState();
Expand All @@ -44,11 +39,6 @@ class LoadingScreenState extends BaseState<LoadingScreen> {
if (startedInit) return;
startedInit = true;
sharedPreferences = await SharedPreferences.getInstance();
String? endpoint = sharedPreferences.getString("customEndpoint");
if (endpoint != null && endpoint != "") {
baseUrl = endpoint;
}
quickstart = sharedPreferences.getBool('quickstart') ?? false;
if (sharedPreferences.getBool("ice") == true) {
sessionManager.set("iCanteenEnabled", true);
}
Expand Down Expand Up @@ -84,14 +74,6 @@ class LoadingScreenState extends BaseState<LoadingScreen> {
});
}

DateTime getWeekDay() {
DateTime now = DateTime.now();
if (now.weekday > 5) {
now.add(Duration(days: 8 - now.weekday));
}
return DateTime(now.year, now.month, now.day);
}

@override
Widget build(BuildContext context) {
if (!startedInit) {
Expand Down

0 comments on commit c516640

Please sign in to comment.