mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-22 19:39:22 +00:00
fixed tests for randomized pin
This commit is contained in:
parent
b5dff2f88b
commit
dc135597e6
1 changed files with 224 additions and 3 deletions
|
@ -7,9 +7,12 @@ import 'package:stackwallet/widgets/custom_pin_put/custom_pin_put.dart';
|
|||
import 'package:stackwallet/widgets/custom_pin_put/pin_keyboard.dart';
|
||||
|
||||
void main() {
|
||||
group("CustomPinPut tests", () {
|
||||
group("CustomPinPut tests, non-random PIN", () {
|
||||
testWidgets("CustomPinPut with 4 fields builds correctly", (tester) async {
|
||||
const pinPut = CustomPinPut(fieldsCount: 4);
|
||||
const pinPut = CustomPinPut(
|
||||
fieldsCount: 4,
|
||||
isRandom: false,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
|
@ -35,8 +38,12 @@ void main() {
|
|||
bool submittedPinMatches = false;
|
||||
final pinPut = CustomPinPut(
|
||||
fieldsCount: 4,
|
||||
onSubmit: (pin) => submittedPinMatches = pin == "1234",
|
||||
onSubmit: (pin) {
|
||||
submittedPinMatches = pin == "1234";
|
||||
print("pin entered: $pin");
|
||||
},
|
||||
useNativeKeyboard: false,
|
||||
isRandom: false,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
|
@ -69,6 +76,8 @@ void main() {
|
|||
await tester.tap(find.byWidgetPredicate(
|
||||
(widget) => widget is NumberKey && widget.number == "4"));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byType(SubmitKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(submittedPinMatches, true);
|
||||
});
|
||||
|
@ -79,6 +88,7 @@ void main() {
|
|||
fieldsCount: 4,
|
||||
pinAnimationType: PinAnimationType.fade,
|
||||
controller: controller,
|
||||
isRandom: false,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
|
@ -110,6 +120,7 @@ void main() {
|
|||
fieldsCount: 4,
|
||||
pinAnimationType: PinAnimationType.scale,
|
||||
controller: controller,
|
||||
isRandom: false,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
|
@ -141,6 +152,7 @@ void main() {
|
|||
fieldsCount: 4,
|
||||
pinAnimationType: PinAnimationType.rotation,
|
||||
controller: controller,
|
||||
isRandom: false,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
|
@ -172,6 +184,215 @@ void main() {
|
|||
onNumberKeyPressed: (_) {},
|
||||
onBackPressed: () {},
|
||||
onSubmitPressed: () {},
|
||||
isRandom: false,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(
|
||||
extensions: [
|
||||
StackColors.fromStackColorTheme(LightColors()),
|
||||
],
|
||||
),
|
||||
home: Material(
|
||||
child: keyboard,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(BackspaceKey), findsOneWidget);
|
||||
expect(find.byType(NumberKey), findsNWidgets(10));
|
||||
expect(find.text("0"), findsOneWidget);
|
||||
expect(find.text("1"), findsOneWidget);
|
||||
expect(find.text("2"), findsOneWidget);
|
||||
expect(find.text("3"), findsOneWidget);
|
||||
expect(find.text("4"), findsOneWidget);
|
||||
expect(find.text("5"), findsOneWidget);
|
||||
expect(find.text("6"), findsOneWidget);
|
||||
expect(find.text("7"), findsOneWidget);
|
||||
expect(find.text("8"), findsOneWidget);
|
||||
expect(find.text("9"), findsOneWidget);
|
||||
expect(find.byType(SvgPicture), findsOneWidget);
|
||||
});
|
||||
|
||||
group("CustomPinPut tests, with random PIN", () {
|
||||
testWidgets("CustomPinPut with 4 fields builds correctly", (tester) async {
|
||||
const pinPut = CustomPinPut(
|
||||
fieldsCount: 4,
|
||||
isRandom: true,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(
|
||||
extensions: [
|
||||
StackColors.fromStackColorTheme(LightColors()),
|
||||
],
|
||||
),
|
||||
home: const Material(
|
||||
child: pinPut,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// expects 5 here. Four + the actual text field text
|
||||
expect(find.text(""), findsNWidgets(5));
|
||||
expect(find.byType(PinKeyboard), findsOneWidget);
|
||||
expect(find.byType(BackspaceKey), findsOneWidget);
|
||||
expect(find.byType(NumberKey), findsNWidgets(10));
|
||||
});
|
||||
|
||||
testWidgets("CustomPinPut entering a pin successfully", (tester) async {
|
||||
bool submittedPinMatches = false;
|
||||
final pinPut = CustomPinPut(
|
||||
fieldsCount: 4,
|
||||
onSubmit: (pin) {
|
||||
submittedPinMatches = pin == "1234";
|
||||
print("pin entered: $pin");
|
||||
},
|
||||
useNativeKeyboard: false,
|
||||
isRandom: true,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(
|
||||
extensions: [
|
||||
StackColors.fromStackColorTheme(LightColors()),
|
||||
],
|
||||
),
|
||||
home: Material(
|
||||
child: pinPut,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.byWidgetPredicate(
|
||||
(widget) => widget is NumberKey && widget.number == "1"));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byWidgetPredicate(
|
||||
(widget) => widget is NumberKey && widget.number == "2"));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byWidgetPredicate(
|
||||
(widget) => widget is NumberKey && widget.number == "6"));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byType(BackspaceKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byWidgetPredicate(
|
||||
(widget) => widget is NumberKey && widget.number == "3"));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byWidgetPredicate(
|
||||
(widget) => widget is NumberKey && widget.number == "4"));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byType(SubmitKey));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(submittedPinMatches, true);
|
||||
});
|
||||
|
||||
testWidgets("CustomPinPut pin enter fade animation", (tester) async {
|
||||
final controller = TextEditingController();
|
||||
final pinPut = CustomPinPut(
|
||||
fieldsCount: 4,
|
||||
pinAnimationType: PinAnimationType.fade,
|
||||
controller: controller,
|
||||
isRandom: true,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(
|
||||
extensions: [
|
||||
StackColors.fromStackColorTheme(LightColors()),
|
||||
],
|
||||
),
|
||||
home: Material(
|
||||
child: pinPut,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.byWidgetPredicate(
|
||||
(widget) => widget is NumberKey && widget.number == "1"));
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.text, "1");
|
||||
|
||||
await tester.tap(find.byType(BackspaceKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.text, "");
|
||||
});
|
||||
|
||||
testWidgets("CustomPinPut pin enter scale animation", (tester) async {
|
||||
final controller = TextEditingController();
|
||||
final pinPut = CustomPinPut(
|
||||
fieldsCount: 4,
|
||||
pinAnimationType: PinAnimationType.scale,
|
||||
controller: controller,
|
||||
isRandom: true,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(
|
||||
extensions: [
|
||||
StackColors.fromStackColorTheme(LightColors()),
|
||||
],
|
||||
),
|
||||
home: Material(
|
||||
child: pinPut,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.byWidgetPredicate(
|
||||
(widget) => widget is NumberKey && widget.number == "1"));
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.text, "1");
|
||||
|
||||
await tester.tap(find.byType(BackspaceKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.text, "");
|
||||
});
|
||||
|
||||
testWidgets("CustomPinPut pin enter rotate animation", (tester) async {
|
||||
final controller = TextEditingController();
|
||||
final pinPut = CustomPinPut(
|
||||
fieldsCount: 4,
|
||||
pinAnimationType: PinAnimationType.rotation,
|
||||
controller: controller,
|
||||
isRandom: true,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: ThemeData(
|
||||
extensions: [
|
||||
StackColors.fromStackColorTheme(LightColors()),
|
||||
],
|
||||
),
|
||||
home: Material(
|
||||
child: pinPut,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.byWidgetPredicate(
|
||||
(widget) => widget is NumberKey && widget.number == "1"));
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.text, "1");
|
||||
|
||||
await tester.tap(find.byType(BackspaceKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(controller.text, "");
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets("PinKeyboard builds correctly", (tester) async {
|
||||
final keyboard = PinKeyboard(
|
||||
onNumberKeyPressed: (_) {},
|
||||
onBackPressed: () {},
|
||||
onSubmitPressed: () {},
|
||||
isRandom: true,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
|
|
Loading…
Reference in a new issue