Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fix dependencies and support unit tests for app #619 #1131 #1233

Draft
wants to merge 54 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
e859d60
fix: missing deps
vincentkoc Nov 1, 2024
0495915
Update .gitignore
vincentkoc Nov 1, 2024
1d41cf3
Create test.sh
vincentkoc Nov 1, 2024
1e7b0e4
Create app_test.dart
vincentkoc Nov 1, 2024
0d8dc54
Create app_test.mocks.dart
vincentkoc Nov 1, 2024
efdd13e
Create basic_test.dart
vincentkoc Nov 1, 2024
9be4025
Create mock_helper.dart
vincentkoc Nov 1, 2024
1978550
Create firebase_mock.dart
vincentkoc Nov 1, 2024
ecc4a9b
Update pubspec.yaml
vincentkoc Nov 1, 2024
3e00786
Update main.dart
vincentkoc Nov 1, 2024
f90a396
Create app_test.dart
vincentkoc Nov 1, 2024
246fdeb
Update app_test.mocks.dart
vincentkoc Nov 1, 2024
f562b24
Update app_test.dart
vincentkoc Nov 1, 2024
a7c8042
fix: font loading strict nomenclature
vincentkoc Nov 1, 2024
b1066d6
Update pubspec.yaml
vincentkoc Nov 1, 2024
b7ae798
Create auth_provider_test.dart
vincentkoc Nov 1, 2024
b526272
Create auth_provider_test.mocks.dart
vincentkoc Nov 1, 2024
bddc0be
Update main.dart
vincentkoc Nov 1, 2024
a3b0bf5
Update test.sh
vincentkoc Nov 1, 2024
b4c8405
Create message_test.dart
vincentkoc Nov 1, 2024
1fad845
Update mock_helper.dart
vincentkoc Nov 1, 2024
e4e1f76
Update auth_provider_test.dart
vincentkoc Nov 1, 2024
66b8e32
Create capture_provider_test.dart
vincentkoc Nov 1, 2024
f6aeb8a
Create capture_provider_test.mocks.dart
vincentkoc Nov 1, 2024
0e747e8
Create memory_provider_test.dart
vincentkoc Nov 1, 2024
083b058
Create memory_provider_test.mocks.dart
vincentkoc Nov 1, 2024
7613c7e
Create device_connection_test.dart
vincentkoc Nov 1, 2024
424e02f
Create device_connection_test.mocks.dart
vincentkoc Nov 1, 2024
c7f2c24
Create notifications_test.dart
vincentkoc Nov 1, 2024
3581811
Update test.sh
vincentkoc Nov 1, 2024
5b8da1c
Create Makefile
vincentkoc Nov 1, 2024
510a980
Update message_test.dart
vincentkoc Nov 1, 2024
89292b9
Create auth_mock_helper.dart
vincentkoc Nov 1, 2024
88ffdfc
Update mock_helper.dart
vincentkoc Nov 1, 2024
701e73f
Update auth_provider_test.dart
vincentkoc Nov 1, 2024
3a4aaff
Update auth_provider_test.mocks.dart
vincentkoc Nov 1, 2024
dff53cf
Create notifications_test.mocks.dart
vincentkoc Nov 1, 2024
ec09cd2
Update notifications_test.dart
vincentkoc Nov 1, 2024
f84e3e8
Update main.dart
vincentkoc Nov 2, 2024
9cc6b6e
Update Makefile
vincentkoc Nov 2, 2024
661559f
Update Podfile
vincentkoc Nov 2, 2024
03f7029
Update test.sh
vincentkoc Nov 2, 2024
4472624
Update test.sh
vincentkoc Nov 2, 2024
d319d1c
Update test.sh
vincentkoc Nov 2, 2024
212aa92
Update .gitignore
vincentkoc Nov 2, 2024
76bf9a6
if exists on pod
vincentkoc Nov 2, 2024
50df4df
Update .env.template
vincentkoc Nov 2, 2024
5afd8cc
chore: update firebase
vincentkoc Nov 2, 2024
48e422e
Update AppDelegate.swift
vincentkoc Nov 2, 2024
fe5b10c
Update app/Makefile
vincentkoc Nov 3, 2024
44e90ee
Update app/Makefile
vincentkoc Nov 3, 2024
2be42b6
Update app/test/app_test.dart
vincentkoc Nov 3, 2024
2ac7c82
Update app/test/app_test.dart
vincentkoc Nov 3, 2024
0c9dd2b
Update app/test/providers/capture_provider_test.mocks.dart
vincentkoc Nov 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ dist/
**/ios/Runner/GoogleService-Info.plist
**/ios/Config/*
**/ios/Config/**/*
**/ios/ogg.xcframework
****/ios/opus.xcframework

