-
Notifications
You must be signed in to change notification settings - Fork 556
/
Copy pathinvoices_it_test.dart
173 lines (144 loc) · 5.43 KB
/
invoices_it_test.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// Package imports:
import 'package:faker/faker.dart';
import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart';
// Project imports:
import 'utils/common_actions.dart';
import 'utils/localizations.dart';
void main() {
runTestSuite();
}
void runTestSuite({bool batchMode = false}) {
group('Invoice Tests', () {
late TestLocalization localization;
FlutterDriver? driver;
final clientName = makeUnique(faker.company.name());
final poNumber =
faker.randomGenerator.integer(999999, min: 100000).toString();
final productKey = makeUnique(faker.food.cuisine());
final clientKey =
faker.randomGenerator.integer(999999, min: 100000).toString();
final description = faker.lorem.sentences(5).toString();
final cost =
faker.randomGenerator.decimal(min: 50, scale: 10).toStringAsFixed(2);
final updatedPoNumber =
faker.randomGenerator.integer(999999, min: 100000).toString();
setUpAll(() async {
localization = TestLocalization('en');
driver = await FlutterDriver.connect();
print('Login to app');
await login(driver!, retype: batchMode);
print('View invoices');
await viewSection(driver: driver!, name: localization.invoices);
});
tearDownAll(() async {
await logout(driver!, localization);
if (driver != null) {
driver!.close();
}
});
// Create an empty invoice
test('Try to add an empty invoice', () async {
print('Tap new invoice');
await driver!.tap(find.byTooltip(localization.newInvoice));
print('Tap save');
await driver!.tap(find.text(localization.save));
print('Check for error');
await driver!.waitFor(find.text(localization.pleaseSelectAClient));
if (await isMobile(driver!)) {
print('Click back');
await driver!.tap(find.pageBack());
await driver!.waitFor(find.byTooltip(localization.newInvoice));
} else {
print('Click cancel');
await driver!.tap(find.text(localization.cancel));
}
});
// Create a new invoice
test('Add a new invoice', () async {
print('Tap new invoice');
await driver!.tap(find.byTooltip(localization.newInvoice));
print('Create new client: $clientName');
if (await isMobile(driver!)) {
await driver!.tap(find.byValueKey(Keys.clientPickerEmptyKey));
}
await driver!.tap(find.byTooltip(localization.createNew));
print('Fill the client form');
await fillTextFields(driver, <String, String>{
localization.name: clientName,
localization.idNumber: clientKey
});
// Await for Debouncer
await Future<dynamic>.delayed(Duration(milliseconds: 500));
await driver!.tap(find.text(localization.save));
// Await for Screen change
await driver!.waitFor(find.text(localization.newInvoice));
print('Fill the invoice form');
if (await isMobile(driver!)) {
await driver!.tap(find.byTooltip(localization.addItem));
await driver!.tap(find.byTooltip(localization.createNew));
await fillTextFields(driver, <String, String>{
localization.product: productKey,
localization.description: description,
localization.unitCost: cost,
localization.quantity: '1',
});
// Await for Debouncer
await Future<dynamic>.delayed(Duration(milliseconds: 500));
await driver!.tap(find.text(localization.done.toUpperCase()));
await driver!.tap(find.text(localization.details));
} else {
await fillTextFields(driver, <String, String>{
getLineItemKey('name', 0): productKey,
getLineItemKey('description', 0): description,
getLineItemKey('cost', 0): cost,
getLineItemKey('quantity', 0): '1'
});
}
await fillAndSaveForm(driver!, <String, String>{
localization.poNumber: poNumber,
});
if (await isMobile(driver!)) {
print('Click back');
await driver!.tap(find.pageBack());
await driver!.waitFor(find.byTooltip(localization.newInvoice));
}
});
// Edit the newly created invoice
test('Edit an existing invoice', () async {
if (await isMobile(driver!)) {
print('Select invoice: $clientName');
await driver!.scrollUntilVisible(
find.byType('ListView'), find.text(clientName),
dyScroll: -300);
await driver!.tap(find.text(clientName));
}
print('Tap edit');
await driver!.tap(find.text(localization.edit));
await fillAndSaveForm(driver!, <String, String>{
localization.poNumber: updatedPoNumber,
});
});
// Archive the edited invoice
test('Archive/delete invoice test', () async {
await testArchiveAndDelete(
driver: driver!,
rowText: clientName,
archivedMessage: localization.archivedInvoice,
deletedMessage: localization.deletedInvoice,
restoredMessage: localization.restoredInvoice);
});
// Mark the invoice as paid
test('Mark invoice as paid', () async {
await selectAction(driver!, localization.enterPayment);
await driver!.tap(find.text(localization.save));
// "Completed" status
await driver!
.waitFor(find.text(localization.paymentStatus4.toUpperCase()));
if (await isMobile(driver!)) {
await driver!.tap(find.pageBack());
await driver!.tap(find.pageBack());
}
});
});
}