mirror of
https://github.com/foss42/apidash.git
synced 2025-06-06 19:38:58 +08:00
refactor: abstract to helper
This commit is contained in:
@ -6,12 +6,9 @@ import 'package:spot/spot.dart';
|
|||||||
import 'package:apidash/app.dart';
|
import 'package:apidash/app.dart';
|
||||||
import 'package:apidash/consts.dart';
|
import 'package:apidash/consts.dart';
|
||||||
import 'package:apidash/widgets/widgets.dart';
|
import 'package:apidash/widgets/widgets.dart';
|
||||||
import 'package:apidash/screens/screens.dart';
|
|
||||||
import 'package:apidash/screens/common_widgets/env_trigger_options.dart';
|
import 'package:apidash/screens/common_widgets/env_trigger_options.dart';
|
||||||
import 'package:apidash/screens/envvar/editor_pane/variables_pane.dart';
|
|
||||||
import 'package:apidash/screens/home_page/editor_pane/editor_request.dart';
|
import 'package:apidash/screens/home_page/editor_pane/editor_request.dart';
|
||||||
import 'package:apidash/screens/home_page/editor_pane/url_card.dart';
|
import 'package:apidash/screens/home_page/editor_pane/url_card.dart';
|
||||||
import 'package:apidash/screens/envvar/environments_pane.dart';
|
|
||||||
import '../../test/extensions/widget_tester_extensions.dart';
|
import '../../test/extensions/widget_tester_extensions.dart';
|
||||||
import '../test_helper.dart';
|
import '../test_helper.dart';
|
||||||
|
|
||||||
@ -19,11 +16,9 @@ void main() async {
|
|||||||
const environmentName = "test-env-name";
|
const environmentName = "test-env-name";
|
||||||
const envVarName = "test-env-var";
|
const envVarName = "test-env-var";
|
||||||
const envVarValue = "8700000";
|
const envVarValue = "8700000";
|
||||||
const testEndpoint = "api.apidash.dev/humanize/social?num=";
|
const testEndpoint = "https://api.apidash.dev/humanize/social?num=";
|
||||||
const unknown = "unknown";
|
const unknown = "unknown";
|
||||||
const untitled = "untitled";
|
const expectedCurlCode = "curl --url '$testEndpoint$envVarValue'";
|
||||||
const expectedCurlCode =
|
|
||||||
"curl --url 'https://api.apidash.dev/humanize/social?num=8700000'";
|
|
||||||
|
|
||||||
await ApidashTestHelper.initialize(
|
await ApidashTestHelper.initialize(
|
||||||
size: Size(kExpandedWindowWidth, kMinWindowSize.height));
|
size: Size(kExpandedWindowWidth, kMinWindowSize.height));
|
||||||
@ -33,60 +28,30 @@ void main() async {
|
|||||||
await Future.delayed(const Duration(seconds: 1));
|
await Future.delayed(const Duration(seconds: 1));
|
||||||
|
|
||||||
/// Navigate to Environment Manager
|
/// Navigate to Environment Manager
|
||||||
await navigateByIcon(tester, Icons.laptop_windows_outlined);
|
await helper.navigateToEnvironmentManager();
|
||||||
await Future.delayed(const Duration(milliseconds: 500));
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
|
|
||||||
/// Create New Environment
|
/// Create New Environment
|
||||||
final newEnvButton =
|
await helper.envHelper.addNewEnvironment();
|
||||||
spot<EnvironmentsPane>().spot<ElevatedButton>().spotText(kLabelPlusNew);
|
|
||||||
newEnvButton.existsOnce();
|
|
||||||
await act.tap(newEnvButton);
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
await Future.delayed(const Duration(milliseconds: 500));
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
|
|
||||||
/// Open ItemCardMenu of the new environment
|
|
||||||
Finder envItems = find.byType(EnvironmentItem);
|
|
||||||
Finder newEnvItem = envItems.at(1);
|
|
||||||
expect(find.descendant(of: newEnvItem, matching: find.text(untitled)),
|
|
||||||
findsOneWidget);
|
|
||||||
Finder itemCardMenu =
|
|
||||||
find.descendant(of: newEnvItem, matching: find.byType(ItemCardMenu));
|
|
||||||
await tester.tap(itemCardMenu);
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
|
|
||||||
/// Rename the new environment
|
/// Rename the new environment
|
||||||
await tester.tap(find.text(ItemMenuOption.edit.label).last);
|
await helper.envHelper.renameNewEnvironment(environmentName);
|
||||||
await tester.pump();
|
|
||||||
await tester.enterText(newEnvItem, environmentName);
|
|
||||||
await tester.testTextInput.receiveAction(TextInputAction.done);
|
|
||||||
await tester.pump();
|
|
||||||
await Future.delayed(const Duration(milliseconds: 500));
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
|
|
||||||
/// Edit Environment Variables
|
/// Add Environment Variables
|
||||||
final envCells = find.descendant(
|
await helper.envHelper.addEnvironmentVariables([(envVarName, envVarValue)]);
|
||||||
of: find.byType(EditEnvironmentVariables),
|
|
||||||
matching: find.byType(CellField));
|
|
||||||
await tester.enterText(envCells.at(0), envVarName);
|
|
||||||
await tester.enterText(envCells.at(1), envVarValue);
|
|
||||||
await Future.delayed(const Duration(milliseconds: 500));
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
|
|
||||||
/// Navigate to Request Editor
|
/// Navigate to Request Editor
|
||||||
await navigateByIcon(tester, Icons.auto_awesome_mosaic_outlined);
|
await helper.navigateToRequestEditor();
|
||||||
await Future.delayed(const Duration(milliseconds: 200));
|
await Future.delayed(const Duration(milliseconds: 200));
|
||||||
|
|
||||||
/// Create a new request
|
/// Create a new request
|
||||||
await act.tap(
|
await helper.reqHelper.addNewRequest();
|
||||||
spot<CollectionPane>().spot<ElevatedButton>().spotText(kLabelPlusNew));
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
|
|
||||||
/// Set active environment
|
/// Set active environment
|
||||||
await tester.tap(find.descendant(
|
await helper.envHelper.setActiveEnvironment(environmentName);
|
||||||
of: find.byType(EnvironmentPopupMenu),
|
|
||||||
matching: find.byIcon(Icons.unfold_more)));
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
|
|
||||||
await tester.tap(find.text(environmentName).last);
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
|
|
||||||
/// Check if environment suggestions are working
|
/// Check if environment suggestions are working
|
||||||
await act.tap(spot<RequestEditor>().spot<URLTextField>());
|
await act.tap(spot<RequestEditor>().spot<URLTextField>());
|
||||||
@ -111,16 +76,12 @@ void main() async {
|
|||||||
expect(find.text(envVarValue), findsOneWidget);
|
expect(find.text(envVarValue), findsOneWidget);
|
||||||
await Future.delayed(const Duration(milliseconds: 500));
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
|
|
||||||
/// Change codegen language to curl
|
await helper.navigateToSettings();
|
||||||
await navigateByIcon(tester, Icons.settings_outlined);
|
|
||||||
await tester.tap(find.descendant(
|
|
||||||
of: find.byType(CodegenPopupMenu),
|
|
||||||
matching: find.byIcon(Icons.unfold_more)));
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
|
|
||||||
await tester.tap(find.text(CodegenLanguage.curl.label).last);
|
/// Change codegen language to curl
|
||||||
await tester.pumpAndSettle();
|
await helper.changeCodegenLanguage(CodegenLanguage.curl);
|
||||||
await navigateByIcon(tester, Icons.auto_awesome_mosaic_outlined);
|
|
||||||
|
await helper.navigateToRequestEditor();
|
||||||
await Future.delayed(const Duration(milliseconds: 200));
|
await Future.delayed(const Duration(milliseconds: 200));
|
||||||
|
|
||||||
/// Check variable substitution in request
|
/// Check variable substitution in request
|
||||||
@ -133,18 +94,15 @@ void main() async {
|
|||||||
findsOneWidget);
|
findsOneWidget);
|
||||||
|
|
||||||
/// Navigate to Environment Manager
|
/// Navigate to Environment Manager
|
||||||
await navigateByIcon(tester, Icons.laptop_windows_outlined);
|
await helper.navigateToEnvironmentManager();
|
||||||
await Future.delayed(const Duration(milliseconds: 200));
|
await Future.delayed(const Duration(milliseconds: 200));
|
||||||
|
|
||||||
/// Delete the environment variable
|
/// Delete the environment variable
|
||||||
final delButtons = find.descendant(
|
await helper.envHelper.deleteFirstEnvironmentVariable();
|
||||||
of: find.byType(EditEnvironmentVariables),
|
|
||||||
matching: find.byIcon(Icons.remove_circle));
|
|
||||||
await tester.tap(delButtons.at(0));
|
|
||||||
await Future.delayed(const Duration(milliseconds: 500));
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
|
|
||||||
/// Navigate back to Request Editor
|
/// Navigate back to Request Editor
|
||||||
await navigateByIcon(tester, Icons.auto_awesome_mosaic_outlined);
|
await helper.navigateToRequestEditor();
|
||||||
await Future.delayed(const Duration(milliseconds: 200));
|
await Future.delayed(const Duration(milliseconds: 200));
|
||||||
|
|
||||||
/// Check if environment variable is now shown on hover
|
/// Check if environment variable is now shown on hover
|
||||||
|
71
integration_test/env_helper.dart
Normal file
71
integration_test/env_helper.dart
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:spot/spot.dart';
|
||||||
|
import 'package:apidash/consts.dart';
|
||||||
|
import 'package:apidash/widgets/widgets.dart';
|
||||||
|
import 'package:apidash/screens/envvar/environments_pane.dart';
|
||||||
|
import 'package:apidash/screens/envvar/editor_pane/variables_pane.dart';
|
||||||
|
|
||||||
|
class ApidashTestEnvHelper {
|
||||||
|
final WidgetTester tester;
|
||||||
|
|
||||||
|
ApidashTestEnvHelper(this.tester);
|
||||||
|
|
||||||
|
Future<void> addNewEnvironment({bool isMobile = false}) async {
|
||||||
|
if (isMobile) {
|
||||||
|
kEnvScaffoldKey.currentState!.openDrawer();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
}
|
||||||
|
final newEnvButton =
|
||||||
|
spot<EnvironmentsPane>().spot<ElevatedButton>().spotText(kLabelPlusNew);
|
||||||
|
newEnvButton.existsOnce();
|
||||||
|
await act.tap(newEnvButton);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> renameNewEnvironment(String newEnvName) async {
|
||||||
|
Finder envItems = find.byType(EnvironmentItem);
|
||||||
|
Finder newEnvItem = envItems.at(1);
|
||||||
|
expect(find.descendant(of: newEnvItem, matching: find.text("untitled")),
|
||||||
|
findsOneWidget);
|
||||||
|
Finder itemCardMenu =
|
||||||
|
find.descendant(of: newEnvItem, matching: find.byType(ItemCardMenu));
|
||||||
|
await tester.tap(itemCardMenu);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
await tester.tap(find.text(ItemMenuOption.edit.label).last);
|
||||||
|
await tester.pump();
|
||||||
|
await tester.enterText(newEnvItem, newEnvName);
|
||||||
|
await tester.testTextInput.receiveAction(TextInputAction.done);
|
||||||
|
await tester.pump();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> addEnvironmentVariables(
|
||||||
|
List<(String, String)> keyValuePairs) async {
|
||||||
|
final envCells = find.descendant(
|
||||||
|
of: find.byType(EditEnvironmentVariables),
|
||||||
|
matching: find.byType(CellField));
|
||||||
|
for (var i = 0; i < keyValuePairs.length; i++) {
|
||||||
|
await tester.enterText(envCells.at(i), keyValuePairs[i].$1);
|
||||||
|
await tester.enterText(envCells.at(i + 1), keyValuePairs[i].$2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> deleteFirstEnvironmentVariable() async {
|
||||||
|
final delButtons = find.descendant(
|
||||||
|
of: find.byType(EditEnvironmentVariables),
|
||||||
|
matching: find.byIcon(Icons.remove_circle));
|
||||||
|
await tester.tap(delButtons.at(0));
|
||||||
|
await tester.pump();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> setActiveEnvironment(String envName) async {
|
||||||
|
await tester.tap(find.descendant(
|
||||||
|
of: find.byType(EnvironmentPopupMenu),
|
||||||
|
matching: find.byIcon(Icons.unfold_more)));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
await tester.tap(find.text(envName).last);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
}
|
||||||
|
}
|
@ -6,11 +6,8 @@ import 'package:spot/spot.dart';
|
|||||||
import 'package:apidash/app.dart';
|
import 'package:apidash/app.dart';
|
||||||
import 'package:apidash/consts.dart';
|
import 'package:apidash/consts.dart';
|
||||||
import 'package:apidash/widgets/widgets.dart';
|
import 'package:apidash/widgets/widgets.dart';
|
||||||
import 'package:apidash/screens/screens.dart';
|
|
||||||
import 'package:apidash/screens/common_widgets/env_trigger_options.dart';
|
import 'package:apidash/screens/common_widgets/env_trigger_options.dart';
|
||||||
import 'package:apidash/screens/envvar/editor_pane/variables_pane.dart';
|
|
||||||
import 'package:apidash/screens/home_page/editor_pane/url_card.dart';
|
import 'package:apidash/screens/home_page/editor_pane/url_card.dart';
|
||||||
import 'package:apidash/screens/envvar/environments_pane.dart';
|
|
||||||
import '../../test/extensions/widget_tester_extensions.dart';
|
import '../../test/extensions/widget_tester_extensions.dart';
|
||||||
import '../test_helper.dart';
|
import '../test_helper.dart';
|
||||||
|
|
||||||
@ -18,11 +15,9 @@ void main() async {
|
|||||||
const environmentName = "test-env-name";
|
const environmentName = "test-env-name";
|
||||||
const envVarName = "test-env-var";
|
const envVarName = "test-env-var";
|
||||||
const envVarValue = "8700000";
|
const envVarValue = "8700000";
|
||||||
const testEndpoint = "api.apidash.dev/humanize/social?num=";
|
const testEndpoint = "https://api.apidash.dev/humanize/social?num=";
|
||||||
const unknown = "unknown";
|
const unknown = "unknown";
|
||||||
const untitled = "untitled";
|
const expectedCurlCode = "curl --url '$testEndpoint$envVarValue'";
|
||||||
const expectedCurlCode =
|
|
||||||
"curl --url 'https://api.apidash.dev/humanize/social?num=8700000'";
|
|
||||||
|
|
||||||
await ApidashTestHelper.initialize(
|
await ApidashTestHelper.initialize(
|
||||||
size: Size(kCompactWindowWidth, kMinWindowSize.height));
|
size: Size(kCompactWindowWidth, kMinWindowSize.height));
|
||||||
@ -31,79 +26,37 @@ void main() async {
|
|||||||
await tester.pumpUntilFound(find.byType(DashApp));
|
await tester.pumpUntilFound(find.byType(DashApp));
|
||||||
await Future.delayed(const Duration(seconds: 1));
|
await Future.delayed(const Duration(seconds: 1));
|
||||||
|
|
||||||
kHomeScaffoldKey.currentState!.openDrawer();
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
|
|
||||||
/// Navigate to Environment Manager
|
/// Navigate to Environment Manager
|
||||||
await navigateByIcon(tester, Icons.laptop_windows_outlined);
|
await helper.navigateToEnvironmentManager(scaffoldKey: kHomeScaffoldKey);
|
||||||
await Future.delayed(const Duration(milliseconds: 500));
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
|
|
||||||
kEnvScaffoldKey.currentState!.openDrawer();
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
|
|
||||||
/// Create New Environment
|
/// Create New Environment
|
||||||
final newEnvButton =
|
await helper.envHelper.addNewEnvironment(isMobile: true);
|
||||||
spot<EnvironmentsPane>().spot<ElevatedButton>().spotText(kLabelPlusNew);
|
|
||||||
newEnvButton.existsOnce();
|
|
||||||
await act.tap(newEnvButton);
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
await Future.delayed(const Duration(milliseconds: 500));
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
|
|
||||||
/// Open ItemCardMenu of the new environment
|
|
||||||
Finder envItems = find.byType(EnvironmentItem);
|
|
||||||
Finder newEnvItem = envItems.at(1);
|
|
||||||
expect(find.descendant(of: newEnvItem, matching: find.text(untitled)),
|
|
||||||
findsOneWidget);
|
|
||||||
Finder itemCardMenu =
|
|
||||||
find.descendant(of: newEnvItem, matching: find.byType(ItemCardMenu));
|
|
||||||
await tester.tap(itemCardMenu);
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
|
|
||||||
/// Rename the new environment
|
/// Rename the new environment
|
||||||
await tester.tap(find.text(ItemMenuOption.edit.label).last);
|
await helper.envHelper.renameNewEnvironment(environmentName);
|
||||||
await tester.pump();
|
|
||||||
await tester.enterText(newEnvItem, environmentName);
|
|
||||||
await tester.testTextInput.receiveAction(TextInputAction.done);
|
|
||||||
await tester.pump();
|
|
||||||
await Future.delayed(const Duration(milliseconds: 500));
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
|
|
||||||
kEnvScaffoldKey.currentState!.closeDrawer();
|
kEnvScaffoldKey.currentState!.closeDrawer();
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
/// Edit Environment Variables
|
/// Add Environment Variables
|
||||||
final envCells = find.descendant(
|
await helper.envHelper.addEnvironmentVariables([(envVarName, envVarValue)]);
|
||||||
of: find.byType(EditEnvironmentVariables),
|
|
||||||
matching: find.byType(CellField));
|
|
||||||
await tester.enterText(envCells.at(0), envVarName);
|
|
||||||
await tester.enterText(envCells.at(1), envVarValue);
|
|
||||||
await Future.delayed(const Duration(milliseconds: 500));
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
|
|
||||||
kEnvScaffoldKey.currentState!.openDrawer();
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
|
|
||||||
/// Navigate to Request Editor
|
/// Navigate to Request Editor
|
||||||
await navigateByIcon(tester, Icons.auto_awesome_mosaic_outlined);
|
await helper.navigateToRequestEditor(scaffoldKey: kEnvScaffoldKey);
|
||||||
await Future.delayed(const Duration(milliseconds: 200));
|
await Future.delayed(const Duration(milliseconds: 200));
|
||||||
|
|
||||||
kHomeScaffoldKey.currentState!.openDrawer();
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
|
|
||||||
/// Create a new request
|
/// Create a new request
|
||||||
await act.tap(
|
await helper.reqHelper.addNewRequest(isMobile: true);
|
||||||
spot<CollectionPane>().spot<ElevatedButton>().spotText(kLabelPlusNew));
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
|
|
||||||
kHomeScaffoldKey.currentState!.closeDrawer();
|
kHomeScaffoldKey.currentState!.closeDrawer();
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
/// Set active environment
|
/// Set active environment
|
||||||
await tester.tap(find.descendant(
|
await helper.envHelper.setActiveEnvironment(environmentName);
|
||||||
of: find.byType(EnvironmentPopupMenu),
|
|
||||||
matching: find.byIcon(Icons.unfold_more)));
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
|
|
||||||
await tester.tap(find.text(environmentName).last);
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
|
|
||||||
/// Check if environment suggestions are working
|
/// Check if environment suggestions are working
|
||||||
await act.tap(spot<URLTextField>());
|
await act.tap(spot<URLTextField>());
|
||||||
@ -129,19 +82,12 @@ void main() async {
|
|||||||
await gesture.moveBy(const Offset(0, 100));
|
await gesture.moveBy(const Offset(0, 100));
|
||||||
await Future.delayed(const Duration(milliseconds: 500));
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
|
|
||||||
kHomeScaffoldKey.currentState!.openDrawer();
|
await helper.navigateToSettings(scaffoldKey: kHomeScaffoldKey);
|
||||||
await tester.pumpAndSettle();
|
|
||||||
|
|
||||||
/// Change codegen language to curl
|
/// Change codegen language to curl
|
||||||
await navigateByIcon(tester, Icons.settings_outlined);
|
await helper.changeCodegenLanguage(CodegenLanguage.curl);
|
||||||
await tester.tap(find.descendant(
|
|
||||||
of: find.byType(CodegenPopupMenu),
|
|
||||||
matching: find.byIcon(Icons.unfold_more)));
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
|
|
||||||
await tester.tap(find.text(CodegenLanguage.curl.label).last);
|
await helper.navigateToRequestEditor();
|
||||||
await tester.pumpAndSettle();
|
|
||||||
await navigateByIcon(tester, Icons.auto_awesome_mosaic_outlined);
|
|
||||||
await Future.delayed(const Duration(milliseconds: 200));
|
await Future.delayed(const Duration(milliseconds: 200));
|
||||||
|
|
||||||
/// Check variable substitution in request
|
/// Check variable substitution in request
|
||||||
@ -153,25 +99,16 @@ void main() async {
|
|||||||
matching: find.text(expectedCurlCode)),
|
matching: find.text(expectedCurlCode)),
|
||||||
findsOneWidget);
|
findsOneWidget);
|
||||||
|
|
||||||
kHomeScaffoldKey.currentState!.openDrawer();
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
|
|
||||||
/// Navigate to Environment Manager
|
/// Navigate to Environment Manager
|
||||||
await navigateByIcon(tester, Icons.laptop_windows_outlined);
|
await helper.navigateToEnvironmentManager(scaffoldKey: kHomeScaffoldKey);
|
||||||
await Future.delayed(const Duration(milliseconds: 200));
|
await Future.delayed(const Duration(milliseconds: 200));
|
||||||
|
|
||||||
/// Delete the environment variable
|
/// Delete the environment variable
|
||||||
final delButtons = find.descendant(
|
await helper.envHelper.deleteFirstEnvironmentVariable();
|
||||||
of: find.byType(EditEnvironmentVariables),
|
|
||||||
matching: find.byIcon(Icons.remove_circle));
|
|
||||||
await tester.tap(delButtons.at(0));
|
|
||||||
await Future.delayed(const Duration(milliseconds: 500));
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
|
|
||||||
kEnvScaffoldKey.currentState!.openDrawer();
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
|
|
||||||
/// Navigate back to Request Editor
|
/// Navigate back to Request Editor
|
||||||
await navigateByIcon(tester, Icons.auto_awesome_mosaic_outlined);
|
await helper.navigateToRequestEditor(scaffoldKey: kEnvScaffoldKey);
|
||||||
await Future.delayed(const Duration(milliseconds: 200));
|
await Future.delayed(const Duration(milliseconds: 200));
|
||||||
|
|
||||||
/// Check if environment variable is now shown on hover
|
/// Check if environment variable is now shown on hover
|
||||||
|
39
integration_test/req_helper.dart
Normal file
39
integration_test/req_helper.dart
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import 'package:apidash/consts.dart';
|
||||||
|
import 'package:apidash/screens/home_page/collection_pane.dart';
|
||||||
|
import 'package:apidash/widgets/menu_item_card.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:spot/spot.dart';
|
||||||
|
|
||||||
|
class ApidashTestRequestHelper {
|
||||||
|
final WidgetTester tester;
|
||||||
|
|
||||||
|
ApidashTestRequestHelper(this.tester);
|
||||||
|
|
||||||
|
Future<void> addNewRequest({bool isMobile = false}) async {
|
||||||
|
if (isMobile) {
|
||||||
|
kHomeScaffoldKey.currentState!.openDrawer();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
}
|
||||||
|
await act.tap(
|
||||||
|
spot<CollectionPane>().spot<ElevatedButton>().spotText(kLabelPlusNew));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> renameNewRequest(String newReqName) async {
|
||||||
|
Finder reqItems = find.byType(RequestItem);
|
||||||
|
Finder newReqItem = reqItems.at(0);
|
||||||
|
expect(find.descendant(of: newReqItem, matching: find.text("untitled")),
|
||||||
|
findsOneWidget);
|
||||||
|
Finder itemCardMenu =
|
||||||
|
find.descendant(of: newReqItem, matching: find.byType(ItemCardMenu));
|
||||||
|
await tester.tap(itemCardMenu);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
await tester.tap(find.text(ItemMenuOption.edit.label).last);
|
||||||
|
await tester.pump();
|
||||||
|
await tester.enterText(newReqItem, newReqName);
|
||||||
|
await tester.testTextInput.receiveAction(TextInputAction.done);
|
||||||
|
await tester.pump();
|
||||||
|
}
|
||||||
|
}
|
@ -1,16 +1,34 @@
|
|||||||
import 'package:apidash/app.dart';
|
import 'package:apidash/app.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:apidash/consts.dart';
|
||||||
|
import 'package:apidash/widgets/widgets.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||||
import 'package:integration_test/integration_test.dart';
|
import 'package:integration_test/integration_test.dart';
|
||||||
import 'package:apidash/main.dart' as app;
|
import 'package:apidash/main.dart' as app;
|
||||||
|
|
||||||
|
import 'env_helper.dart';
|
||||||
|
import 'req_helper.dart';
|
||||||
|
|
||||||
class ApidashTestHelper {
|
class ApidashTestHelper {
|
||||||
final WidgetTester tester;
|
final WidgetTester tester;
|
||||||
|
|
||||||
ApidashTestHelper(this.tester);
|
ApidashTestHelper(this.tester);
|
||||||
|
|
||||||
|
ApidashTestRequestHelper? _reqHelper;
|
||||||
|
ApidashTestEnvHelper? _envHelper;
|
||||||
|
|
||||||
|
ApidashTestRequestHelper get reqHelper {
|
||||||
|
_reqHelper ??= ApidashTestRequestHelper(tester);
|
||||||
|
return _reqHelper!;
|
||||||
|
}
|
||||||
|
|
||||||
|
ApidashTestEnvHelper get envHelper {
|
||||||
|
_envHelper ??= ApidashTestEnvHelper(tester);
|
||||||
|
return _envHelper!;
|
||||||
|
}
|
||||||
|
|
||||||
static Future<IntegrationTestWidgetsFlutterBinding> initialize(
|
static Future<IntegrationTestWidgetsFlutterBinding> initialize(
|
||||||
{Size? size}) async {
|
{Size? size}) async {
|
||||||
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
||||||
@ -30,6 +48,66 @@ class ApidashTestHelper {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> navigateToRequestEditor(
|
||||||
|
{GlobalKey<ScaffoldState>? scaffoldKey}) async {
|
||||||
|
if (scaffoldKey != null) {
|
||||||
|
scaffoldKey.currentState!.openDrawer();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
}
|
||||||
|
await tester.tap(find.byIcon(Icons.auto_awesome_mosaic_outlined));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> navigateToEnvironmentManager(
|
||||||
|
{GlobalKey<ScaffoldState>? scaffoldKey}) async {
|
||||||
|
if (scaffoldKey != null) {
|
||||||
|
scaffoldKey.currentState!.openDrawer();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
}
|
||||||
|
await tester.tap(find.byIcon(Icons.laptop_windows_outlined));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> navigateToHistory(
|
||||||
|
{GlobalKey<ScaffoldState>? scaffoldKey}) async {
|
||||||
|
if (scaffoldKey != null) {
|
||||||
|
scaffoldKey.currentState!.openDrawer();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
}
|
||||||
|
await tester.tap(find.byIcon(Icons.history_outlined));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> navigateToSettings(
|
||||||
|
{GlobalKey<ScaffoldState>? scaffoldKey}) async {
|
||||||
|
if (scaffoldKey != null) {
|
||||||
|
scaffoldKey.currentState!.openDrawer();
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
}
|
||||||
|
await tester.tap(find.byIcon(Icons.settings_outlined));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> changeURIScheme(String scheme) async {
|
||||||
|
await tester.tap(find.descendant(
|
||||||
|
of: find.byType(URIPopupMenu),
|
||||||
|
matching: find.byIcon(Icons.unfold_more)));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
await tester.tap(find.text(scheme).last);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> changeCodegenLanguage(CodegenLanguage language) async {
|
||||||
|
await tester.tap(find.descendant(
|
||||||
|
of: find.byType(CodegenPopupMenu),
|
||||||
|
matching: find.byIcon(Icons.unfold_more)));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
await tester.tap(find.text(language.label).last);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@isTest
|
@isTest
|
||||||
@ -46,8 +124,3 @@ void apidashWidgetTest(
|
|||||||
semanticsEnabled: false,
|
semanticsEnabled: false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> navigateByIcon(WidgetTester tester, IconData icon) async {
|
|
||||||
await tester.tap(find.byIcon(icon));
|
|
||||||
await tester.pumpAndSettle();
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user