# macOS specific
**/macos/**/Pods/
Expand All @@ -63,6 +65,7 @@ dist/
**/macos/.generated/
**/macos/Runner.xcworkspace
**/macos/**/GeneratedPluginRegistrant.*
**/macos/Runner/GoogleService-Info.plist

# Linux specific
**/linux/.dart_tool/
Expand Down Expand Up @@ -112,6 +115,7 @@ src/recordings

# test output
test/recordings
app/coverage

# Flutter
env.g.dart
Expand Down
19 changes: 19 additions & 0 deletions app/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.PHONY: test build clean

test:
@echo "🧪 Running tests..."
@dart run build_runner build --delete-conflicting-outputs
@if ! ./test.sh; then \
echo "❌ Tests failed"; \
exit 1; \
fi
vincentkoc marked this conversation as resolved.
Show resolved Hide resolved

build:
@echo "🏗️ Building..."
@dart run build_runner build --delete-conflicting-outputs
vincentkoc marked this conversation as resolved.
Show resolved Hide resolved

clean:
@echo "🧹 Cleaning..."
@flutter clean
@rm -rf coverage
@rm -rf build
vincentkoc marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 18 additions & 0 deletions app/integration_test/app_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'package:integration_test/integration_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:friend_private/main.dart';
import 'package:flutter/material.dart';

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

group('Full App Tests', () {
testWidgets('App shows onboarding flow', (tester) async {
await tester.pumpWidget(const MyApp());
await tester.pumpAndSettle();

// Test full app flow with real dependencies
expect(find.byType(DeciderWidget), findsOneWidget);
});
vincentkoc marked this conversation as resolved.
Show resolved Hide resolved
});
}
21 changes: 20 additions & 1 deletion app/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ platform :ios, '15.0'
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

# Add script to download XCFrameworks
def download_xcframework(url, name)
system("echo downloading #{url}")
system("curl -L #{url} -o #{name}.xcframework.zip")
system("unzip -o #{name}.xcframework.zip")
system("rm #{name}.xcframework.zip")
end
vincentkoc marked this conversation as resolved.
Show resolved Hide resolved

