Skip to content

Commit

Permalink
fix(app-test): workaround for fake GoRouter which cant navigate
Browse files Browse the repository at this point in the history
We can't navigate using the mocked router (I don't understand why). Which means, we can't navigate to the new channel configuration flow.
Because of this, I've split up the tests into more fine granular tests. We test now each widget separately.
This has the advantage that our tests are smaller and easier to understand.
It seems like that if we want to test navigation, we should write integration tests instead.
  • Loading branch information
bonomat committed May 22, 2024
1 parent 8644cb8 commit ef42084
Show file tree
Hide file tree
Showing 5 changed files with 352 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ class _ChannelConfiguration extends State<ChannelConfiguration> {
mainAxisAlignment: MainAxisAlignment.start,
children: [
Checkbox(
key: tradeScreenBottomSheetChannelConfigurationFundWithWalletCheckBox,
value: useInnerWallet,
onChanged: fundWithWalletEnabled
? (bool? value) {
Expand Down Expand Up @@ -442,6 +443,7 @@ class _ChannelConfiguration extends State<ChannelConfiguration> {
child: Padding(
padding: const EdgeInsets.only(top: 1, left: 8, right: 8, bottom: 8),
child: ConfirmationSlider(
key: tradeScreenBottomSheetChannelConfigurationConfirmSlider,
text: "Swipe to confirm ${widget.tradeValues.direction.nameU}",
textStyle: TextStyle(color: confirmationSliderColor),
height: 40,
Expand Down
4 changes: 4 additions & 0 deletions mobile/lib/features/trade/trade_bottom_sheet_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import 'package:get_10101/features/trade/submit_order_change_notifier.dart';
import 'package:get_10101/features/trade/trade_bottom_sheet_confirmation.dart';
import 'package:get_10101/features/trade/trade_theme.dart';
import 'package:get_10101/features/trade/trade_value_change_notifier.dart';
import 'package:get_10101/util/constants.dart';
import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';

Expand Down Expand Up @@ -231,6 +232,7 @@ class _TradeBottomSheetTabState extends State<TradeBottomSheetTab>
selector: (_, provider) => provider.fromDirection(direction).price ?? 0,
builder: (context, price, child) {
return UsdTextField(
key: tradeButtonSheetMarketPrice,
value: Usd.fromDouble(price),
label: "Market Price (USD)",
);
Expand All @@ -240,6 +242,7 @@ class _TradeBottomSheetTabState extends State<TradeBottomSheetTab>
children: [
Flexible(
child: AmountInputField(
key: tradeButtonSheetQuantityInput,
controller: quantityController,
suffixIcon: TextButton(
onPressed: () {
Expand Down Expand Up @@ -302,6 +305,7 @@ class _TradeBottomSheetTabState extends State<TradeBottomSheetTab>
provider.fromDirection(direction).margin ?? Amount.zero(),
builder: (context, margin, child) {
return AmountTextField(
key: tradeButtonSheetMarginField,
value: margin,
label: "Margin (sats)",
);
Expand Down
7 changes: 6 additions & 1 deletion mobile/lib/features/trade/trade_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class TradeScreen extends StatelessWidget {
return provider.getAskPrice();
}, builder: (context, price, child) {
return LatestPriceWidget(
innerKey: tradeScreenAskPrice,
label: "Latest Ask: ",
price: Usd.fromDouble(price ?? 0.0),
);
Expand All @@ -69,6 +70,7 @@ class TradeScreen extends StatelessWidget {
return provider.getBidPrice();
}, builder: (context, price, child) {
return LatestPriceWidget(
innerKey: tradeScreenBidPrice,
label: "Latest Bid: ",
price: Usd.fromDouble(price ?? 0.0),
);
Expand Down Expand Up @@ -261,12 +263,15 @@ class TradeScreen extends StatelessWidget {
class LatestPriceWidget extends StatelessWidget {
final Usd price;
final String label;
final Key innerKey;

const LatestPriceWidget({super.key, required this.price, required this.label});
const LatestPriceWidget(
{super.key, required this.price, required this.label, required this.innerKey});

@override
Widget build(BuildContext context) {
return RichText(
key: innerKey,
text: TextSpan(
text: label,
style: DefaultTextStyle.of(context).style,
Expand Down
27 changes: 23 additions & 4 deletions mobile/lib/util/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const _buy = "buy";
const _sell = "sell";
const _positions = "positions";
const _orders = "orders";
const _configureChannel = "configure_channel";
const _confirmationButton = "confirmation_button";
const _confirmationSlider = "confirmation_slider";
const _openChannel = "open_channel";

const tradeScreenTabsOrders = Key(_trade + _tabs + _orders);
Expand All @@ -46,9 +47,6 @@ const tradeScreenBottomSheetTabsSell = Key(_trade + _bottomSheet + _tabs + _sell
const tradeScreenBottomSheetButtonBuy = Key(_trade + _bottomSheet + _button + _buy);
const tradeScreenBottomSheetButtonSell = Key(_trade + _bottomSheet + _button + _sell);

const tradeScreenBottomSheetChannelConfigurationConfirmButton =
Key(_trade + _bottomSheet + _configureChannel);

const tradeScreenBottomSheetConfirmationConfigureChannelSlider =
Key(_trade + _bottomSheet + _confirmSheet + _channelConfig + _slider + _openChannel);

Expand All @@ -65,3 +63,24 @@ const tradeScreenBottomSheetConfirmationSliderButtonSell =
const tabStable = Key(_tabs + _stable);
const tabWallet = Key(_tabs + _wallet);
const tabTrade = Key(_tabs + _trade);

const _ask = "ask";
const _bid = "bid";
const _marketPrice = "marketPrice";
const _quantityInput = "quantityInput";
const _marginField = "marginField";

const tradeScreenAskPrice = Key(_trade + _tabs + _ask);
const tradeScreenBidPrice = Key(_trade + _tabs + _bid);

const tradeButtonSheetMarketPrice = Key(_trade + _tabs + _bottomSheet + _marketPrice);
const tradeButtonSheetQuantityInput = Key(_trade + _tabs + _bottomSheet + _quantityInput);
const tradeButtonSheetMarginField = Key(_trade + _tabs + _bottomSheet + _marginField);

const tradeScreenBottomSheetChannelConfigurationConfirmButton =
Key(_trade + _channelConfig + _confirmationButton);

const tradeScreenBottomSheetChannelConfigurationConfirmSlider =
Key(_trade + _channelConfig + _confirmationSlider);
const tradeScreenBottomSheetChannelConfigurationFundWithWalletCheckBox =
Key(_trade + _channelConfig + _confirmationSlider);
Loading

0 comments on commit ef42084

Please sign in to comment.