Files
sure/mobile/test/widgets/sure_card_test.dart
ghost 56000d7834 feat(mobile): add SureCard primitive and migrate account cards (#2370)
* feat(mobile): add SureCard primitive and migrate account cards

SureCard mirrors the web card chrome — `bg-container` + a hairline border +
rounded corners + the subtle DS shadow (`shadowXs`, from the scale shipped in
#2349) — resolved from the active SureColors palette so it stays in lockstep with
`sure.tokens.json` in light and dark. An optional `onTap` gives a flat ink
response clipped to the card radius.

Migrates AccountCard off the Material `Card` to `SureCard`.

Refs #2235.

* fix(coinstats): deterministic wallet batch order in bulk fetches

The bulk balance/transaction fetches built the "blockchain:address" param in
linked-account query order, which isn't stable across runs — so the batched
param (and its mocked expectations) varied seed to seed, intermittently failing
CoinstatsItem::ImporterTest and red-flagging unrelated PRs. Sort the wallets
before joining so the batch order is deterministic, and align the test
expectations to the sorted order.

* fix(mobile): tokenize swipe-reveal radius + cover SureCard dark theme

Address PR review:
- The account-card swipe-reveal background still used a hardcoded radius (12)
  that mismatched SureCard's radiusLg (10) once the card was migrated — tokenize
  it so the reveal corners line up during the swipe.
- Parameterize the SureCard chrome test over light + dark, since the card is
  brightness-aware (catches palette regressions in either mode).

* test(mobile): assert SureCard onTap ink is clipped to the card radius

Address review nit: the onTap test claimed the ink is clipped to the card but
only checked the InkWell exists. Now it asserts the InkWell's borderRadius equals
SureTokens.radiusLg (tester.widget already enforces a single InkWell).
2026-06-20 21:43:20 +02:00

70 lines
2.4 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:sure_mobile/theme/sure_theme.dart';
import 'package:sure_mobile/theme/sure_tokens.dart';
import 'package:sure_mobile/widgets/sure_card.dart';
void main() {
Future<void> pump(WidgetTester tester, Widget child,
{Brightness brightness = Brightness.light}) {
return tester.pumpWidget(
MaterialApp(
theme:
brightness == Brightness.light ? SureTheme.light : SureTheme.dark,
home: Scaffold(body: child),
),
);
}
BoxDecoration decorationOf(WidgetTester tester) => tester
.widget<Container>(
find
.descendant(of: find.byType(SureCard), matching: find.byType(Container))
.first,
)
.decoration as BoxDecoration;
// Brightness-aware by contract — assert the chrome resolves the right palette
// in both themes so a token regression in either mode is caught.
for (final (brightness, tokens) in [
(Brightness.light, SureTokens.light),
(Brightness.dark, SureTokens.dark),
]) {
testWidgets('paints the Sure card chrome from tokens (${brightness.name})',
(tester) async {
await pump(tester, const SureCard(child: Text('Body')),
brightness: brightness);
final deco = decorationOf(tester);
expect(deco.color, tokens.container);
expect((deco.border as Border).top.color, tokens.borderSecondary);
expect(deco.borderRadius, BorderRadius.circular(SureTokens.radiusLg));
expect(deco.boxShadow, tokens.shadowXs);
expect(find.text('Body'), findsOneWidget);
});
}
testWidgets('elevated: false drops the shadow', (tester) async {
await pump(tester, const SureCard(elevated: false, child: Text('Body')));
expect(decorationOf(tester).boxShadow, isNull);
});
testWidgets('onTap fires and is clipped to the card (InkWell present)',
(tester) async {
var taps = 0;
await pump(
tester,
SureCard(onTap: () => taps++, child: const Text('Tap me')),
);
final inkWell = tester.widget<InkWell>(find.byType(InkWell));
expect(inkWell.borderRadius, BorderRadius.circular(SureTokens.radiusLg));
await tester.tap(find.text('Tap me'));
expect(taps, 1);
});
testWidgets('is non-interactive without onTap (no InkWell)', (tester) async {
await pump(tester, const SureCard(child: Text('Body')));
expect(find.byType(InkWell), findsNothing);
});
}