project 'Runner', {
'Debug-prod' => :debug,
'Profile-prod' => :release,
Expand All @@ -30,6 +38,10 @@ require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelpe

flutter_ios_podfile_setup

# Download XCFrameworks before installing pods
download_xcframework("https://github.com/sbooth/opus-binary-xcframework/releases/download/0.2.0/opus.xcframework.zip", "opus")
download_xcframework("https://github.com/sbooth/ogg-binary-xcframework/releases/download/0.1.0/ogg.xcframework.zip", "ogg")
vincentkoc marked this conversation as resolved.
Show resolved Hide resolved

target 'Runner' do
use_frameworks! :linkage => :static
use_modular_headers!
Expand All @@ -42,6 +54,13 @@ post_install do |installer|
flutter_additional_ios_build_settings(target)
target.build_configurations.each do |config|
config.build_settings.delete 'IPHONEOS_DEPLOYMENT_TARGET'
# Add framework search paths for manually added XCFrameworks
config.build_settings['FRAMEWORK_SEARCH_PATHS'] ||= ['$(inherited)']
config.build_settings['FRAMEWORK_SEARCH_PATHS'] << '$(PROJECT_DIR)'
# Add specific settings for opus and ogg
config.build_settings['OTHER_LDFLAGS'] ||= ['$(inherited)']
config.build_settings['OTHER_LDFLAGS'] << '-framework opus'
config.build_settings['OTHER_LDFLAGS'] << '-framework ogg'
vincentkoc marked this conversation as resolved.
Show resolved Hide resolved
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [
'$(inherited)',

Expand All @@ -50,7 +69,7 @@ post_install do |installer|

# dart: PermissionGroup.bluetooth
'PERMISSION_BLUETOOTH=1',

## The 'PERMISSION_LOCATION' macro enables the `locationWhenInUse` and `locationAlways` permission. If
## the application only requires `locationWhenInUse`, only specify the `PERMISSION_LOCATION_WHENINUSE`
## macro.
Expand Down
74 changes: 33 additions & 41 deletions app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,24 @@ class _DeciderWidgetState extends State<DeciderWidget> {
if (SharedPreferencesUtil().onboardingCompleted && authProvider.user != null) {
return const HomePageWrapper();
} else {
return const OnboardingWrapper();
return LayoutBuilder(
builder: (context, constraints) {
return SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: constraints.maxHeight,
minWidth: constraints.maxWidth,
),
child: IntrinsicHeight(
child: DefaultTextStyle(
style: Theme.of(context).textTheme.bodyMedium!,
child: const OnboardingWrapper(),
),
),
),
);
},
);
}
},
);
Expand All @@ -308,12 +325,16 @@ class _DeciderWidgetState extends State<DeciderWidget> {
class CustomErrorWidget extends StatelessWidget {
final String errorMessage;

const CustomErrorWidget({super.key, required this.errorMessage});
const CustomErrorWidget({
super.key,
required this.errorMessage,
});

@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
return Center(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expand All @@ -322,48 +343,19 @@ class CustomErrorWidget extends StatelessWidget {
color: Colors.red,
size: 50.0,
),
const SizedBox(height: 10.0),
const SizedBox(height: 16.0),
const Text(
'Something went wrong! Please try again later.',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold),
),
const SizedBox(height: 10.0),
Container(
padding: const EdgeInsets.all(10),
margin: const EdgeInsets.all(16),
height: 200,
decoration: BoxDecoration(
color: const Color.fromARGB(255, 63, 63, 63),
borderRadius: BorderRadius.circular(10),
),
child: Text(
errorMessage,
textAlign: TextAlign.start,
style: const TextStyle(fontSize: 16.0),
),
),
const SizedBox(height: 10.0),
SizedBox(
width: 210,
child: ElevatedButton(
style: ElevatedButton.styleFrom(backgroundColor: Colors.red),
onPressed: () {
Clipboard.setData(ClipboardData(text: errorMessage));
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Error message copied to clipboard'),
),
);
},
child: const Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('Copy error message'),
SizedBox(width: 10),
Icon(Icons.copy_rounded),
],
const SizedBox(height: 16.0),
Expanded(
child: SingleChildScrollView(
key: const Key('error_message_scroll_view'),
child: Text(
errorMessage,
style: const TextStyle(fontSize: 16.0),
),
),
),
Expand Down
21 changes: 11 additions & 10 deletions app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ environment:
dependencies:
flutter:
sdk: flutter

# State Management
provider: ^6.1.2
flutter_provider_utilities: ^1.0.6
Expand All @@ -20,7 +20,7 @@ dependencies:
flutter_localizations:
sdk: flutter

# UI
# UI
auto_size_text: 3.0.0
lottie: ^3.1.2
expandable_text: ^2.3.0
Expand Down Expand Up @@ -126,6 +126,7 @@ dev_dependencies:
envied_generator: ^0.5.4+1
build_runner: ^2.4.11
flutter_flavorizr: ^2.2.3
mockito: ^5.4.4


flutter_launcher_icons:
Expand Down Expand Up @@ -155,23 +156,23 @@ flutter:
fonts:
- family: 'SF Pro Display'
fonts:
- asset: assets/fonts/SFPRODISPLAYTHINITALIC.OTF
- asset: assets/fonts/SFProDisplayThinItalic.otf
weight: 100
style: italic
- asset: assets/fonts/SFPRODISPLAYLIGHTITALIC.OTF
- asset: assets/fonts/SFProDisplayLightItalic.otf
weight: 300
style: italic
- asset: assets/fonts/SFPRODISPLAYREGULAR.OTF
- asset: assets/fonts/SFPRODISPLAYHEAVYITALIC.OTF
- asset: assets/fonts/SFProDisplayRegular.otf
- asset: assets/fonts/SFProDisplayHeavyItalic.otf
style: italic
- asset: assets/fonts/SFPRODISPLAYMEDIUM.OTF
- asset: assets/fonts/SFProDisplayMedium.otf
weight: 500
- asset: assets/fonts/SFPRODISPLAYSEMIBOLDITALIC.OTF
- asset: assets/fonts/SFProDisplaySemiboldItalic.otf
weight: 600
style: italic
- asset: assets/fonts/SFPRODISPLAYBOLD.OTF
- asset: assets/fonts/SFProDisplayBold.otf
weight: 700
- asset: assets/fonts/SFPRODISPLAYBLACKITALIC.OTF
- asset: assets/fonts/SFProDisplayBlackItalic.otf
weight: 900
style: italic

Expand Down
47 changes: 47 additions & 0 deletions app/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash

echo "🚀 Starting test suite..."

# Clean and rebuild mocks
echo "🔨 Generating mocks..."
dart run build_runner build --delete-conflicting-outputs

vincentkoc marked this conversation as resolved.
Show resolved Hide resolved
# Function to run tests with proper output formatting
run_test() {
echo "🧪 Running tests for: $1"
flutter test "$1" --coverage
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance test runner function robustness

The function should validate input and handle errors gracefully.

Consider this improved implementation:

 # Function to run tests with proper output formatting
 run_test() {
+    local test_file="$1"
+    if [ ! -f "$test_file" ]; then
+        echo "❌ Test file not found: $test_file"
+        return 1
+    }
+
     echo "🧪 Running tests for: $1"
-    flutter test "$1" --coverage
+    if ! flutter test "$test_file" --coverage; then
+        echo "❌ Tests failed for: $test_file"
+        return 1
+    fi
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Function to run tests with proper output formatting
run_test() {
echo "🧪 Running tests for: $1"
flutter test "$1" --coverage
}
# Function to run tests with proper output formatting
run_test() {
local test_file="$1"
if [ ! -f "$test_file" ]; then
echo "❌ Test file not found: $test_file"
return 1
}
echo "🧪 Running tests for: $1"
if ! flutter test "$test_file" --coverage; then
echo "❌ Tests failed for: $test_file"
return 1
fi
}


# Run all test files
echo "📋 Running all tests..."

# Core tests
run_test "test/app_test.dart"

# Provider tests
run_test "test/providers/auth_provider_test.dart"
run_test "test/providers/capture_provider_test.dart"
run_test "test/providers/memory_provider_test.dart"

# Service tests
run_test "test/services/device_connection_test.dart"
run_test "test/services/notifications_test.dart"

# Schema tests
run_test "test/backend/schema/message_test.dart"

vincentkoc marked this conversation as resolved.
Show resolved Hide resolved
# Combine coverage data
if [ -d "coverage" ]; then
echo "📊 Generating combined coverage report..."
lcov -a coverage/lcov.info -o coverage/lcov_combined.info
genhtml coverage/lcov_combined.info -o coverage/html --no-function-coverage
echo "Coverage report generated in coverage/html"
fi
vincentkoc marked this conversation as resolved.
Show resolved Hide resolved

# Check if any test failed
if [ $? -eq 0 ]; then
echo "✅ All tests completed successfully!"
else
echo "❌ Some tests failed!"
exit 1
fi
vincentkoc marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Test script needs CI/CD integration

The test script (app/test.sh) is currently not integrated into any CI/CD workflow, despite having multiple workflow configurations. While the codemagic.yaml shows Flutter build configurations, it doesn't include the test execution step. To ensure consistent testing across all environments:

  • Add test execution in .github/workflows/main.yml for GitHub Actions
  • Include test step in codemagic.yaml before the build steps
  • Consider adding test coverage reporting to CI artifacts
🔗 Analysis chain

Verify script integration with CI/CD pipeline

The script looks functional but should be verified in the CI/CD context.


Let me gather more information about the CI/CD integration by adjusting the search patterns.


Let me check one more aspect to see if there are any GitHub Actions or similar CI configurations that might be using this test script.


Let me check the content of the workflow files specifically for Flutter/Dart testing configurations.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for related CI configuration files and Makefile integration

echo "Checking for CI configuration files..."
fd -t f "^\.github/workflows/.*\.ya?ml$"

echo "Checking for Makefile integration..."
if [ -f "Makefile" ]; then
    rg -A 5 "test\.sh" Makefile
fi

Length of output: 442


Script:

#!/bin/bash
# Check for CI configurations with adjusted patterns and include hidden files
echo "Checking for CI/CD configurations..."
fd -H -t f "workflow" .github/
fd -H -t f "ci" .

# Check for any test-related configurations
echo -e "\nChecking for test configurations..."
rg -l "flutter test|dart test" .

Length of output: 700


Script:

#!/bin/bash
# Look for any yaml configurations and their content
echo "Checking for CI yaml configurations..."
fd -H -e yml -e yaml .

# If any yaml files exist, check their content for test-related commands
echo -e "\nChecking yaml contents for test integration..."
rg -l "test\.sh|flutter test|dart test" -g "*.{yml,yaml}" .

Length of output: 904


Script:

#!/bin/bash
# Check content of workflow files for Flutter/testing related configurations
echo "Checking workflow files content..."
for file in .github/workflows/*.yml; do
    echo "=== $file ==="
    cat "$file" | grep -A 5 -i "flutter\|test\|dart"
done

# Also check codemagic.yaml as it's commonly used for Flutter CI/CD
echo -e "\n=== codemagic.yaml ==="
cat codemagic.yaml | grep -A 5 -i "flutter\|test\|dart"

Length of output: 17751

Loading