diff --git a/integration_test/desktop/req_editor_test.dart b/integration_test/desktop/req_editor_test.dart new file mode 100644 index 00000000..146732da --- /dev/null +++ b/integration_test/desktop/req_editor_test.dart @@ -0,0 +1,58 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:spot/spot.dart'; +import 'package:apidash/app.dart'; +import 'package:apidash/consts.dart'; +import 'package:apidash/widgets/widgets.dart'; +import '../../test/extensions/widget_tester_extensions.dart'; +import '../test_helper.dart'; + +void main() async { + const reqName = "test-req-name"; + const testEndpoint = "https://api.apidash.dev/humanize/social"; + const paramKey = "num"; + const paramValue = "870000"; + const headerKey = "Content-Type"; + const headerValue = "application/json"; + const expectedCurlCode = "curl --url '$testEndpoint?$paramKey=$paramValue'"; + const expectedRawCode = '''{ + "data": "870K" +}'''; + + await ApidashTestHelper.initialize( + size: Size(kExpandedWindowWidth, kMinWindowSize.height)); + apidashWidgetTest("Testing Request Editor in desktop end-to-end", + (WidgetTester tester, helper) async { + await tester.pumpUntilFound(find.byType(DashApp)); + await Future.delayed(const Duration(seconds: 1)); + + /// Create New Request + await helper.reqHelper.addRequest(testEndpoint, + name: reqName, + params: [(paramKey, paramValue)], + headers: [(headerKey, headerValue)]); + await Future.delayed(const Duration(milliseconds: 200)); + await helper.reqHelper.sendRequest(); + + /// Check if response is received + await act.tap(spotText(ResponseBodyView.raw.label)); + await tester.pumpAndSettle(); + spotText(expectedRawCode).existsOnce(); + + /// Check Response Headers + await act.tap(spot().spotText(kLabelHeaders)); + await tester.pumpAndSettle(); + spotText("$kLabelRequestHeaders (1 $kLabelItems)").existsOnce(); + + /// Change codegen language to curl + await helper.navigateToSettings(); + await helper.changeCodegenLanguage(CodegenLanguage.curl); + await helper.navigateToRequestEditor(); + + /// Check generated code + await helper.reqHelper.unCheckFirstHeader(); + await act.tap(spot().spotText(kLabelViewCode)); + await tester.pumpAndSettle(); + spot().spotText(expectedCurlCode).existsOnce(); + }); +} diff --git a/integration_test/mobile/req_editor_test.dart b/integration_test/mobile/req_editor_test.dart new file mode 100644 index 00000000..032c1818 --- /dev/null +++ b/integration_test/mobile/req_editor_test.dart @@ -0,0 +1,67 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:spot/spot.dart'; +import 'package:apidash/app.dart'; +import 'package:apidash/consts.dart'; +import 'package:apidash/widgets/widgets.dart'; +import '../../test/extensions/widget_tester_extensions.dart'; +import '../test_helper.dart'; + +void main() async { + const reqName = "test-req-name"; + const testEndpoint = "https://api.apidash.dev/humanize/social"; + const paramKey = "num"; + const paramValue = "870000"; + const headerKey = "Content-Type"; + const headerValue = "application/json"; + const expectedCurlCode = "curl --url '$testEndpoint?$paramKey=$paramValue'"; + const expectedRawCode = '''{ + "data": "870K" +}'''; + + await ApidashTestHelper.initialize( + size: Size(kCompactWindowWidth, kMinWindowSize.height)); + apidashWidgetTest("Testing Request Editor in mobile end-to-end", + (WidgetTester tester, helper) async { + await tester.pumpUntilFound(find.byType(DashApp)); + await Future.delayed(const Duration(seconds: 1)); + + /// Create New Request + await helper.reqHelper.addRequest(testEndpoint, + name: reqName, + params: [(paramKey, paramValue)], + headers: [(headerKey, headerValue)], + isMobile: true); + await Future.delayed(const Duration(milliseconds: 200)); + await helper.reqHelper.sendRequest(); + + /// Check if response is received + await act.tap(spot().spotText(kLabelResponse)); + await tester.pumpAndSettle(); + await act.tap(spotText(ResponseBodyView.raw.label)); + await tester.pumpAndSettle(); + spotText(expectedRawCode).existsOnce(); + + /// Check Response Headers + await act.tap(spot().spotText(kLabelHeaders)); + await tester.pumpAndSettle(); + spotText("$kLabelRequestHeaders (1 $kLabelItems)").existsOnce(); + + /// Change codegen language to curl + await helper.navigateToSettings(scaffoldKey: kHomeScaffoldKey); + await helper.changeCodegenLanguage(CodegenLanguage.curl); + await helper.navigateToRequestEditor(); + + /// Uncheck first header + await act.tap(spot().spotText(kLabelRequest)); + await tester.pumpAndSettle(); + await act.tap(spot().spot().spotText(kLabelHeaders)); + await tester.pumpAndSettle(); + await helper.reqHelper.unCheckFirstHeader(); + + /// Check generated code + await act.tap(spot().spotText(kLabelCode)); + await tester.pumpAndSettle(); + spot().spotText(expectedCurlCode).existsOnce(); + }); +} diff --git a/integration_test/req_helper.dart b/integration_test/req_helper.dart index ecc9c403..4d2fd68c 100644 --- a/integration_test/req_helper.dart +++ b/integration_test/req_helper.dart @@ -100,6 +100,13 @@ class ApidashTestRequestHelper { } } + Future unCheckFirstHeader() async { + final headerCells = find.descendant( + of: find.byType(EditRequestHeaders), matching: find.byType(CheckBox)); + await tester.tap(headerCells.at(0)); + await tester.pumpAndSettle(); + } + Future addRequest( String url, { String? name,