Skip to content

Commit

Permalink
Unit testing setup (#206)
Browse files Browse the repository at this point in the history
* First working test

* Create testing yml

* Exclude generated mock files

* Add another test and update test job

* test getVersionSemVer and fix bug in it

* remove concurrency check from testing job

* First test which mocks hive and riverpod

also made add/remove methods async for stored devices

* Update testing.yml

* remove matrix and prevent duplicate runs on PR

* add codecov.yml
  • Loading branch information
Codel1417 authored Jun 4, 2024
1 parent d880109 commit de7bdaa
Show file tree
Hide file tree
Showing 11 changed files with 395 additions and 21 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
on:
push:
branches:
- master
paths-ignore:
- '*.md'
pull_request:
jobs:
run-tests:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Environment
uses: ./.github/actions/setup_build
- name: Pre Build Tasks
uses: ./.github/actions/pre_build
- name: Run Tests
run: flutter test --coverage
- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage/lcov.info
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ android/build/
android/key.properties

lib/gen/assets.gen.dart

coverage/

*.mocks.dart
15 changes: 15 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
coverage:
status:
project: #add everything under here, more options at https://docs.codecov.com/docs/commit-status
default:
# basic
target: auto #default
threshold: 0%
base: auto
comment: #this is a top-level key
layout: " diff, flags, files"
behavior: default
require_changes: false # if true: only post the comment if coverage changes
require_base: false # [true :: must have a base report to post]
require_head: true # [true :: must have a head report to post]
hide_project_coverage: false # [true :: only show coverage on the git diff aka patch coverage]]
8 changes: 4 additions & 4 deletions lib/Backend/Bluetooth/bluetooth_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ class KnownDevices extends _$KnownDevices {
return results;
}

void add(BaseStatefulDevice baseStatefulDevice) {
Future<void> add(BaseStatefulDevice baseStatefulDevice) async {
Map<String, BaseStatefulDevice> state2 = Map.from(state);
state2[baseStatefulDevice.baseStoredDevice.btMACAddress] = baseStatefulDevice;
state = state2;
store();
await store();
}

void remove(String id) {
Future<void> remove(String id) async {
Map<String, BaseStatefulDevice> state2 = Map.from(state);
state2.remove(id);
state = state2;
store();
await store();
}

Future<void> store() async {
Expand Down
21 changes: 11 additions & 10 deletions lib/Frontend/utils.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:cross_platform/cross_platform.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
Expand All @@ -7,22 +6,25 @@ import 'package:logarte/logarte.dart';
import 'package:logging/logging.dart';
import 'package:native_dio_adapter/native_dio_adapter.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:platform/platform.dart';
import 'package:pub_semver/pub_semver.dart';
import 'package:sentry_dio/sentry_dio.dart';
import 'package:wordpress_client/wordpress_client.dart';

import '../Backend/LoggingWrappers.dart';

LocalPlatform platform = const LocalPlatform();

Future<bool> getBluetoothPermission(Logger logger) async {
bool granted = false;
if (Platform.isAndroid && (await DeviceInfoPlugin().androidInfo).version.sdkInt > 30) {
if (platform.isAndroid && (await DeviceInfoPlugin().androidInfo).version.sdkInt > 30) {
PermissionStatus permissionStatusScan = await Permission.bluetoothScan.request();
logger.info("permissionStatusScan $permissionStatusScan");
granted = PermissionStatus.granted == permissionStatusScan;
PermissionStatus permissionStatusConnect = await Permission.bluetoothConnect.request();
logger.info("permissionStatusConnect $permissionStatusConnect");
granted = granted && PermissionStatus.granted == permissionStatusConnect;
} else if (Platform.isAndroid) {
} else if (platform.isAndroid) {
PermissionStatus permissionStatusLocation = await Permission.location.request();
logger.info("permissionStatusLocation $permissionStatusLocation");
granted = PermissionStatus.granted == permissionStatusLocation;
Expand Down Expand Up @@ -77,8 +79,8 @@ Version getVersionSemVer(String input) {
if (split.length > 1 && int.tryParse(split[1]) != null) {
minor = split[1];
}
if (split.length > 2 && int.tryParse(split[2]) != null) {
patch = split[2].replaceAll(RegExp(r"\D"), "");
if (split.length > 2 && int.tryParse(split[2].replaceAll(RegExp(r'[^0-9]'), '')) != null) {
patch = split[2].replaceAll(RegExp(r'[^0-9]'), '');
}
return Version(int.parse(major), int.parse(minor), int.parse(patch));
}
Expand Down Expand Up @@ -129,11 +131,10 @@ Future<void> setupSystemColor(BuildContext context) async {

String getOutboundUtm() {
String utm = "?utm_medium=Tail_App";

if (Platform.isAndroid) {
utm = "$utm?utm_source=tailappandr'";
} else if (Platform.isIOS) {
utm = "$utm?utm_source=tailappios'";
if (platform.isAndroid) {
utm = "$utm?utm_source=tailappandr";
} else if (platform.isIOS) {
utm = "$utm?utm_source=tailappios";
}

return utm;
Expand Down
Loading

0 comments on commit de7bdaa

Please sign in to comment.