mirror of
https://github.com/foss42/apidash.git
synced 2025-06-17 20:16:27 +08:00
refactor: abstract to helper
This commit is contained in:
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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user