enterCompanyData static method
enter company data in company dialog screen. when the list only contains a single item it is assumed the detail screen is already shown and need not be created/opened
Implementation
static Future<void> enterCompanyData(
WidgetTester tester, List<Company> inputList) async {
SaveTest test = await PersistFunctions.getTest();
if (inputList.length == 1) {
// if single company: main company test
test = test.copyWith(companies: [test.company!]);
}
// if already done return
if (test.companies.isNotEmpty &&
test.companies[0].name == inputList[0].name) {
return;
}
// create new list with pseudoId from last list from test if not empty
List<Company> clist = List.of(inputList);
if (test.companies.isNotEmpty) {
for (int x = 0; x < test.companies.length; x++) {
clist[x] = clist[x].copyWith(pseudoId: test.companies[x].pseudoId);
}
}
int seq = test.sequence;
List<Company> newCompanies = [];
for (Company c in clist) {
if (clist.length > 1) {
// single (main) company no selection
if (c.pseudoId == null) {
await CommonTest.tapByKey(tester, 'addNewCompany');
} else {
await CommonTest.doNewSearch(tester, searchString: c.pseudoId!);
expect(
CommonTest.getTextField('topHeader').split('#')[1], c.pseudoId);
}
}
await CommonTest.enterText(tester, 'companyName', c.name!);
if (c.currency != null) {
await CommonTest.enterDropDown(
tester, 'currency', c.currency?.description ?? '');
}
await CommonTest.enterText(tester, 'telephoneNr', c.telephoneNr ?? '');
await CommonTest.dragNew(tester, key: 'telephoneNr');
if (c.email != null && c.email!.isNotEmpty) {
c = c.copyWith(email: c.email!.replaceFirst('XXX', '${seq++}'));
}
await CommonTest.enterText(tester, 'email', c.email ?? '');
if (c.role == Role.company) {
await CommonTest.enterText(tester, 'vatPerc', c.vatPerc.toString());
await CommonTest.enterText(tester, 'salesPerc', c.salesPerc.toString());
}
// if required add address and payment
if (c.address != null) {
await updateAddress(tester, c.address!);
} else {
if (CommonTest.getTextField('addressLabel') !=
'No postal address yet') {
await CommonTest.tapByKey(tester, 'deleteAddress');
}
}
if (c.paymentMethod != null) {
await updatePaymentMethod(tester, c.paymentMethod!);
} else {
if (!CommonTest.getTextField('paymentMethodLabel')
.startsWith('No payment methods yet')) {
await CommonTest.tapByKey(tester, 'deletePaymentMethod');
}
}
await CommonTest.dragNew(tester, key: 'paymentMethodLabel');
// add/update company record
await CommonTest.tapByKey(tester, 'update', seconds: CommonTest.waitTime);
if (clist.length > 1 && c.pseudoId == null) {
await CommonTest.doNewSearch(tester, searchString: c.name!);
var id = CommonTest.getTextField('topHeader').split('#')[1];
c = c.copyWith(pseudoId: id);
await CommonTest.tapByKey(tester, 'cancel');
}
newCompanies.add(c);
}
await PersistFunctions.persistTest(
test.copyWith(companies: newCompanies, sequence: seq));
await CommonTest.gotoMainMenu(tester);
}