utils/sync_settings_ui/test/sync_settings_screen_google_test.dart
Krzysztof kuhy Rudnicki 3084080d74
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file length / file-length (push) Waiting to run
github_device_auth tests / test (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
palette drift / palette (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
shared gate tests / gate unit tests (push) Waiting to run
sync_settings_ui tests / test (push) Waiting to run
sync_settings_ui 0.7.0, gda 0.4.0: text-free
Glyph + spoken label replaces every app-written string on the shared
Sync settings screen and the GitHub device-code dialog (kuhy's
textgate rule). Old sentences are semantics labels; tests find them
there. The device user code stays visible (GitHub's data).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 01:27:57 +01:00

200 lines
6.1 KiB
Dart

import 'dart:async';
import 'package:crdt_sync/crdt_sync.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:sync_settings_ui/sync_settings_ui.dart';
FirebaseRestClient _fakeClient() => FirebaseRestClient(
databaseUrl: 'https://example.firebasedatabase.app',
auth: FirebaseTokenProvider(
apiKey: 'test-key',
store: InMemoryCredentialStore(),
),
);
Widget _wrap(Widget child) => MaterialApp(home: child);
void main() {
group('Firebase section Google sign-in', () {
testWidgets('Google sign-in cancelled shows the cancellation message', (
tester,
) async {
await tester.pumpWidget(
_wrap(
SyncSettingsScreen(
accountLoader: () async => null,
accountSaver: (_) async {},
accountClearer: () async {},
sessionProbe: () async => false,
firebaseFactory: () async => null,
googleFirebaseFactory: () async => null,
googleAvailable: true,
),
),
);
await tester.pumpAndSettle();
await tester.tap(find.bySemanticsLabel('Sign in with Google'));
await tester.pumpAndSettle();
expect(find.bySemanticsLabel('Google sign-in was cancelled.'), findsOneWidget);
});
testWidgets(
'Google sign-in that does not persist a session reports the retry '
'message',
(tester) async {
await tester.pumpWidget(
_wrap(
SyncSettingsScreen(
accountLoader: () async => null,
accountSaver: (_) async {},
accountClearer: () async {},
sessionProbe: () async => false,
firebaseFactory: () async => null,
googleFirebaseFactory: () async => _fakeClient(),
googleAvailable: true,
),
),
);
await tester.pumpAndSettle();
await tester.tap(find.bySemanticsLabel('Sign in with Google'));
await tester.pumpAndSettle();
expect(
spoken('did not save the session'),
findsOneWidget,
);
},
);
testWidgets('Google sign-in wrong-account error surfaces the message', (
tester,
) async {
await tester.pumpWidget(
_wrap(
SyncSettingsScreen(
accountLoader: () async => null,
accountSaver: (_) async {},
accountClearer: () async {},
sessionProbe: () async => false,
firebaseFactory: () async => null,
googleFirebaseFactory: () async =>
throw FirebaseAuthError('wrong uid'),
googleAvailable: true,
),
),
);
await tester.pumpAndSettle();
await tester.tap(find.bySemanticsLabel('Sign in with Google'));
await tester.pumpAndSettle();
expect(find.bySemanticsLabel('wrong uid'), findsOneWidget);
});
testWidgets('Google sign-in generic failure surfaces the error text', (
tester,
) async {
await tester.pumpWidget(
_wrap(
SyncSettingsScreen(
accountLoader: () async => null,
accountSaver: (_) async {},
accountClearer: () async {},
sessionProbe: () async => false,
firebaseFactory: () async => null,
googleFirebaseFactory: () async => throw StateError('boom'),
googleAvailable: true,
),
),
);
await tester.pumpAndSettle();
await tester.tap(find.bySemanticsLabel('Sign in with Google'));
await tester.pumpAndSettle();
expect(spoken('Sign-in failed'), findsOneWidget);
});
testWidgets(
'hides the Google button when googleAvailable is true but no '
'googleFirebaseFactory is wired -- a visible button that can never '
'succeed must not render',
(tester) async {
await tester.pumpWidget(
_wrap(
SyncSettingsScreen(
accountLoader: () async => null,
accountSaver: (_) async {},
accountClearer: () async {},
sessionProbe: () async => false,
firebaseFactory: () async => null,
googleAvailable: true,
),
),
);
await tester.pumpAndSettle();
expect(find.bySemanticsLabel('Sign in with Google'), findsNothing);
},
);
testWidgets('a reason renders a disabled button that explains itself', (
tester,
) async {
await tester.pumpWidget(
_wrap(
SyncSettingsScreen(
accountLoader: () async => null,
accountSaver: (_) async {},
accountClearer: () async {},
sessionProbe: () async => false,
firebaseFactory: () async => null,
googleFirebaseFactory: () async => _fakeClient(),
googleAvailable: false,
googleUnavailableReason: 'Not available on this platform.',
),
),
);
await tester.pumpAndSettle();
expect(find.bySemanticsLabel('Sign in with Google'), findsOneWidget);
expect(find.bySemanticsLabel('Not available on this platform.'), findsOneWidget);
// Disabled, so it cannot report a misleading "cancelled".
final button = tester.widget<FilledButton>(
find.widgetWithIcon(FilledButton, Icons.account_circle),
);
expect(button.onPressed, isNull);
});
testWidgets('no reason keeps the button hidden, as before', (
tester,
) async {
await tester.pumpWidget(
_wrap(
SyncSettingsScreen(
accountLoader: () async => null,
accountSaver: (_) async {},
accountClearer: () async {},
sessionProbe: () async => false,
firebaseFactory: () async => null,
googleFirebaseFactory: () async => _fakeClient(),
googleAvailable: false,
),
),
);
await tester.pumpAndSettle();
expect(find.bySemanticsLabel('Sign in with Google'), findsNothing);
});
});
}
/// A node whose spoken label contains [part] literally.
Finder spoken(String part) =>
find.bySemanticsLabel(RegExp(RegExp.escape(part)));