Added Vendor Test
This commit is contained in:
parent
59f2ecd8c8
commit
cd503e7269
|
|
@ -265,6 +265,13 @@ abstract class VendorEntity extends Object
|
|||
FormatNumberType get listDisplayAmountType => FormatNumberType.money;
|
||||
|
||||
static Serializer<VendorEntity> get serializer => _$vendorEntitySerializer;
|
||||
|
||||
bool get hasNameSet {
|
||||
final contact = contacts.first;
|
||||
return name.isNotEmpty ||
|
||||
contact.fullName.isNotEmpty ||
|
||||
contact.email.isNotEmpty;
|
||||
}
|
||||
}
|
||||
|
||||
abstract class VendorContactEntity extends Object
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:invoiceninja_flutter/data/models/entities.dart';
|
||||
import 'package:invoiceninja_flutter/ui/app/form_card.dart';
|
||||
import 'package:invoiceninja_flutter/ui/app/forms/custom_field.dart';
|
||||
import 'package:invoiceninja_flutter/ui/app/forms/decorated_form_field.dart';
|
||||
import 'package:invoiceninja_flutter/ui/vendor/edit/vendor_edit_vm.dart';
|
||||
import 'package:invoiceninja_flutter/utils/localization.dart';
|
||||
import 'package:invoiceninja_flutter/ui/app/form_card.dart';
|
||||
|
||||
class VendorEditDetails extends StatefulWidget {
|
||||
const VendorEditDetails({
|
||||
|
|
@ -95,44 +96,29 @@ class VendorEditDetailsState extends State<VendorEditDetails> {
|
|||
children: <Widget>[
|
||||
FormCard(
|
||||
children: <Widget>[
|
||||
TextFormField(
|
||||
autocorrect: false,
|
||||
DecoratedFormField(
|
||||
controller: _nameController,
|
||||
decoration: InputDecoration(
|
||||
labelText: localization.name,
|
||||
),
|
||||
label: localization.name,
|
||||
validator: (String val) => val == null || val.isEmpty
|
||||
? AppLocalization.of(context).pleaseEnterAName
|
||||
: null,
|
||||
),
|
||||
TextFormField(
|
||||
autocorrect: false,
|
||||
DecoratedFormField(
|
||||
controller: _idNumberController,
|
||||
decoration: InputDecoration(
|
||||
labelText: localization.idNumber,
|
||||
),
|
||||
label: localization.idNumber,
|
||||
),
|
||||
TextFormField(
|
||||
autocorrect: false,
|
||||
DecoratedFormField(
|
||||
controller: _vatNumberController,
|
||||
decoration: InputDecoration(
|
||||
labelText: localization.vatNumber,
|
||||
),
|
||||
label: localization.vatNumber,
|
||||
),
|
||||
TextFormField(
|
||||
autocorrect: false,
|
||||
DecoratedFormField(
|
||||
controller: _websiteController,
|
||||
decoration: InputDecoration(
|
||||
labelText: localization.website,
|
||||
),
|
||||
label: localization.website,
|
||||
keyboardType: TextInputType.url,
|
||||
),
|
||||
TextFormField(
|
||||
autocorrect: false,
|
||||
DecoratedFormField(
|
||||
controller: _phoneController,
|
||||
decoration: InputDecoration(
|
||||
labelText: localization.phone,
|
||||
),
|
||||
label: localization.phone,
|
||||
keyboardType: TextInputType.phone,
|
||||
),
|
||||
CustomField(
|
||||
|
|
|
|||
|
|
@ -1,18 +1,20 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_redux/flutter_redux.dart';
|
||||
import 'package:invoiceninja_flutter/data/models/models.dart';
|
||||
import 'package:invoiceninja_flutter/data/models/vendor_model.dart';
|
||||
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
||||
import 'package:invoiceninja_flutter/redux/ui/ui_actions.dart';
|
||||
import 'package:invoiceninja_flutter/redux/vendor/vendor_actions.dart';
|
||||
import 'package:invoiceninja_flutter/ui/app/dialogs/error_dialog.dart';
|
||||
import 'package:invoiceninja_flutter/ui/vendor/edit/vendor_edit.dart';
|
||||
import 'package:invoiceninja_flutter/ui/vendor/vendor_screen.dart';
|
||||
import 'package:invoiceninja_flutter/ui/vendor/view/vendor_view_vm.dart';
|
||||
import 'package:invoiceninja_flutter/utils/localization.dart';
|
||||
import 'package:invoiceninja_flutter/utils/platforms.dart';
|
||||
import 'package:redux/redux.dart';
|
||||
import 'package:invoiceninja_flutter/data/models/models.dart';
|
||||
import 'package:invoiceninja_flutter/ui/app/dialogs/error_dialog.dart';
|
||||
import 'package:invoiceninja_flutter/ui/vendor/view/vendor_view_vm.dart';
|
||||
import 'package:invoiceninja_flutter/redux/vendor/vendor_actions.dart';
|
||||
import 'package:invoiceninja_flutter/data/models/vendor_model.dart';
|
||||
import 'package:invoiceninja_flutter/ui/vendor/edit/vendor_edit.dart';
|
||||
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
||||
|
||||
class VendorEditScreen extends StatelessWidget {
|
||||
const VendorEditScreen({Key key}) : super(key: key);
|
||||
|
|
@ -77,6 +79,15 @@ class VendorEditVM {
|
|||
}
|
||||
},
|
||||
onSavePressed: (BuildContext context) {
|
||||
if (!vendor.hasNameSet) {
|
||||
showDialog<ErrorDialog>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return ErrorDialog(
|
||||
AppLocalization.of(context).pleaseEnterAName);
|
||||
});
|
||||
return null;
|
||||
}
|
||||
final Completer<VendorEntity> completer = new Completer<VendorEntity>();
|
||||
store.dispatch(SaveVendorRequest(completer: completer, vendor: vendor));
|
||||
return completer.future.then((savedVendor) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
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('Vendor Tests', () {
|
||||
TestLocalization localization;
|
||||
FlutterDriver driver;
|
||||
|
||||
final name = makeUnique(faker.company.name());
|
||||
|
||||
final updatedName = makeUnique(faker.company.name());
|
||||
|
||||
setUpAll(() async {
|
||||
localization = TestLocalization('en');
|
||||
driver = await FlutterDriver.connect();
|
||||
|
||||
print('Login to app');
|
||||
await login(driver, retype: batchMode);
|
||||
|
||||
print('View vendors');
|
||||
viewSection(driver: driver, name: localization.vendors);
|
||||
});
|
||||
|
||||
tearDownAll(() async {
|
||||
await logout(driver, localization);
|
||||
|
||||
if (driver != null) {
|
||||
driver.close();
|
||||
}
|
||||
});
|
||||
|
||||
// Create an empty vendor
|
||||
test('Try to add an empty vendor', () async {
|
||||
print('Tap new vendor');
|
||||
await driver.tap(find.byTooltip(localization.newVendor));
|
||||
|
||||
print('Tap save');
|
||||
await driver.tap(find.text(localization.save));
|
||||
|
||||
print('Check for error');
|
||||
await driver.waitFor(find.text(localization.pleaseEnterAName));
|
||||
|
||||
if (await isMobile(driver)) {
|
||||
print('Click back');
|
||||
await driver.tap(find.pageBack());
|
||||
await driver.waitFor(find.byTooltip(localization.newVendor));
|
||||
} else {
|
||||
print('Click cancel');
|
||||
await driver.tap(find.text(localization.cancel));
|
||||
}
|
||||
});
|
||||
|
||||
// Create a new vendor
|
||||
test('Add a new vendor', () async {
|
||||
print('Tap new vendor');
|
||||
await driver.tap(find.byTooltip(localization.newVendor));
|
||||
|
||||
print('Fill form: $name');
|
||||
await fillAndSaveForm(driver, <String, dynamic>{
|
||||
localization.name: name,
|
||||
});
|
||||
print('Form filled');
|
||||
|
||||
if (await isMobile(driver)) {
|
||||
print('Click back');
|
||||
await driver.tap(find.pageBack());
|
||||
await driver.waitFor(find.byTooltip(localization.newVendor));
|
||||
}
|
||||
});
|
||||
|
||||
// Edit the newly created vendor
|
||||
test('Edit an existing vendor', () async {
|
||||
if (await isMobile(driver)) {
|
||||
print('Select vendor: $name');
|
||||
await driver.scrollUntilVisible(
|
||||
find.byType('ListView'), find.text(name),
|
||||
dyScroll: -300);
|
||||
await driver.tap(find.text(name));
|
||||
}
|
||||
|
||||
print('Tap edit');
|
||||
await driver.tap(find.text(localization.edit));
|
||||
|
||||
await fillAndSaveForm(driver, <String, String>{
|
||||
localization.name: updatedName,
|
||||
});
|
||||
});
|
||||
|
||||
// Archive the edited vendor
|
||||
test('Archieve/delete vendor test', () async {
|
||||
await testArchiveAndDelete(
|
||||
driver: driver,
|
||||
archivedMessage: localization.archivedVendor,
|
||||
deletedMessage: localization.deletedVendor,
|
||||
restoredMessage: localization.restoredVendor);
|
||||
|
||||
if (await isMobile(driver)) {
|
||||
await driver.tap(find.pageBack());
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
Loading…
Reference in New Issue