forked from SatoshiPortal/bullbitcoin-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfiat_settlement_editor_screen_test.dart
More file actions
157 lines (138 loc) · 5.53 KB
/
Copy pathfiat_settlement_editor_screen_test.dart
File metadata and controls
157 lines (138 loc) · 5.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import 'dart:async';
import 'package:bb_mobile/core/themes/app_theme.dart';
import 'package:bb_mobile/core/utils/result.dart';
import 'package:bb_mobile/features/fiat_settlement/public/fiat_settlement_facade.dart';
import 'package:bb_mobile/features/fiat_settlement/ui/screens/fiat_settlement_editor_screen.dart';
import 'package:bb_mobile/generated/l10n/localization.dart';
import 'package:bb_mobile/locator.dart';
import 'package:bb_mobile/core/widgets/loading/loading_box_content.dart';
import 'package:bull_ui/bull_ui.dart' show BullButton;
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
Finder _button(String label) =>
find.byWidgetPredicate((w) => w is BullButton && w.label == label);
class _MockFacade extends Mock implements FiatSettlementFacade {}
FiatSettlementConfigurationView _view(
FiatSettlementProduct product,
int pct, {
FiatCurrency? currency,
}) {
return FiatSettlementConfigurationView(
products: [
FiatSettlementProductConfig(
product: product,
fiatPercentage: pct,
currency: currency,
),
],
credentialActive: true,
);
}
void main() {
late _MockFacade facade;
const product = FiatSettlementProduct.paymentPage;
setUpAll(() {
registerFallbackValue(FiatSettlementProduct.invoice);
registerFallbackValue(FiatCurrency.cad);
});
setUp(() {
facade = _MockFacade();
if (locator.isRegistered<FiatSettlementFacade>()) {
locator.unregister<FiatSettlementFacade>();
}
locator.registerFactory<FiatSettlementFacade>(() => facade);
});
tearDown(() {
if (locator.isRegistered<FiatSettlementFacade>()) {
locator.unregister<FiatSettlementFacade>();
}
});
Future<void> pump(WidgetTester tester) async {
// A tall surface so the whole scrolling form (incl. the bottom action
// button) is laid out and findable without scrolling.
await tester.binding.setSurfaceSize(const Size(1080, 3200));
addTearDown(() => tester.binding.setSurfaceSize(null));
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.themeData(AppThemeType.light),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
locale: const Locale('en'),
home: const FiatSettlementEditorScreen(product: product),
),
);
// Let load() (two awaited reads) complete and the form settle.
await tester.pumpAndSettle();
}
testWidgets('a saved active split renders AND is savable — no local account '
'gate, no login panel, no standalone reconnect', (tester) async {
// There is no exchange-login concept in the editor anymore: the saved
// split shows, and Save is offered directly (a keyless npm-signed save).
when(() => facade.configuration()).thenAnswer(
(_) async => Ok(_view(product, 50, currency: FiatCurrency.cad)),
);
await pump(tester);
// The saved split is displayed — the mix chooser option is present.
expect(find.text('A mix of Bitcoin and fiat'), findsOneWidget);
// Save is offered directly; the old pre-gate reconnect/login panel is gone.
expect(_button('Save'), findsOneWidget);
expect(_button('Reconnect Bull Bitcoin'), findsNothing);
expect(_button('Log in to Bull Bitcoin'), findsNothing);
expect(tester.takeException(), isNull);
});
testWidgets('a server credential-required outcome surfaces the Reconnect '
'action (the only path that needs the exchange login)', (tester) async {
when(() => facade.configuration()).thenAnswer(
(_) async => Ok(_view(product, 50, currency: FiatCurrency.cad)),
);
// The keyless save is rejected by the server for want of a stored key.
when(
() => facade.set(
product: any(named: 'product'),
fiatPercentage: any(named: 'fiatPercentage'),
currency: any(named: 'currency'),
),
).thenAnswer(
(_) async => const Err(FiatSettlementFailure.credentialProblem()),
);
await pump(tester);
await tester.tap(_button('Save'));
await tester.pumpAndSettle();
// Reconnect appears ONLY now, as the outcome of the server's answer.
expect(_button('Reconnect Bull Bitcoin'), findsOneWidget);
expect(tester.takeException(), isNull);
});
testWidgets('the wait for the server config is named, in the app\'s own '
'loading treatment', (tester) async {
final answer =
Completer<
Result<FiatSettlementConfigurationView, FiatSettlementFailure>
>();
when(() => facade.configuration()).thenAnswer((_) => answer.future);
await tester.binding.setSurfaceSize(const Size(1080, 3200));
addTearDown(() => tester.binding.setSurfaceSize(null));
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.themeData(AppThemeType.light),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
locale: const Locale('en'),
home: const FiatSettlementEditorScreen(
product: product,
activated: true,
),
),
);
await tester.pump();
// Post-activation, this read is the whole wait before the chooser appears.
expect(
find.text('Checking your current payout settings with Bull Bitcoin...'),
findsOneWidget,
);
expect(find.byType(LoadingBoxContent), findsOneWidget);
expect(find.byType(CircularProgressIndicator), findsNothing);
answer.complete(Ok(_view(product, 0)));
await tester.pumpAndSettle();
});
}