utils/crdt_sync_flutter/test/e2e_passphrase_button_test.dart
Krzysztof kuhy Rudnicki 1962d30333 crdt_sync_flutter 0.8.2: import material_ui
Flutter 3.50 deprecates package:flutter/material.dart. In an app whose
MaterialApp comes from material_ui, the passphrase button's showDialog
found no MaterialLocalizations and threw. The test now pumps a
material_ui MaterialApp: red on the old import, 107 pass after.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 08:03:18 +01:00

66 lines
2.0 KiB
Dart

import 'package:crdt_sync_flutter/crdt_sync_flutter.dart';
import 'package:crdt_sync_flutter/testing/fake_secure_storage.dart';
import 'package:material_ui/material_ui.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
setUp(installFakeSecureStorage);
Future<void> pump(WidgetTester t, {required bool locked, VoidCallback? cb}) =>
t.pumpWidget(
MaterialApp(
home: Scaffold(
body: E2ePassphraseButton(locked: locked, onSaved: cb),
),
),
);
testWidgets('icon follows the locked flag', (t) async {
await pump(t, locked: true);
expect(find.byIcon(Icons.lock), findsOneWidget);
await pump(t, locked: false);
expect(find.byIcon(Icons.lock_open), findsOneWidget);
});
testWidgets('entering a passphrase stores it and notifies', (t) async {
var saved = 0;
await pump(t, locked: true, cb: () => saved++);
await t.tap(find.byType(IconButton));
await t.pumpAndSettle();
await t.enterText(find.byType(TextField), 'pw');
await t.tap(find.byIcon(Icons.check));
await t.pumpAndSettle();
expect(
await const FlutterSecureStorage().read(key: kE2ePassphraseKey),
'pw',
);
expect(saved, 1);
});
testWidgets('submitting with Enter saves; empty input saves nothing', (
t,
) async {
await pump(t, locked: true);
await t.tap(find.byType(IconButton));
await t.pumpAndSettle();
await t.enterText(find.byType(TextField), 'x1');
await t.testTextInput.receiveAction(TextInputAction.done);
await t.pumpAndSettle();
expect(
await const FlutterSecureStorage().read(key: kE2ePassphraseKey),
'x1',
);
await clearE2ePassphrase();
await t.tap(find.byType(IconButton));
await t.pumpAndSettle();
await t.tap(find.byIcon(Icons.check));
await t.pumpAndSettle();
expect(
await const FlutterSecureStorage().read(key: kE2ePassphraseKey),
isNull,
);
});
}