mirror of
https://github.com/foss42/apidash.git
synced 2025-12-05 12:34:26 +08:00
test: env_manager desktop
This commit is contained in:
@@ -1,29 +1,38 @@
|
|||||||
|
import 'dart:ui';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:spot/spot.dart';
|
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/screens/screens.dart';
|
import 'package:apidash/screens/screens.dart';
|
||||||
import 'package:apidash/widgets/field_cell.dart';
|
|
||||||
import 'package:apidash/widgets/menu_item_card.dart';
|
|
||||||
import 'package:apidash/widgets/popup_menu_env.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/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 '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';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
|
const environmentName = "test-env-name";
|
||||||
|
const envVarName = "test-env-var";
|
||||||
|
const envVarValue = "8700000";
|
||||||
|
const testEndpoint = "api.apidash.dev/humanize/social?num=";
|
||||||
|
const unknown = "unknown";
|
||||||
|
const untitled = "untitled";
|
||||||
|
const expectedCurlCode =
|
||||||
|
"curl --url 'https://api.apidash.dev/humanize/social?num=8700000'";
|
||||||
|
|
||||||
await ApidashTestHelper.initialize();
|
await ApidashTestHelper.initialize();
|
||||||
apidashWidgetTest("Testing Environment Manager end-to-end",
|
apidashWidgetTest("Testing Environment Manager in desktop end-to-end",
|
||||||
(WidgetTester tester, helper) async {
|
(WidgetTester tester, helper) 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));
|
||||||
|
|
||||||
/// Navigate to Environment Manager
|
/// Navigate to Environment Manager
|
||||||
await navigateByIcon(Icons.laptop_windows_outlined, tester);
|
await navigateByIcon(tester, Icons.laptop_windows_outlined);
|
||||||
await Future.delayed(const Duration(milliseconds: 500));
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
|
|
||||||
/// Create New Environment
|
/// Create New Environment
|
||||||
@@ -37,7 +46,7 @@ void main() async {
|
|||||||
/// Open ItemCardMenu of the new environment
|
/// Open ItemCardMenu of the new environment
|
||||||
Finder envItems = find.byType(EnvironmentItem);
|
Finder envItems = find.byType(EnvironmentItem);
|
||||||
Finder newEnvItem = envItems.at(1);
|
Finder newEnvItem = envItems.at(1);
|
||||||
expect(find.descendant(of: newEnvItem, matching: find.text('untitled')),
|
expect(find.descendant(of: newEnvItem, matching: find.text(untitled)),
|
||||||
findsOneWidget);
|
findsOneWidget);
|
||||||
Finder itemCardMenu =
|
Finder itemCardMenu =
|
||||||
find.descendant(of: newEnvItem, matching: find.byType(ItemCardMenu));
|
find.descendant(of: newEnvItem, matching: find.byType(ItemCardMenu));
|
||||||
@@ -45,9 +54,9 @@ void main() async {
|
|||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
/// Rename the new environment
|
/// Rename the new environment
|
||||||
await tester.tap(find.text('Rename').last);
|
await tester.tap(find.text(ItemMenuOption.edit.label).last);
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
await tester.enterText(newEnvItem, "New Environment");
|
await tester.enterText(newEnvItem, environmentName);
|
||||||
await tester.testTextInput.receiveAction(TextInputAction.done);
|
await tester.testTextInput.receiveAction(TextInputAction.done);
|
||||||
await tester.pump();
|
await tester.pump();
|
||||||
await Future.delayed(const Duration(milliseconds: 500));
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
@@ -56,13 +65,13 @@ void main() async {
|
|||||||
final envCells = find.descendant(
|
final envCells = find.descendant(
|
||||||
of: find.byType(EditEnvironmentVariables),
|
of: find.byType(EditEnvironmentVariables),
|
||||||
matching: find.byType(CellField));
|
matching: find.byType(CellField));
|
||||||
await tester.enterText(envCells.at(0), "test-key");
|
await tester.enterText(envCells.at(0), envVarName);
|
||||||
await tester.enterText(envCells.at(1), "test-value");
|
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(Icons.auto_awesome_mosaic_outlined, tester);
|
await navigateByIcon(tester, Icons.auto_awesome_mosaic_outlined);
|
||||||
await Future.delayed(const Duration(milliseconds: 500));
|
await Future.delayed(const Duration(milliseconds: 200));
|
||||||
|
|
||||||
/// Create a new request
|
/// Create a new request
|
||||||
await act.tap(
|
await act.tap(
|
||||||
@@ -75,43 +84,75 @@ void main() async {
|
|||||||
matching: find.byIcon(Icons.unfold_more)));
|
matching: find.byIcon(Icons.unfold_more)));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
await tester.tap(find.text('New Environment').last);
|
await tester.tap(find.text(environmentName).last);
|
||||||
await tester.pumpAndSettle();
|
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>());
|
||||||
tester.testTextInput.enterText("{{test-k");
|
tester.testTextInput.enterText("$testEndpoint{{$envVarName");
|
||||||
await tester.pumpAndSettle(
|
await tester.pumpAndSettle(
|
||||||
const Duration(milliseconds: 500)); // wait for suggestions
|
const Duration(milliseconds: 500)); // wait for suggestions
|
||||||
spot<EnvironmentTriggerOptions>()
|
await act.tap(spot<EnvironmentTriggerOptions>()
|
||||||
.spot<ListTile>()
|
.spot<ListTile>()
|
||||||
.spotText('test-key')
|
.spotText(envVarValue));
|
||||||
.existsOnce();
|
await tester.pumpAndSettle();
|
||||||
|
|
||||||
|
final gesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||||
|
await gesture.addPointer(location: Offset.zero);
|
||||||
|
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 Future.delayed(const Duration(milliseconds: 500));
|
||||||
|
|
||||||
|
/// Change codegen language to curl
|
||||||
|
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);
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
await navigateByIcon(tester, Icons.auto_awesome_mosaic_outlined);
|
||||||
|
await Future.delayed(const Duration(milliseconds: 200));
|
||||||
|
|
||||||
|
/// Check variable substitution in request
|
||||||
|
await act.tap(spot<RequestPane>().spotText(kLabelViewCode));
|
||||||
|
await tester.pumpAndSettle();
|
||||||
|
expect(
|
||||||
|
find.descendant(
|
||||||
|
of: find.byType(CodeGenPreviewer),
|
||||||
|
matching: find.text(expectedCurlCode)),
|
||||||
|
findsOneWidget);
|
||||||
|
|
||||||
/// Navigate to Environment Manager
|
/// Navigate to Environment Manager
|
||||||
await navigateByIcon(Icons.laptop_windows_outlined, tester);
|
await navigateByIcon(tester, Icons.laptop_windows_outlined);
|
||||||
await Future.delayed(const Duration(milliseconds: 500));
|
await Future.delayed(const Duration(milliseconds: 200));
|
||||||
|
|
||||||
/// Delete the environment variable
|
/// Delete the environment variable
|
||||||
final delButtons = find.descendant(
|
final delButtons = find.descendant(
|
||||||
of: find.byType(EditEnvironmentVariables),
|
of: find.byType(EditEnvironmentVariables),
|
||||||
matching: find.byIcon(Icons.remove_circle));
|
matching: find.byIcon(Icons.remove_circle));
|
||||||
await tester.tap(delButtons.at(0));
|
await tester.tap(delButtons.at(0));
|
||||||
|
|
||||||
/// Navigate back to Request Editor
|
|
||||||
await navigateByIcon(Icons.auto_awesome_mosaic_outlined, tester);
|
|
||||||
await Future.delayed(const Duration(milliseconds: 500));
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
|
|
||||||
/// Check if environment suggestions are shown
|
/// Navigate back to Request Editor
|
||||||
await act.tap(spot<RequestEditor>().spot<URLTextField>());
|
await navigateByIcon(tester, Icons.auto_awesome_mosaic_outlined);
|
||||||
tester.testTextInput.enterText("{{test-k");
|
await Future.delayed(const Duration(milliseconds: 200));
|
||||||
await tester.pumpAndSettle(
|
|
||||||
const Duration(milliseconds: 500)); // wait for suggestions
|
|
||||||
spot<EnvironmentTriggerOptions>()
|
|
||||||
.spot<ListTile>()
|
|
||||||
.spotText('test-key')
|
|
||||||
.doesNotExist();
|
|
||||||
|
|
||||||
await Future.delayed(const Duration(seconds: 2));
|
/// 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));
|
||||||
|
|
||||||
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,7 @@ void apidashWidgetTest(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> navigateByIcon(IconData icon, WidgetTester tester) async {
|
Future<void> navigateByIcon(WidgetTester tester, IconData icon) async {
|
||||||
await tester.tap(find.byIcon(icon));
|
await tester.tap(find.byIcon(icon));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user