All onboarding workflow is tested; normalize input mnemonic word to nfkd, no unaccentued anymore

This commit is contained in:
poka 2021-04-27 04:09:20 +02:00
parent 900cfbac9b
commit c77b776d59
10 changed files with 109 additions and 23 deletions

View File

@ -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<int> 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];

View File

@ -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++;

View File

@ -52,6 +52,7 @@ class WalletsHome extends StatelessWidget {
);
}),
title: Text('Mes portefeuilles',
key: Key('myWallets'),
style: TextStyle(color: Colors.grey[850])),
backgroundColor: Color(0xffFFD58D),
),

View File

@ -55,6 +55,7 @@ class OnboardingStepThirteen extends StatelessWidget {
alignment: Alignment.centerRight,
children: <Widget>[
TextField(
key: Key('generatedPin'),
enabled: false,
controller: _generateWalletProvider.pin,
maxLines: 1,

View File

@ -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)),
]));
}

View File

@ -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,

View File

@ -30,7 +30,7 @@ class OnboardingStepEleven extends StatelessWidget {
text:
" \n\nVotre code secret chiffre votre trousseau de clefs, ce qui le rend inutilisable par dautres, 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(

View File

@ -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:

View File

@ -50,6 +50,7 @@ dependencies:
flutter_driver:
sdk: flutter
test: ^1.16.6
unorm_dart: ^0.2.0
flutter_icons:
android: "ic_launcher"

View File

@ -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() {
"Jai généré votre phrase de restauration !\nTâchez de la garder bien secrète, car elle permet à quiconque la connaît daccé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 dautres, 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");
});
});
}