mirror of
https://github.com/foss42/apidash.git
synced 2025-05-21 16:26:37 +08:00
test: his_request_test desktop
This commit is contained in:
63
integration_test/desktop/his_request_test.dart
Normal file
63
integration_test/desktop/his_request_test.dart
Normal file
@ -0,0 +1,63 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:apidash/screens/history/history_pane.dart';
|
||||
import 'package:apidash/screens/history/history_requests.dart';
|
||||
import 'package:apidash/widgets/widgets.dart';
|
||||
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 '../../test/extensions/widget_tester_extensions.dart';
|
||||
import '../test_helper.dart';
|
||||
|
||||
void main() async {
|
||||
await ApidashTestHelper.initialize(
|
||||
size: Size(kExpandedWindowWidth, kMinWindowSize.height));
|
||||
apidashWidgetTest("Testing Environment Manager 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(
|
||||
"https://api.apidash.dev/humanize/social",
|
||||
name: "Social",
|
||||
params: [("num", "870000")],
|
||||
);
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
await helper.reqHelper.sendRequest();
|
||||
|
||||
/// Navigate to History
|
||||
await helper.navigateToHistory();
|
||||
var sidebarCards = spot<HistoryPane>().spot<SidebarHistoryCard>().finder;
|
||||
final initSidebarCardCount =
|
||||
tester.widgetList<SidebarHistoryCard>(sidebarCards).length;
|
||||
var historyCards =
|
||||
spot<HistoryRequests>().spot<HistoryRequestCard>().finder;
|
||||
final initHistoryCardCount =
|
||||
tester.widgetList<HistoryRequestCard>(historyCards).length;
|
||||
|
||||
/// Send another request with same name
|
||||
await helper.navigateToRequestEditor();
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
await helper.reqHelper.addRequest(
|
||||
"https://api.apidash.dev/convert/leet",
|
||||
name: "Social",
|
||||
params: [("text", "870000")],
|
||||
);
|
||||
await Future.delayed(const Duration(milliseconds: 200));
|
||||
await helper.reqHelper.sendRequest();
|
||||
|
||||
/// Check history Card counts
|
||||
await helper.navigateToHistory();
|
||||
sidebarCards = spot<HistoryPane>().spot<SidebarHistoryCard>().finder;
|
||||
final newSidebarCardCount =
|
||||
tester.widgetList<SidebarHistoryCard>(sidebarCards).length;
|
||||
historyCards = spot<HistoryRequests>().spot<HistoryRequestCard>().finder;
|
||||
final newHistoryCardCount =
|
||||
tester.widgetList<HistoryRequestCard>(historyCards).length;
|
||||
expect(newSidebarCardCount, initSidebarCardCount);
|
||||
expect(newHistoryCardCount, initHistoryCardCount + 1);
|
||||
});
|
||||
}
|
@ -42,12 +42,15 @@ class ApidashTestEnvHelper {
|
||||
|
||||
Future<void> addEnvironmentVariables(
|
||||
List<(String, String)> keyValuePairs) async {
|
||||
final envCells = find.descendant(
|
||||
var 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);
|
||||
await tester.enterText(envCells.at(i * 2), keyValuePairs[i].$1);
|
||||
await tester.enterText(envCells.at(i * 2 + 1), keyValuePairs[i].$2);
|
||||
envCells = find.descendant(
|
||||
of: find.byType(EditEnvironmentVariables),
|
||||
matching: find.byType(CellField));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,13 @@
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:apidash/screens/home_page/collection_pane.dart';
|
||||
import 'package:apidash/screens/home_page/editor_pane/url_card.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';
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:apidash/widgets/widgets.dart';
|
||||
import 'package:apidash/screens/common_widgets/common_widgets.dart';
|
||||
import 'package:apidash/screens/home_page/collection_pane.dart';
|
||||
import 'package:apidash/screens/home_page/editor_pane/url_card.dart';
|
||||
import 'package:apidash/screens/home_page/editor_pane/details_card/request_pane/request_params.dart';
|
||||
import 'package:apidash/screens/home_page/editor_pane/details_card/request_pane/request_headers.dart';
|
||||
|
||||
class ApidashTestRequestHelper {
|
||||
final WidgetTester tester;
|
||||
@ -42,4 +45,88 @@ class ApidashTestRequestHelper {
|
||||
await act.tap(spot<URLTextField>());
|
||||
tester.testTextInput.enterText(url);
|
||||
}
|
||||
|
||||
Future<void> setRequestMethod(HTTPVerb method) async {
|
||||
final methodDropdown = spot<DropdownButtonHTTPMethod>();
|
||||
await act.tap(methodDropdown);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text(method.name.toUpperCase()).last);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
|
||||
Future<void> addRequestParams(List<(String, String)> keyValuePairs) async {
|
||||
final paramTabButton =
|
||||
spot<RequestPane>().spot<TabBar>().spotText(kLabelURLParams);
|
||||
await act.tap(paramTabButton);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
var paramCells = find.descendant(
|
||||
of: find.byType(EditRequestURLParams),
|
||||
matching: find.byType(EnvCellField));
|
||||
for (var i = 0; i < keyValuePairs.length; i++) {
|
||||
await tester.tap(paramCells.at(i));
|
||||
tester.testTextInput.enterText(keyValuePairs[i].$1);
|
||||
await tester.tap(paramCells.at(i + 1));
|
||||
tester.testTextInput.enterText(keyValuePairs[i].$2);
|
||||
paramCells = find.descendant(
|
||||
of: find.byType(EditRequestURLParams),
|
||||
matching: find.byType(EnvCellField));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> addRequestHeaders(List<(String, String)> keyValuePairs) async {
|
||||
final headerTabButton =
|
||||
spot<RequestPane>().spot<TabBar>().spotText(kLabelHeaders);
|
||||
await act.tap(headerTabButton);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
var headerCells = find.descendant(
|
||||
of: find.byType(EditRequestHeaders),
|
||||
matching: find.byType(HeaderField));
|
||||
var valueCells = find.descendant(
|
||||
of: find.byType(EditRequestHeaders),
|
||||
matching: find.byType(EnvCellField));
|
||||
for (var i = 0; i < keyValuePairs.length; i++) {
|
||||
await tester.tap(headerCells.at(i));
|
||||
tester.testTextInput.enterText(keyValuePairs[i].$1);
|
||||
await tester.tap(valueCells.at(i));
|
||||
tester.testTextInput.enterText(keyValuePairs[i].$2);
|
||||
headerCells = find.descendant(
|
||||
of: find.byType(EditRequestHeaders),
|
||||
matching: find.byType(HeaderField));
|
||||
valueCells = find.descendant(
|
||||
of: find.byType(EditRequestHeaders),
|
||||
matching: find.byType(EnvCellField));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> addRequest(
|
||||
String url, {
|
||||
String? name,
|
||||
HTTPVerb method = HTTPVerb.get,
|
||||
List<(String, String)> params = const [],
|
||||
List<(String, String)> headers = const [],
|
||||
bool isMobile = false,
|
||||
}) async {
|
||||
await addNewRequest(isMobile: isMobile);
|
||||
if (name != null) {
|
||||
await renameNewRequest(name);
|
||||
}
|
||||
if (isMobile) {
|
||||
kHomeScaffoldKey.currentState!.closeDrawer();
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
if (method != HTTPVerb.get) {
|
||||
await setRequestMethod(method);
|
||||
}
|
||||
await addRequestURL(url);
|
||||
await addRequestParams(params);
|
||||
await addRequestHeaders(headers);
|
||||
}
|
||||
|
||||
Future<void> sendRequest(
|
||||
{Duration stallTime = const Duration(seconds: 3)}) async {
|
||||
await act.tap(spot<SendRequestButton>());
|
||||
await tester.pumpAndSettle(stallTime);
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
import 'package:apidash/app.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_test/flutter_test.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:integration_test/integration_test.dart';
|
||||
import 'package:apidash/main.dart' as app;
|
||||
import 'package:apidash/app.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:apidash/widgets/widgets.dart';
|
||||
|
||||
import 'env_helper.dart';
|
||||
import 'req_helper.dart';
|
||||
|
@ -761,6 +761,7 @@ const kHintAddName = "Add Name";
|
||||
const kHintAddFieldName = "Add Field Name";
|
||||
const kLabelAddParam = "Add Param";
|
||||
const kLabelAddHeader = "Add Header";
|
||||
const kLabelAddVariable = "Add Variable";
|
||||
const kLabelSelectFile = "Select File";
|
||||
const kLabelAddFormField = "Add Form Field";
|
||||
// Response Pane
|
||||
|
@ -217,7 +217,7 @@ class EditEnvironmentVariablesState
|
||||
},
|
||||
icon: const Icon(Icons.add),
|
||||
label: const Text(
|
||||
"Add Variable",
|
||||
kLabelAddVariable,
|
||||
style: kTextStyleButton,
|
||||
),
|
||||
),
|
||||
|
Reference in New Issue
Block a user