From 4bb5afecb6ae4b04289238730db9e96c14571684 Mon Sep 17 00:00:00 2001 From: DenserMeerkat Date: Sun, 25 Aug 2024 21:04:45 +0530 Subject: [PATCH 1/2] test: common runner file --- .../desktop/env_manager_test.dart | 6 ++- .../desktop/his_request_test.dart | 6 ++- integration_test/desktop/req_editor_test.dart | 6 ++- integration_test/mobile/env_manager_test.dart | 54 ++++++++++++++----- integration_test/mobile/his_request_test.dart | 6 ++- integration_test/mobile/req_editor_test.dart | 6 ++- integration_test/runner.dart | 22 ++++++++ 7 files changed, 87 insertions(+), 19 deletions(-) create mode 100644 integration_test/runner.dart diff --git a/integration_test/desktop/env_manager_test.dart b/integration_test/desktop/env_manager_test.dart index b68d168c..cdd748a2 100644 --- a/integration_test/desktop/env_manager_test.dart +++ b/integration_test/desktop/env_manager_test.dart @@ -11,7 +11,11 @@ import 'package:apidash/screens/home_page/editor_pane/url_card.dart'; import '../../test/extensions/widget_tester_extensions.dart'; import '../test_helper.dart'; -void main() async { +Future main() async { + await runDesktopEnvIntegrationTest(); +} + +Future runDesktopEnvIntegrationTest() async { const environmentName = "test-env-name"; const envVarName = "test-env-var"; const envVarValue = "8700000"; diff --git a/integration_test/desktop/his_request_test.dart b/integration_test/desktop/his_request_test.dart index 41e739ea..b47fe6e7 100644 --- a/integration_test/desktop/his_request_test.dart +++ b/integration_test/desktop/his_request_test.dart @@ -8,7 +8,11 @@ import 'package:apidash/widgets/widgets.dart'; import '../../test/extensions/widget_tester_extensions.dart'; import '../test_helper.dart'; -void main() async { +Future main() async { + await runDesktopHisIntegrationTest(); +} + +Future runDesktopHisIntegrationTest() async { await ApidashTestHelper.initialize( size: Size(kExpandedWindowWidth, kMinWindowSize.height)); apidashWidgetTest("Testing History of Requests in desktop end-to-end", diff --git a/integration_test/desktop/req_editor_test.dart b/integration_test/desktop/req_editor_test.dart index 146732da..abdb24cf 100644 --- a/integration_test/desktop/req_editor_test.dart +++ b/integration_test/desktop/req_editor_test.dart @@ -7,7 +7,11 @@ import 'package:apidash/widgets/widgets.dart'; import '../../test/extensions/widget_tester_extensions.dart'; import '../test_helper.dart'; -void main() async { +Future main() async { + await runDesktopReqIntegrationTest(); +} + +Future runDesktopReqIntegrationTest() async { const reqName = "test-req-name"; const testEndpoint = "https://api.apidash.dev/humanize/social"; const paramKey = "num"; diff --git a/integration_test/mobile/env_manager_test.dart b/integration_test/mobile/env_manager_test.dart index 12d99d4b..d6544331 100644 --- a/integration_test/mobile/env_manager_test.dart +++ b/integration_test/mobile/env_manager_test.dart @@ -11,7 +11,11 @@ import 'package:apidash/screens/home_page/editor_pane/url_card.dart'; import '../../test/extensions/widget_tester_extensions.dart'; import '../test_helper.dart'; -void main() async { +Future main() async { + await runMobileEnvIntegrationTest(); +} + +Future runMobileEnvIntegrationTest() async { const environmentName = "test-env-name"; const envVarName = "test-env-var"; const envVarValue = "8700000"; @@ -73,13 +77,26 @@ void main() async { addTearDown(gesture.removePointer); await tester.pump(); - /// Check if environment variable is shown on hover - await gesture.moveTo(tester.getCenter(find.descendant( - of: find.byType(URLTextField), - matching: find.text('{{$envVarName}}')))); - await tester.pumpAndSettle(); - expect(find.text(envVarValue), findsOneWidget); - await gesture.moveBy(const Offset(0, 100)); + /// Check if environment variable is shown + if (kIsMobile) { + // TODO: Unable to get Popover to show on mobile + // await tester.tapAt(tester.getCenter(find.descendant( + // of: find.byType(URLTextField), + // matching: find.text('{{$envVarName}}')))); + // await tester.pumpAndSettle(); + // expect(find.text(envVarValue), findsOneWidget); + // await tester.tapAt(tester.getCenter(find.descendant( + // of: find.byType(URLTextField), + // matching: find.byType(WidgetSpan))) + + // const Offset(0, 100)); + } else { + await gesture.moveTo(tester.getCenter(find.descendant( + of: find.byType(URLTextField), + matching: find.text('{{$envVarName}}')))); + await tester.pumpAndSettle(); + expect(find.text(envVarValue), findsOneWidget); + await gesture.moveBy(const Offset(0, 100)); + } await Future.delayed(const Duration(milliseconds: 500)); await helper.navigateToSettings(scaffoldKey: kHomeScaffoldKey); @@ -111,12 +128,21 @@ void main() async { await helper.navigateToRequestEditor(scaffoldKey: kEnvScaffoldKey); await Future.delayed(const Duration(milliseconds: 200)); - /// Check if environment variable is now shown on hover - await gesture.moveTo(tester.getCenter(find.descendant( - of: find.byType(URLTextField), - matching: find.text('{{$envVarName}}')))); - await tester.pumpAndSettle(); - expect(find.text(unknown), findsNWidgets(2)); + /// Check if environment variable is now shown as unknown + if (kIsMobile) { + // TODO: Unable to get Popover to show on mobile + // await tester.tapAt(tester.getCenter(find.descendant( + // of: find.byType(URLTextField), + // matching: find.text('{{$envVarName}}')))); + // await tester.pumpAndSettle(); + // expect(find.text(unknown), findsNWidgets(2)); + } else { + await gesture.moveTo(tester.getCenter(find.descendant( + of: find.byType(URLTextField), + matching: find.text('{{$envVarName}}')))); + await tester.pumpAndSettle(); + expect(find.text(unknown), findsNWidgets(2)); + } await Future.delayed(const Duration(milliseconds: 500)); }); diff --git a/integration_test/mobile/his_request_test.dart b/integration_test/mobile/his_request_test.dart index 7de01ec9..c2544bc0 100644 --- a/integration_test/mobile/his_request_test.dart +++ b/integration_test/mobile/his_request_test.dart @@ -8,7 +8,11 @@ import 'package:apidash/screens/history/history_widgets/history_widgets.dart'; import '../../test/extensions/widget_tester_extensions.dart'; import '../test_helper.dart'; -void main() async { +Future main() async { + await runMobileHisIntegrationTest(); +} + +Future runMobileHisIntegrationTest() async { await ApidashTestHelper.initialize( size: Size(kCompactWindowWidth, kMinWindowSize.height)); apidashWidgetTest("Testing History of Requests in mobile end-to-end", diff --git a/integration_test/mobile/req_editor_test.dart b/integration_test/mobile/req_editor_test.dart index 032c1818..a407db3e 100644 --- a/integration_test/mobile/req_editor_test.dart +++ b/integration_test/mobile/req_editor_test.dart @@ -7,7 +7,11 @@ import 'package:apidash/widgets/widgets.dart'; import '../../test/extensions/widget_tester_extensions.dart'; import '../test_helper.dart'; -void main() async { +Future main() async { + await runMobileReqIntegrationTest(); +} + +Future runMobileReqIntegrationTest() async { const reqName = "test-req-name"; const testEndpoint = "https://api.apidash.dev/humanize/social"; const paramKey = "num"; diff --git a/integration_test/runner.dart b/integration_test/runner.dart new file mode 100644 index 00000000..a2b88c0d --- /dev/null +++ b/integration_test/runner.dart @@ -0,0 +1,22 @@ +import 'dart:io'; + +import 'desktop/env_manager_test.dart'; +import 'desktop/his_request_test.dart'; +import 'desktop/req_editor_test.dart'; +import 'mobile/env_manager_test.dart'; +import 'mobile/his_request_test.dart'; +import 'mobile/req_editor_test.dart'; + +Future main() async { + if (Platform.isLinux || Platform.isWindows || Platform.isMacOS) { + await runDesktopReqIntegrationTest(); + await runDesktopEnvIntegrationTest(); + await runDesktopHisIntegrationTest(); + } else if (Platform.isAndroid || Platform.isIOS) { + await runMobileReqIntegrationTest(); + await runMobileEnvIntegrationTest(); + await runMobileHisIntegrationTest(); + } else { + throw Exception("Unsupported Platform"); + } +} From 55ad184a494ac0cf8edac985d99336b575212eec Mon Sep 17 00:00:00 2001 From: Ashita Prasad Date: Sun, 25 Aug 2024 23:05:44 +0530 Subject: [PATCH 2/2] Update for running for responsive widths in desktop --- integration_test/desktop/env_manager_test.dart | 5 ++--- integration_test/desktop/his_request_test.dart | 8 ++------ integration_test/desktop/req_editor_test.dart | 6 ++---- integration_test/mobile/env_manager_test.dart | 5 ++--- integration_test/mobile/his_request_test.dart | 6 ++---- integration_test/mobile/req_editor_test.dart | 5 ++--- integration_test/runner.dart | 10 ++++++---- integration_test/test_helper.dart | 3 +++ 8 files changed, 21 insertions(+), 27 deletions(-) diff --git a/integration_test/desktop/env_manager_test.dart b/integration_test/desktop/env_manager_test.dart index cdd748a2..8b35fe4b 100644 --- a/integration_test/desktop/env_manager_test.dart +++ b/integration_test/desktop/env_manager_test.dart @@ -23,9 +23,8 @@ Future runDesktopEnvIntegrationTest() async { const unknown = "unknown"; const expectedCurlCode = "curl --url '$testEndpoint$envVarValue'"; - await ApidashTestHelper.initialize( - size: Size(kExpandedWindowWidth, kMinWindowSize.height)); - apidashWidgetTest("Testing Environment Manager in desktop end-to-end", + apidashWidgetTest( + "Testing Environment Manager in desktop end-to-end", kExpandedWindowWidth, (WidgetTester tester, helper) async { await tester.pumpUntilFound(find.byType(DashApp)); await Future.delayed(const Duration(seconds: 1)); diff --git a/integration_test/desktop/his_request_test.dart b/integration_test/desktop/his_request_test.dart index b47fe6e7..b643d7e6 100644 --- a/integration_test/desktop/his_request_test.dart +++ b/integration_test/desktop/his_request_test.dart @@ -1,6 +1,3 @@ -import 'dart:ui'; - -import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:apidash/app.dart'; import 'package:apidash/consts.dart'; @@ -13,9 +10,8 @@ Future main() async { } Future runDesktopHisIntegrationTest() async { - await ApidashTestHelper.initialize( - size: Size(kExpandedWindowWidth, kMinWindowSize.height)); - apidashWidgetTest("Testing History of Requests in desktop end-to-end", + apidashWidgetTest( + "Testing History of Requests in desktop end-to-end", kExpandedWindowWidth, (WidgetTester tester, helper) async { await tester.pumpUntilFound(find.byType(DashApp)); await Future.delayed(const Duration(seconds: 1)); diff --git a/integration_test/desktop/req_editor_test.dart b/integration_test/desktop/req_editor_test.dart index abdb24cf..a3f81ddd 100644 --- a/integration_test/desktop/req_editor_test.dart +++ b/integration_test/desktop/req_editor_test.dart @@ -1,4 +1,3 @@ -import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:spot/spot.dart'; import 'package:apidash/app.dart'; @@ -23,9 +22,8 @@ Future runDesktopReqIntegrationTest() async { "data": "870K" }'''; - await ApidashTestHelper.initialize( - size: Size(kExpandedWindowWidth, kMinWindowSize.height)); - apidashWidgetTest("Testing Request Editor in desktop end-to-end", + apidashWidgetTest( + "Testing Request Editor in desktop end-to-end", kExpandedWindowWidth, (WidgetTester tester, helper) async { await tester.pumpUntilFound(find.byType(DashApp)); await Future.delayed(const Duration(seconds: 1)); diff --git a/integration_test/mobile/env_manager_test.dart b/integration_test/mobile/env_manager_test.dart index d6544331..0fd810fd 100644 --- a/integration_test/mobile/env_manager_test.dart +++ b/integration_test/mobile/env_manager_test.dart @@ -24,9 +24,8 @@ Future runMobileEnvIntegrationTest() async { const unknown = "unknown"; const expectedCurlCode = "curl --url '$testEndpoint$envVarValue'"; - await ApidashTestHelper.initialize( - size: Size(kCompactWindowWidth, kMinWindowSize.height)); - apidashWidgetTest("Testing Environment Manager in mobile end-to-end", + apidashWidgetTest( + "Testing Environment Manager in mobile end-to-end", kCompactWindowWidth, (WidgetTester tester, helper) async { await tester.pumpUntilFound(find.byType(DashApp)); await Future.delayed(const Duration(seconds: 1)); diff --git a/integration_test/mobile/his_request_test.dart b/integration_test/mobile/his_request_test.dart index c2544bc0..995284e0 100644 --- a/integration_test/mobile/his_request_test.dart +++ b/integration_test/mobile/his_request_test.dart @@ -13,9 +13,8 @@ Future main() async { } Future runMobileHisIntegrationTest() async { - await ApidashTestHelper.initialize( - size: Size(kCompactWindowWidth, kMinWindowSize.height)); - apidashWidgetTest("Testing History of Requests in mobile end-to-end", + apidashWidgetTest( + "Testing History of Requests in mobile end-to-end", kCompactWindowWidth, (WidgetTester tester, helper) async { await tester.pumpUntilFound(find.byType(DashApp)); await Future.delayed(const Duration(seconds: 1)); @@ -29,7 +28,6 @@ Future runMobileHisIntegrationTest() async { ); await Future.delayed(const Duration(milliseconds: 200)); await helper.reqHelper.sendRequest(); - await helper.reqHelper.sendRequest(); /// Navigate to History await helper.navigateToHistory(scaffoldKey: kHomeScaffoldKey); diff --git a/integration_test/mobile/req_editor_test.dart b/integration_test/mobile/req_editor_test.dart index a407db3e..738d2fc4 100644 --- a/integration_test/mobile/req_editor_test.dart +++ b/integration_test/mobile/req_editor_test.dart @@ -23,9 +23,8 @@ Future runMobileReqIntegrationTest() async { "data": "870K" }'''; - await ApidashTestHelper.initialize( - size: Size(kCompactWindowWidth, kMinWindowSize.height)); - apidashWidgetTest("Testing Request Editor in mobile end-to-end", + apidashWidgetTest( + "Testing Request Editor in mobile end-to-end", kCompactWindowWidth, (WidgetTester tester, helper) async { await tester.pumpUntilFound(find.byType(DashApp)); await Future.delayed(const Duration(seconds: 1)); diff --git a/integration_test/runner.dart b/integration_test/runner.dart index a2b88c0d..abd43956 100644 --- a/integration_test/runner.dart +++ b/integration_test/runner.dart @@ -1,5 +1,4 @@ -import 'dart:io'; - +import 'package:apidash/consts.dart'; import 'desktop/env_manager_test.dart'; import 'desktop/his_request_test.dart'; import 'desktop/req_editor_test.dart'; @@ -8,11 +7,14 @@ import 'mobile/his_request_test.dart'; import 'mobile/req_editor_test.dart'; Future main() async { - if (Platform.isLinux || Platform.isWindows || Platform.isMacOS) { + if (kIsMobile) { + await runMobileReqIntegrationTest(); + await runMobileEnvIntegrationTest(); + await runMobileHisIntegrationTest(); + } else if (kIsMobile || kIsDesktop) { await runDesktopReqIntegrationTest(); await runDesktopEnvIntegrationTest(); await runDesktopHisIntegrationTest(); - } else if (Platform.isAndroid || Platform.isIOS) { await runMobileReqIntegrationTest(); await runMobileEnvIntegrationTest(); await runMobileHisIntegrationTest(); diff --git a/integration_test/test_helper.dart b/integration_test/test_helper.dart index a1ce860d..70cafa9d 100644 --- a/integration_test/test_helper.dart +++ b/integration_test/test_helper.dart @@ -113,11 +113,14 @@ class ApidashTestHelper { @isTest void apidashWidgetTest( String description, + double? width, Future Function(WidgetTester, ApidashTestHelper) test, ) { testWidgets( description, (widgetTester) async { + await ApidashTestHelper.initialize( + size: width != null ? Size(width, kMinWindowSize.height) : null); await ApidashTestHelper.loadApp(widgetTester); await test(widgetTester, ApidashTestHelper(widgetTester)); },