Skip to content

Commit b393f4b

Browse files
test(core): cover multi-tag backup option cards
BackupOptionCard grew from one optional tag to a list so the encrypted vault card could say both how easy it is and that it uses Tor, but nothing verified either the list or the Wrap that carries it. Covers all three cardinalities and both layouts: two tags sit side by side when the card is wide, and the second moves to its own row when it is not. That last case is the whole reason for the Wrap — with a Row it would overflow instead, and the test would fail.
1 parent 9393bef commit b393f4b

1 file changed

Lines changed: 88 additions & 0 deletions

File tree

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import 'package:bb_mobile/core/themes/app_theme.dart';
2+
import 'package:bb_mobile/core/widgets/cards/backup_option_card.dart';
3+
import 'package:bb_mobile/core/widgets/cards/tag_card.dart';
4+
import 'package:bb_mobile/generated/l10n/localization.dart';
5+
import 'package:flutter/material.dart';
6+
import 'package:flutter_test/flutter_test.dart';
7+
8+
void main() {
9+
Future<void> pumpCard(
10+
WidgetTester tester, {
11+
List<String> tags = const [],
12+
double width = 400,
13+
}) async {
14+
await tester.pumpWidget(
15+
MaterialApp(
16+
theme: AppTheme.themeData(AppThemeType.light),
17+
localizationsDelegates: AppLocalizations.localizationsDelegates,
18+
supportedLocales: AppLocalizations.supportedLocales,
19+
home: Scaffold(
20+
body: Center(
21+
child: SizedBox(
22+
width: width,
23+
child: BackupOptionCard(
24+
icon: const Icon(Icons.lock),
25+
title: 'Encrypted vault',
26+
description: 'Stored on a server, unlocked with your PIN.',
27+
tags: tags,
28+
onTap: () {},
29+
),
30+
),
31+
),
32+
),
33+
),
34+
);
35+
}
36+
37+
testWidgets('renders every tag it is given', (tester) async {
38+
await pumpCard(tester, tags: ['Easy and simple (1 minute)', 'Uses Tor']);
39+
40+
expect(find.byType(OptionsTag), findsNWidgets(2));
41+
expect(find.text('Easy and simple (1 minute)'), findsOneWidget);
42+
expect(find.text('Uses Tor'), findsOneWidget);
43+
});
44+
45+
testWidgets('renders a single tag', (tester) async {
46+
await pumpCard(tester, tags: ['Takes 10 minutes']);
47+
48+
expect(find.byType(OptionsTag), findsOneWidget);
49+
expect(find.text('Takes 10 minutes'), findsOneWidget);
50+
});
51+
52+
testWidgets('renders no tag widget at all when given none', (tester) async {
53+
await pumpCard(tester);
54+
55+
expect(find.byType(OptionsTag), findsNothing);
56+
// The rest of the card is unaffected.
57+
expect(find.text('Encrypted vault'), findsOneWidget);
58+
});
59+
60+
testWidgets('lays two tags side by side when there is room', (tester) async {
61+
await pumpCard(
62+
tester,
63+
tags: ['Easy and simple (1 minute)', 'Uses Tor'],
64+
width: 600,
65+
);
66+
67+
final first = tester.getTopLeft(find.byType(OptionsTag).at(0));
68+
final second = tester.getTopLeft(find.byType(OptionsTag).at(1));
69+
expect(second.dy, first.dy);
70+
expect(second.dx, greaterThan(first.dx));
71+
});
72+
73+
testWidgets('wraps the second tag onto its own row when the card is narrow', (
74+
tester,
75+
) async {
76+
await pumpCard(
77+
tester,
78+
tags: ['Easy and simple (1 minute)', 'Uses Tor'],
79+
width: 260,
80+
);
81+
82+
final first = tester.getTopLeft(find.byType(OptionsTag).at(0));
83+
final second = tester.getTopLeft(find.byType(OptionsTag).at(1));
84+
expect(second.dy, greaterThan(first.dy));
85+
// Wrapping, not overflowing: no layout exception and both are still there.
86+
expect(find.byType(OptionsTag), findsNWidgets(2));
87+
});
88+
}

0 commit comments

Comments
 (0)