Skip to content

Commit

Permalink
[Parent] Account creation error for no self reg/generic (#992)
Browse files Browse the repository at this point in the history
* [Parent] Account  creation error for no self  reg/generic

* added a test for new error case
  • Loading branch information
TrevorNeedham authored Sep 16, 2020
1 parent 1473f7b commit 2b962ab
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
3 changes: 3 additions & 0 deletions apps/flutter_parent/lib/l10n/app_localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,9 @@ class AppLocalizations {

String get errorPairingFailed => Intl.message('Your code is incorrect or expired.');

String get errorGenericPairingFailed => Intl.message(
'Something went wrong trying to create your account, please reach out to your school for assistance.');

String get qrCode => Intl.message('QR Code');

String get qrCodeDescription =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,11 @@ class _AccountCreationScreenState extends State<AccountCreationScreen> {
}

_handleDioError(DioError e) {
String emailError = '';
String pairingError = '';
try {
String emailError = e.response.data['errors']['user']['pseudonyms'][0]['message'];
if (emailError != null && emailError.isNotEmpty) {
emailError = e.response.data['errors']['user']['pseudonyms'][0]['message'];
if (emailError.isNotEmpty) {
setState(() {
_emailErrorText = _validateEmail('', apiError: true);
});
Expand All @@ -455,14 +457,21 @@ class _AccountCreationScreenState extends State<AccountCreationScreen> {
}

try {
String pairingError = e.response.data['errors']['pairing_code']['code'][0]['message'];
if (pairingError != null && pairingError.isNotEmpty) {
pairingError = e.response.data['errors']['pairing_code']['code'][0]['message'];
if (pairingError.isNotEmpty) {
_scaffoldKey.currentState.showSnackBar(
SnackBar(content: Text(L10n(context).errorPairingFailed)),
);
}
} catch (e) {
// If we catch it means the error isn't present
}

if (pairingError.isEmpty && emailError.isEmpty) {
// Show generic error case
_scaffoldKey.currentState.showSnackBar(
SnackBar(content: Text(L10n(context).errorGenericPairingFailed)),
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -404,4 +404,36 @@ void main() {
));
}, a11yExclusions: {A11yExclusion.minTapSize});
});

testWidgetsWithAccessibilityChecks('account creation with error shows generic error message', (tester) async {
when(interactor.getToSForAccount('123', 'hodor.com')).thenAnswer((_) async => tos);
when(interactor.createNewAccount('123', '123', 'hodor', '[email protected]', '12345678', 'hodor.com'))
.thenThrow(DioError(response: Response()));

await tester.pumpWidget(TestApp(AccountCreationScreen(pairingInfo)));
await tester.pumpAndSettle();

await tester.enterText(find.widgetWithText(TextFormField, 'Full Name…'), 'hodor');
await tester.enterText(find.widgetWithText(TextFormField, 'Email…'), '[email protected]');
await tester.enterText(find.widgetWithText(TextFormField, 'Password…'), '12345678');

await tester.drag(find.byType(Scaffold), Offset(0, -500));

await tester.pumpAndSettle();

await tester.tap(find.byType(RaisedButton));

await tester.pump();
await tester.pump();
await tester.pump();

expect(
find.text(
'Something went wrong trying to create your account, please reach out to your school for assistance.'),
findsOneWidget);
verify(analytics.logEvent(
AnalyticsEventConstants.QR_ACCOUNT_FAILURE,
extras: {AnalyticsParamConstants.DOMAIN_PARAM: 'hodor.com'},
));
}, a11yExclusions: {A11yExclusion.minTapSize});
}

0 comments on commit 2b962ab

Please sign in to comment.