From e45abb36c21abbcfd2982a9d79de592c5ced3c2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=AD=E6=B5=81=E8=8A=B3?= <97436317+Rocke1001feller@users.noreply.github.com> Date: Mon, 24 Mar 2025 12:48:13 +0800 Subject: [PATCH 1/6] fix(test): value key --- compass_app/app/integration_test/app_server_data_test.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compass_app/app/integration_test/app_server_data_test.dart b/compass_app/app/integration_test/app_server_data_test.dart index cb4bb28b7ef..89b17d0b553 100644 --- a/compass_app/app/integration_test/app_server_data_test.dart +++ b/compass_app/app/integration_test/app_server_data_test.dart @@ -147,7 +147,7 @@ void main() { // Select guests await tester.tap( - find.byKey(const ValueKey('add_guests')), + find.byKey(const ValueKey('add-guests')), warnIfMissed: false, ); @@ -155,7 +155,7 @@ void main() { await tester.pumpAndSettle(); // Perform search and navigate to next screen - await tester.tap(find.byKey(const ValueKey('submit_button'))); + await tester.tap(find.byKey(const ValueKey('submit-button'))); await tester.pumpAndSettle(); // Results Screen From cd57eb2814ee6e4eda66346e5b28a3571befe0e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=AD=E6=B5=81=E8=8A=B3?= <97436317+Rocke1001feller@users.noreply.github.com> Date: Mon, 24 Mar 2025 12:53:47 +0800 Subject: [PATCH 2/6] fix(test): add local server test setup --- .../test_app_server_data.dart | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 compass_app/app/integration_test/test_app_server_data.dart diff --git a/compass_app/app/integration_test/test_app_server_data.dart b/compass_app/app/integration_test/test_app_server_data.dart new file mode 100644 index 00000000000..b4694a783ca --- /dev/null +++ b/compass_app/app/integration_test/test_app_server_data.dart @@ -0,0 +1,30 @@ +import 'dart:io'; + +void main() async { + const port = '8080'; + late Process p; + + // Start the dart server + p = await Process.start( + 'dart', + ['run', 'bin/compass_server.dart'], + environment: {'PORT': port}, + // Relative to the app/ folder + workingDirectory: '../server', + ); + // Wait for server to start and print to stdout. + await p.stdout.first; + + final testProcess = await Process.start('flutter', [ + 'test', + 'integration_test/app_server_data_test.dart', + ], workingDirectory: '../app'); + + await testProcess.stdout.pipe(stdout); + await testProcess.stderr.pipe(stderr); + + await testProcess.exitCode; + + // tearDownAll(() => p.kill()); + p.kill(); +} From 2dd30840bda587a315f97642c3de6737a1e99600 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=AD=E6=B5=81=E8=8A=B3?= <97436317+Rocke1001feller@users.noreply.github.com> Date: Mon, 24 Mar 2025 12:55:32 +0800 Subject: [PATCH 3/6] fix(test): remove local server api setup in test file --- .../integration_test/app_server_data_test.dart | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/compass_app/app/integration_test/app_server_data_test.dart b/compass_app/app/integration_test/app_server_data_test.dart index 89b17d0b553..f6285aaa27b 100644 --- a/compass_app/app/integration_test/app_server_data_test.dart +++ b/compass_app/app/integration_test/app_server_data_test.dart @@ -25,28 +25,13 @@ void main() { IntegrationTestWidgetsFlutterBinding.ensureInitialized(); group('end-to-end test with remote data', () { - const port = '8080'; - late Process p; setUpAll(() async { // Clear any stored shared preferences final sharedPreferences = await SharedPreferences.getInstance(); await sharedPreferences.clear(); - - // Start the dart server - p = await Process.start( - 'dart', - ['run', 'bin/compass_server.dart'], - environment: {'PORT': port}, - // Relative to the app/ folder - workingDirectory: '../server', - ); - // Wait for server to start and print to stdout. - await p.stdout.first; }); - tearDownAll(() => p.kill()); - testWidgets('should load app', (tester) async { // Load app widget. await tester.pumpWidget( From f6db91ff72c8c7d095f7366cf25ac76f90ac626c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=AD=E6=B5=81=E8=8A=B3?= <97436317+Rocke1001feller@users.noreply.github.com> Date: Mon, 24 Mar 2025 12:56:54 +0800 Subject: [PATCH 4/6] fix(README): path --- compass_app/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compass_app/README.md b/compass_app/README.md index 05ed7670aa4..eb44bebd852 100644 --- a/compass_app/README.md +++ b/compass_app/README.md @@ -32,7 +32,7 @@ $ cd server $ dart run # => Server listening on port 8080 -$ cd ../compass_app/app +$ cd ../app $ flutter run --target lib/main_staging.dart ``` From 61bcd95e8d724fa552830886e72210148ef181c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=AD=E6=B5=81=E8=8A=B3?= <97436317+Rocke1001feller@users.noreply.github.com> Date: Mon, 24 Mar 2025 13:08:00 +0800 Subject: [PATCH 5/6] fix(localhost): every device have localhost --- compass_app/app/lib/config/dependencies.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compass_app/app/lib/config/dependencies.dart b/compass_app/app/lib/config/dependencies.dart index 3b2bd541af7..aa17951f83c 100644 --- a/compass_app/app/lib/config/dependencies.dart +++ b/compass_app/app/lib/config/dependencies.dart @@ -1,7 +1,7 @@ // Copyright 2024 The Flutter team. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. - +import 'dart:io'; import 'package:provider/provider.dart'; import 'package:provider/single_child_widget.dart'; @@ -53,8 +53,8 @@ List _sharedProviders = [ /// This dependency list uses repositories that connect to a remote server. List get providersRemote { return [ - Provider(create: (context) => AuthApiClient()), - Provider(create: (context) => ApiClient()), + Provider(create: (context) => AuthApiClient(host: Platform.environment['LOCALHOST'])), + Provider(create: (context) => ApiClient(host: Platform.environment['LOCALHOST'])), Provider(create: (context) => SharedPreferencesService()), ChangeNotifierProvider( create: From e836790664fb697d8c5abb21a1d927dd38ecb7b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=AD=E6=B5=81=E8=8A=B3?= <97436317+Rocke1001feller@users.noreply.github.com> Date: Mon, 24 Mar 2025 13:43:27 +0800 Subject: [PATCH 6/6] fix(README): update run command --- compass_app/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compass_app/README.md b/compass_app/README.md index eb44bebd852..4401179a37f 100644 --- a/compass_app/README.md +++ b/compass_app/README.md @@ -48,10 +48,10 @@ $ flutter test integration_test/app_local_data_test.dart ``` **Integration tests with background server and remote data** - +> Simulators have their own `localhost`, separate from the desktop's. Therefore, tests on a simulator that try to connect to a local background server using `localhost` will fail to reach. To resolve this, find a non-loopback IPv4 address (e.g., using `ifconfig | grep inet` and choosing an address other than `127.0.0.1`, such as `192.168.0.106`). ```bash cd app -$ flutter test integration_test/app_server_data_test.dart +$ LOCALHOST='your_non-loopback_ipv4_address' dart run integration_test/test_app_server_data.dart ``` Running the tests together with `flutter test integration_test` will fail.