From c77b776d599192f5842b7391deff75ff45f9e7bc Mon Sep 17 00:00:00 2001 From: poka Date: Tue, 27 Apr 2021 04:09:20 +0200 Subject: [PATCH] All onboarding workflow is tested; normalize input mnemonic word to nfkd, no unaccentued anymore --- lib/models/generateWallets.dart | 28 +++------ lib/models/home.dart | 2 +- lib/screens/myWallets/walletsHome.dart | 1 + lib/screens/onBoarding/11.dart | 1 + lib/screens/onBoarding/7.dart | 2 + lib/screens/onBoarding/8.dart | 2 + lib/screens/onBoarding/9.dart | 2 +- pubspec.lock | 7 +++ pubspec.yaml | 1 + test_driver/app_test.dart | 86 +++++++++++++++++++++++++- 10 files changed, 109 insertions(+), 23 deletions(-) diff --git a/lib/models/generateWallets.dart b/lib/models/generateWallets.dart index 3a42498..19e13d9 100644 --- a/lib/models/generateWallets.dart +++ b/lib/models/generateWallets.dart @@ -1,4 +1,3 @@ -import 'dart:convert'; import 'dart:io'; import 'dart:math'; import 'dart:typed_data'; @@ -10,6 +9,7 @@ import 'package:gecko/globals.dart'; import 'package:pdf/pdf.dart'; import 'package:pdf/widgets.dart' as pw; import 'package:printing/printing.dart'; +import "package:unorm_dart/unorm_dart.dart" as unorm; class GenerateWalletsProvider with ChangeNotifier { GenerateWalletsProvider(); @@ -74,26 +74,14 @@ class GenerateWalletsProvider with ChangeNotifier { return _name; } - void checkAskedWord(String value, String _mnemo) { - // nbrWord = getRandomInt(); + void checkAskedWord(String inputWord, String _mnemo) { + final expectedWord = _mnemo.split(' ')[nbrWord]; + final normInputWord = unorm.nfkd(inputWord); - final runesAsked = _mnemo.split(' ')[nbrWord].runes; - List runesAskedUnaccent = []; - for (int i in runesAsked) { - if (i == 768 || i == 769 || i == 770 || i == 771) { - continue; - } else { - runesAskedUnaccent.add(i); - } - } - final String unaccentedAskedWord = - utf8.decode(runesAskedUnaccent).toLowerCase(); - final String unaccentedInputWord = removeDiacritics(value).toLowerCase(); - - log.i("Is $unaccentedAskedWord equal to input $unaccentedInputWord ?"); - if (unaccentedAskedWord == unaccentedInputWord || - value == 'triche' || - value == '3.14') { + log.i("Is $expectedWord equal to input $normInputWord ?"); + if (expectedWord == normInputWord || + inputWord == 'triche' || + inputWord == '3.14') { log.d('Word is OK'); isAskedWordValid = true; askedWordColor = Colors.green[600]; diff --git a/lib/models/home.dart b/lib/models/home.dart index 0338ded..63fc715 100644 --- a/lib/models/home.dart +++ b/lib/models/home.dart @@ -52,7 +52,7 @@ class HomeProvider with ChangeNotifier { int _statusCode = 0; final _client = new HttpClient(); - _client.connectionTimeout = const Duration(milliseconds: 800); + _client.connectionTimeout = const Duration(milliseconds: 1000); do { i++; diff --git a/lib/screens/myWallets/walletsHome.dart b/lib/screens/myWallets/walletsHome.dart index 6987a2c..99e48df 100644 --- a/lib/screens/myWallets/walletsHome.dart +++ b/lib/screens/myWallets/walletsHome.dart @@ -52,6 +52,7 @@ class WalletsHome extends StatelessWidget { ); }), title: Text('Mes portefeuilles', + key: Key('myWallets'), style: TextStyle(color: Colors.grey[850])), backgroundColor: Color(0xffFFD58D), ), diff --git a/lib/screens/onBoarding/11.dart b/lib/screens/onBoarding/11.dart index f622416..f4e1c55 100644 --- a/lib/screens/onBoarding/11.dart +++ b/lib/screens/onBoarding/11.dart @@ -55,6 +55,7 @@ class OnboardingStepThirteen extends StatelessWidget { alignment: Alignment.centerRight, children: [ TextField( + key: Key('generatedPin'), enabled: false, controller: _generateWalletProvider.pin, maxLines: 1, diff --git a/lib/screens/onBoarding/7.dart b/lib/screens/onBoarding/7.dart index 3d685d1..c64def2 100644 --- a/lib/screens/onBoarding/7.dart +++ b/lib/screens/onBoarding/7.dart @@ -126,6 +126,7 @@ Widget sentanceArray(BuildContext context) { '12:...', ], builder: (context, formatedArray) { + // print(formatedArray.data); return Container( padding: EdgeInsets.symmetric(horizontal: 12), child: Container( @@ -173,6 +174,7 @@ Widget arrayCell(dataWord) { Text(dataWord.split(':')[0], style: TextStyle(fontSize: 14)), SizedBox(height: 2), Text(dataWord.split(':')[1], + key: Key('word${dataWord.split(':')[0]}'), style: TextStyle(fontSize: 19, color: Colors.black)), ])); } diff --git a/lib/screens/onBoarding/8.dart b/lib/screens/onBoarding/8.dart index e740527..c98efbd 100644 --- a/lib/screens/onBoarding/8.dart +++ b/lib/screens/onBoarding/8.dart @@ -108,6 +108,7 @@ class OnboardingStepTen extends StatelessWidget { SizedBox(height: isTall ? 70 : 10), if (isTall) Text('${_generateWalletProvider.nbrWord + 1}', + key: Key('askedWord'), style: TextStyle( fontSize: 17, color: Color(0xffD28928), @@ -122,6 +123,7 @@ class OnboardingStepTen extends StatelessWidget { )), width: 430, child: TextFormField( + key: Key('inputWord'), autofocus: true, enabled: !_generateWalletProvider.isAskedWordValid, controller: this.wordController, diff --git a/lib/screens/onBoarding/9.dart b/lib/screens/onBoarding/9.dart index 3c0a876..22e67c9 100644 --- a/lib/screens/onBoarding/9.dart +++ b/lib/screens/onBoarding/9.dart @@ -30,7 +30,7 @@ class OnboardingStepEleven extends StatelessWidget { text: " \n\nVotre code secret chiffre votre trousseau de clefs, ce qui le rend inutilisable par d’autres, par exemple si vous perdez votre téléphone ou si on vous le vole."), ], - textKey: Key('step8'), + textKey: Key('step9'), ), SizedBox(height: isTall ? 50 : 10), Image.asset( diff --git a/pubspec.lock b/pubspec.lock index 8c8924d..7ff5c63 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -899,6 +899,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.0" + unorm_dart: + dependency: "direct main" + description: + name: unorm_dart + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.0" uuid: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 5c6eeb0..709ee97 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -50,6 +50,7 @@ dependencies: flutter_driver: sdk: flutter test: ^1.16.6 + unorm_dart: ^0.2.0 flutter_icons: android: "ic_launcher" diff --git a/test_driver/app_test.dart b/test_driver/app_test.dart index a1c30e8..e217d0a 100644 --- a/test_driver/app_test.dart +++ b/test_driver/app_test.dart @@ -1,4 +1,6 @@ // Imports the Flutter Driver API. +import 'dart:async'; + import 'package:flutter_driver/flutter_driver.dart'; // import 'package:flutter_test/flutter_test.dart'; import 'package:test/test.dart'; @@ -60,15 +62,97 @@ void main() { "J’ai généré votre phrase de restauration !\nTâchez de la garder bien secrète, car elle permet à quiconque la connaît d’accéder à tous vos portefeuilles."); }); - test('OnBoarding - Generate sentance', ( + test('OnBoarding - Generate sentance and confirme it', ( {timeout: const Duration(seconds: 5)}) async { await driver.tap(find.byValueKey('goStep7')); + print('THE SECOND WORD IS:'); + + while (await driver.getText(find.byValueKey( + 'word1', + )) == + '...') { + print('Waiting for Mnemonic generation...'); + await Future.delayed(const Duration(seconds: 1)); + } + + List words = [for (var i = 1; i <= 13; i += 1) i]; + + for (var j = 1; j < 13; j++) { + words[j] = await driver.getText(find.byValueKey( + 'word$j', + )); + } + + // print word 1, 2 and 12 + // print(words[1] + words[2] + words[12]); + expect( await driver.getText(find.byValueKey( 'step7', )), "C'est le moment de noter votre phrase !"); + + await driver.tap(find.byValueKey('goStep8')); + + final String goodWord = words[int.parse( + await driver.getText( + find.byValueKey( + 'askedWord', + ), + ), + )]; + + await driver.enterText(goodWord); + + await driver.tap(find.byValueKey('goStep9')); + }); + test('OnBoarding - Generate secret code and confirm it', ( + {timeout: const Duration(seconds: 5)}) async { + expect( + await driver.getText(find.byValueKey( + 'step9', + )), + "Super !\n\nJe vais maintenant créer votre code secret. \n\nVotre code secret chiffre votre trousseau de clefs, ce qui le rend inutilisable par d’autres, par exemple si vous perdez votre téléphone ou si on vous le vole."); + + await driver.tap(find.byValueKey('goStep10')); + await driver.tap(find.byValueKey('goStep11')); + + while (await driver.getText(find.byValueKey( + 'generatedPin', + )) == + '') { + print('Waiting for pin code generation...'); + await Future.delayed(const Duration(seconds: 1)); + } + + final pinCode = await driver.getText( + find.byValueKey( + 'generatedPin', + ), + ); + + await driver.tap(find.byValueKey('goStep12')); + await Future.delayed(const Duration(seconds: 1)); + + await driver.enterText(pinCode); + + expect( + await driver.getText(find.byValueKey( + 'step13', + )), + "Top !\n\nVotre trousseau de clef et votre portefeuille ont été créés avec un immense succès.\n\nFélicitations !"); + }); + + test('OnBoarding - Create a derivation and display it', ( + {timeout: const Duration(seconds: 5)}) async { + await driver.tap(find.byValueKey('goWalletHome')); + + expect( + await driver.getText(find.byValueKey( + 'myWallets', + )), + "Mes portefeuilles"); }); }); }