Files
meshcore-open/test/widgets/get_node_banner_test.dart
zjs81 ee382f9177 Configure the connect screen's node banner from a DNS TXT record
The "get a node" banner's link, and optionally its title, body and button
text, now come from the _banner.meshcoreopen.org TXT record, looked up
over Cloudflare DNS-over-HTTPS and cached for the record's TTL (1 min to
6 h). The record is `v=1;on=1;url=<https link>` with URL-encoded values;
`on=0`, a missing record or any lookup failure hides the banner.
2026-10-24 21:29:08 -07:00

90 lines
2.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:meshcore_open/l10n/app_localizations.dart';
import 'package:meshcore_open/services/node_banner_service.dart';
import 'package:meshcore_open/widgets/get_node_banner.dart';
final _config = NodeBannerConfig(url: Uri.parse('https://example.com/node'));
void main() {
Future<void> pumpBanner(
WidgetTester tester, {
required Size size,
required double textScale,
NodeBannerConfig? config,
bool hidden = false,
}) async {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.pumpWidget(
MaterialApp(
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: MediaQuery(
data: MediaQueryData(
size: size,
textScaler: TextScaler.linear(textScale),
),
child: Scaffold(
bottomNavigationBar: GetNodeBanner(
loadConfig: () async => hidden ? null : config ?? _config,
),
),
),
),
);
}
testWidgets('shows the pitch and affiliate link', (tester) async {
await pumpBanner(tester, size: const Size(390, 844), textScale: 1);
await tester.pump();
expect(find.text('Need a new node?'), findsOneWidget);
expect(find.text('Get one here'), findsOneWidget);
expect(find.textContaining('Affiliate link'), findsOneWidget);
// Leaves most of the screen for the device list.
expect(
tester.getSize(find.byType(GetNodeBanner)).height,
lessThan(844 * 0.4),
);
});
testWidgets('lays out on a narrow phone with large text', (tester) async {
await pumpBanner(tester, size: const Size(320, 800), textScale: 1.5);
await tester.pump();
expect(tester.takeException(), isNull);
});
testWidgets('uses text overrides from the record', (tester) async {
await pumpBanner(
tester,
size: const Size(390, 844),
textScale: 1,
config: NodeBannerConfig(
url: Uri.parse('https://example.com'),
title: 'Spring sale',
action: 'Shop now',
),
);
await tester.pump();
expect(find.text('Spring sale'), findsOneWidget);
expect(find.text('Shop now'), findsOneWidget);
expect(find.textContaining('Affiliate link'), findsOneWidget);
});
testWidgets('shows nothing when there is no config', (tester) async {
await pumpBanner(
tester,
size: const Size(390, 844),
textScale: 1,
hidden: true,
);
await tester.pump();
expect(find.byType(InkWell), findsNothing);
expect(tester.getSize(find.byType(GetNodeBanner)).height, 0);
});
}