Files
plezy/test/widgets/device_code_dialog_test.dart
T
edde746 f1d4be70e2 feat(trackers): show a QR code in every tracker sign-in dialog and fit them on TV screens
Every tracker auth dialog (Trakt/Simkl/MDBList device-code and MAL/AniList
OAuth proxy) now shares the same PendingAuthDialog affordances: a QR code for
the sign-in URL, a large copyable URL with the scheme stripped, the browser
launch button (hidden on Apple TV, which has no browser), and the polling
spinner. On wide viewports (TV logical 960x540, desktop, phone landscape) the
QR pane sits beside the instructions so the dialog no longer clips on tvOS,
and the content is scrollable as an overflow safety net. Device activation
codes scale down instead of wrapping.
2026-08-10 08:33:11 +02:00

61 lines
2.2 KiB
Dart

import 'dart:ui' show SemanticsAction, Tristate;
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:plezy/i18n/strings.g.dart';
import 'package:plezy/models/trackers/device_code.dart';
import 'package:plezy/widgets/device_code_dialog.dart';
import 'package:qr_flutter/qr_flutter.dart';
void main() {
setUpAll(() => LocaleSettings.setLocaleSync(AppLocale.en));
const code = DeviceCode(
deviceCode: 'device-token',
userCode: 'ABCD-EFGH',
verificationUrl: 'https://example.com/activate',
verificationUrlComplete: 'https://example.com/activate/ABCD-EFGH',
expiresIn: 600,
interval: 5,
);
testWidgets('copy control exposes the activation code as its value', (tester) async {
final semantics = tester.ensureSemantics();
await tester.pumpWidget(
MaterialApp(
home: DeviceCodeDialog(code: code, serviceName: 'Example', onCancel: () {}),
),
);
final finder = find.bySemanticsLabel(t.services.deviceCode.copyCode);
expect(finder, findsOneWidget);
final data = tester.getSemantics(finder).getSemanticsData();
expect(data.value, code.userCode);
expect(data.flagsCollection.isButton, isTrue);
expect(data.flagsCollection.isEnabled, Tristate.isTrue);
expect(data.hasAction(SemanticsAction.tap), isTrue);
expect(find.bySemanticsLabel(code.userCode), findsNothing);
semantics.dispose();
});
testWidgets('shows a QR code for the complete verification URL and a copyable readable URL', (tester) async {
final semantics = tester.ensureSemantics();
await tester.pumpWidget(
MaterialApp(
home: DeviceCodeDialog(code: code, serviceName: 'Example', onCancel: () {}),
),
);
expect(find.byType(QrImageView), findsOneWidget);
// The visible URL is the short verification URL with the scheme stripped,
// but copying yields the full code-prefilled URL.
expect(find.text('example.com/activate'), findsOneWidget);
final urlFinder = find.bySemanticsLabel(t.services.pendingAuth.copyUrl);
expect(urlFinder, findsOneWidget);
expect(tester.getSemantics(urlFinder).getSemanticsData().value, code.verificationUrlComplete);
semantics.dispose();
});
}