import 'package:flutter_driver/flutter_driver.dart'; import 'package:test/test.dart'; import 'package:faker/faker.dart'; import 'utils/common_actions.dart'; import 'utils/localizations.dart'; void main() { group('PRODUCTS TEST', () { TestLocalization localization; FlutterDriver driver; final productKey = faker.food.cuisine() + ' ' + faker.randomGenerator.decimal(min: 1).toStringAsFixed(0); final notes = faker.food.dish(); final cost = faker.randomGenerator.decimal(min: 50).toStringAsFixed(2); final updatedProductKey = faker.food.cuisine(); final updatedNotes = faker.food.dish(); final updatedCost = faker.randomGenerator.decimal(min: 50).toStringAsFixed(2); setUpAll(() async { localization = TestLocalization('en'); driver = await FlutterDriver.connect(); print('Login to app'); await login(driver); print('View products'); await driver.tap(find.byTooltip(Keys.openAppDrawer)); await driver.tap(find.byTooltip(localization.products)); }); tearDownAll(() async { await logout(driver, localization); if (driver != null) { driver.close(); } }); // Create an empty product test('Try to add an empty product', () async { print('Tap new product'); await driver.tap(find.byTooltip(localization.newProduct)); print('Tap save'); await driver.tap(find.text(localization.save)); print('Check for error'); await driver.waitFor(find.text(localization.pleaseEnterAProductKey)); print('Click back'); await driver.tap(find.pageBack()); }); // Create a new product test('Add a new product', () async { print('Tap new product'); await driver.tap(find.byTooltip(localization.newProduct)); print('Fill form: $productKey'); await fillTextFields(driver, { localization.productKey: productKey, localization.notes: notes, localization.cost: cost, }); print('Tap save'); await driver.tap(find.text(localization.save)); //await driver.waitFor(find.text(localization.createdProduct)); //await driver.waitFor(find.text(productKey)); /* await driver.tap(find.pageBack()); await driver.scrollUntilVisible( find.byType('ListView'), find.text(productKey)); await driver.tap(find.text(productKey)); */ print('Check for new value: $productKey'); await driver.waitFor(find.text(productKey)); await driver.waitFor(find.text(notes)); //await driver.waitFor(find.text(cost)); print('Click back'); await driver.tap(find.pageBack()); await driver.waitFor(find.byTooltip(localization.newProduct)); }); // Edit the newly created product test('Edit an existing product', () async { print('Select product: $productKey'); await driver.scrollUntilVisible( find.byType('ListView'), find.text(productKey), dyScroll: -300); await driver.tap(find.text(productKey)); print('Tap edit'); await driver.tap(find.text(localization.edit)); print('Fill in form: $updatedProductKey'); await fillTextFields(driver, { localization.productKey: updatedProductKey, localization.notes: updatedNotes, localization.cost: updatedCost, }); print('Tap save'); await driver.tap(find.text(localization.save)); // verify snackbar //await driver.waitFor(find.text(localization.updatedProduct)); //await driver.tap(find.pageBack()); print('Check for updated values'); await driver.waitFor(find.text(updatedProductKey)); await driver.waitFor(find.text(updatedNotes)); //await driver.waitFor(find.text(updatedCost)); }); // Archive the edited product test('Archieve a product test', () async { print('Archive product'); await driver.tap(find.byType('ActionMenuButton')); await driver.tap(find.text(localization.archive)); await driver.waitFor(find.text(localization.archivedProduct)); print('Restore product'); await driver.tap(find.byType('ActionMenuButton')); await driver.tap(find.text(localization.restore)); await driver.waitFor(find.text(localization.restoredProduct)); print('Delete product'); await driver.tap(find.byType('ActionMenuButton')); await driver.tap(find.text(localization.delete)); await driver.waitFor(find.text(localization.deletedProduct)); print('Restore product'); await driver.tap(find.byType('ActionMenuButton')); await driver.tap(find.text(localization.restore)); await driver.waitFor(find.text(localization.restoredProduct)); await driver.tap(find.pageBack()); }); }); }