Considerando o seguinte ajuste em points_exchange.dart
para adicionar uma chave de identificação accountPoints
da subseção de pontos:
class PointsExchange extends StatelessWidget {
const PointsExchange({super.key});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 16.0, bottom: 16.0),
child: Text(
"Account Points",
style: Theme.of(context).textTheme.titleLarge,
),
),
const BoxCard(boxCardBody: AccountPoints(key: Key("accountPoints"),)),
],
),
);
}
}
Escrevi o seguinte cenário de teste para testar se a quantidade de pontos sobe, mas está dando erro:
class _Home extends StatelessWidget {
const _Home();
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "Flutter Demo",
theme: purpleTheme,
home: BankInherited(child: const Home()),
);
}
}
main() {
testWidgets("Deposit increases 10 points smoke test", (widgetTester) async {
await widgetTester.pumpWidget(const _Home());
await widgetTester.tap(find.byIcon(Icons.account_balance_wallet));
await widgetTester.tap(find.byKey(Key("accountPoints")));
await widgetTester.pumpAndSettle();
expect(
find.descendant(
of: find.byKey(Key("accountPoints")),
matching: find.text("10.0"),
),
findsOneWidget,
);
});
}
Substituindo a averiguação pela seguinte, o teste passa:
expect(
find.descendant(
of: find.byKey(Key("accountPoints")),
matching: find.text("0.0"),
),
findsOneWidget,
);
Já testei averiguando outros valores que são atualizados (saldo, gasto, ganho), mas é neste em específico que está dando erro e que parece não atualizar. Como proceder?