forked from foss42/apidash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv_helper.dart
74 lines (65 loc) · 2.59 KB
/
env_helper.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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(kUntitled)),
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 {
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 * 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));
}
}
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();
}
}