From 49e0a64bfc248f8a634ad36a2233735e71660f6a Mon Sep 17 00:00:00 2001 From: Gianfranco Gasbarri Date: Sun, 1 Sep 2019 17:47:27 +0100 Subject: [PATCH] Quotes Tests --- test_driver/all_it_test.dart | 4 + test_driver/invoices_it_test.dart | 2 +- test_driver/quotes_it.dart | 8 ++ test_driver/quotes_it_test.dart | 145 ++++++++++++++++++++++++++++++ 4 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 test_driver/quotes_it.dart create mode 100644 test_driver/quotes_it_test.dart diff --git a/test_driver/all_it_test.dart b/test_driver/all_it_test.dart index 870ba28b8..a4980431d 100644 --- a/test_driver/all_it_test.dart +++ b/test_driver/all_it_test.dart @@ -2,10 +2,14 @@ import 'clients_it_test.dart' as clients; import 'invoices_it_test.dart' as invoices; import 'login_it_test.dart' as login; import 'products_it_test.dart' as products; +import 'quotes_it_test.dart' as quotes; +import 'vendors_it_test.dart' as vendors; void main() { login.main(); products.runTestSuite(batchMode: true); clients.runTestSuite(batchMode: true); invoices.runTestSuite(batchMode: true); + quotes.runTestSuite(batchMode: true); + vendors.runTestSuite(batchMode: true); } diff --git a/test_driver/invoices_it_test.dart b/test_driver/invoices_it_test.dart index f9bac7413..f8888cc2f 100644 --- a/test_driver/invoices_it_test.dart +++ b/test_driver/invoices_it_test.dart @@ -123,7 +123,7 @@ void runTestSuite({bool batchMode = false}) { }); // Archive the edited invoice - test('Archieve/delete invoice test', () async { + test('Archive/delete invoice test', () async { await testArchiveAndDelete( driver: driver, archivedMessage: localization.archivedInvoice, diff --git a/test_driver/quotes_it.dart b/test_driver/quotes_it.dart new file mode 100644 index 000000000..8b3c41a49 --- /dev/null +++ b/test_driver/quotes_it.dart @@ -0,0 +1,8 @@ +import 'package:flutter_driver/driver_extension.dart'; +import 'package:invoiceninja_flutter/main.dart' as app; + +void main() { + // This line enables the extension + enableFlutterDriverExtension(); + app.main(isTesting: true); +} diff --git a/test_driver/quotes_it_test.dart b/test_driver/quotes_it_test.dart new file mode 100644 index 000000000..81a1c4c86 --- /dev/null +++ b/test_driver/quotes_it_test.dart @@ -0,0 +1,145 @@ +import 'package:faker/faker.dart'; +import 'package:flutter_driver/flutter_driver.dart'; +import 'package:test/test.dart'; + +import 'utils/common_actions.dart'; +import 'utils/localizations.dart'; + +void main() { + runTestSuite(); +} + +void runTestSuite({bool batchMode = false}) { + group('Quote Tests', () { + 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 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 quotes'); + viewSection(driver: driver, name: localization.quotes); + }); + + tearDownAll(() async { + await logout(driver, localization); + + if (driver != null) { + driver.close(); + } + }); + + // Create an empty quote + test('Try to add an empty quote', () async { + print('Tap new quote'); + await driver.tap(find.byTooltip(localization.newQuote)); + + 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.newQuote)); + } else { + print('Click cancel'); + await driver.tap(find.text(localization.cancel)); + } + }); + + // Create a new quote + test('Add a new quote', () async { + print('Tap new quote'); + await driver.tap(find.byTooltip(localization.newQuote)); + + print('Create new client: $clientName'); + await driver.tap(find.byValueKey(localization.client)); + await driver.tap(find.byTooltip(localization.createNew)); + + print('Fill the client form'); + await fillTextField( + driver: driver, field: localization.name, value: clientName); + await driver.tap(find.text(localization.save)); + + print('Fill the quote form'); + await driver.tap(find.byTooltip(localization.addItem)); + await driver.tap(find.byTooltip(localization.createNew)); + + await fillTextFields(driver, { + localization.product: productKey, + localization.description: description, + localization.unitCost: cost, + localization.quantity: '1', + }); + + await driver.tap(find.text(localization.done)); + await driver.tap(find.text(localization.details)); + + await fillAndSaveForm(driver, { + localization.poNumber: poNumber, + }); + + if (await isMobile(driver)) { + print('Click back'); + await driver.tap(find.pageBack()); + await driver.waitFor(find.byTooltip(localization.newQuote)); + } + }); + + // Edit the newly created quote + test('Edit an existing quote', () async { + if (await isMobile(driver)) { + print('Select quote: $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, { + localization.poNumber: updatedPoNumber, + }); + }); + + // Archive the edited quote + test('Archive/delete quote test', () async { + await testArchiveAndDelete( + driver: driver, + archivedMessage: localization.archivedQuote, + deletedMessage: localization.deletedQuote, + restoredMessage: localization.restoredQuote); + }); + + // Convert to invoice + test('Convert to invoice', () async { + await selectAction(driver, localization.convert); + await driver.waitFor(find.byType('InvoiceView')); + + if (await isMobile(driver)) { + await driver.tap(find.pageBack()); + await driver.tap(find.pageBack()); + } + }); + }); +}