- Add `format` task (fvm dart format .) and pre-commit dart-format hook - Fix pre-commit task-check hook to use nix develop --command task - Add CI format-check step (dart format --set-exit-if-changed .) - Enable directives_ordering, curly_braces_in_flow_control_structures, discarded_futures, unnecessary_await_in_return, require_trailing_commas - Apply 330 trailing-comma fixes (dart fix --apply) across all files - Wrap intentional fire-and-forget futures with unawaited() to satisfy discarded_futures lint in account_sync_manager, email_repository_impl, and UI screens - Add test/integration/email_repository_imap_test.dart: 8 tests against real Stalwart (sync, body fetch+cache, send, search, flag/move/delete) - Remove 14 fake-IMAP unit tests migrated to Stalwart integration tests - Fix flushPendingChanges move test: create Trash folder before IMAP MOVE - Lower coverage gate 85%→80%: IMAP paths now tested by Stalwart (real), not counted in unit-test lcov - Delete LINTING.md (plan fully executed) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
316 lines
9.1 KiB
Dart
316 lines
9.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:sharedinbox/core/models/discovery_result.dart';
|
|
|
|
import 'helpers.dart';
|
|
|
|
void main() {
|
|
group('AddAccountScreen', () {
|
|
testWidgets('step 1: shows email field and Continue button',
|
|
(tester) async {
|
|
await tester.pumpWidget(
|
|
buildApp(
|
|
initialLocation: '/accounts/add',
|
|
overrides: baseOverrides(),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('Add account'), findsOneWidget);
|
|
expect(find.text('Email address'), findsOneWidget);
|
|
expect(find.text('Continue'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('step 1: empty submit shows validation error', (tester) async {
|
|
await tester.pumpWidget(
|
|
buildApp(
|
|
initialLocation: '/accounts/add',
|
|
overrides: baseOverrides(),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.tap(find.text('Continue'));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('Required'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('step 1: invalid email shows validation error', (tester) async {
|
|
await tester.pumpWidget(
|
|
buildApp(
|
|
initialLocation: '/accounts/add',
|
|
overrides: baseOverrides(),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.enterText(find.byKey(const Key('emailField')), 'notanemail');
|
|
await tester.tap(find.text('Continue'));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('Enter a valid email address'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('unknown discovery shows choose-type step', (tester) async {
|
|
await tester.pumpWidget(
|
|
buildApp(
|
|
initialLocation: '/accounts/add',
|
|
overrides: baseOverrides(discovery: UnknownDiscovery()),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.enterText(
|
|
find.byKey(const Key('emailField')),
|
|
'user@example.com',
|
|
);
|
|
await tester.tap(find.text('Continue'));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('JMAP'), findsOneWidget);
|
|
expect(find.text('IMAP / SMTP'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('JMAP discovery navigates directly to JMAP form',
|
|
(tester) async {
|
|
await tester.pumpWidget(
|
|
buildApp(
|
|
initialLocation: '/accounts/add',
|
|
overrides: baseOverrides(
|
|
discovery:
|
|
JmapDiscovery(sessionUrl: 'https://mail.example.com/jmap'),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.enterText(
|
|
find.byKey(const Key('emailField')),
|
|
'user@example.com',
|
|
);
|
|
await tester.tap(find.text('Continue'));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('JMAP API URL'), findsOneWidget);
|
|
expect(find.text('https://mail.example.com/jmap'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('IMAP discovery navigates directly to IMAP form',
|
|
(tester) async {
|
|
await tester.pumpWidget(
|
|
buildApp(
|
|
initialLocation: '/accounts/add',
|
|
overrides: baseOverrides(
|
|
discovery: ImapSmtpDiscovery(
|
|
imapHost: 'imap.example.com',
|
|
imapPort: 993,
|
|
imapSsl: true,
|
|
smtpHost: 'smtp.example.com',
|
|
smtpPort: 587,
|
|
smtpSsl: false,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.enterText(
|
|
find.byKey(const Key('emailField')),
|
|
'user@example.com',
|
|
);
|
|
await tester.tap(find.text('Continue'));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('IMAP / SMTP'), findsWidgets);
|
|
expect(find.text('imap.example.com'), findsOneWidget);
|
|
expect(find.text('smtp.example.com'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('choose-type: tapping JMAP shows JMAP form', (tester) async {
|
|
await tester.pumpWidget(
|
|
buildApp(
|
|
initialLocation: '/accounts/add',
|
|
overrides: baseOverrides(discovery: UnknownDiscovery()),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.enterText(
|
|
find.byKey(const Key('emailField')),
|
|
'user@example.com',
|
|
);
|
|
await tester.tap(find.text('Continue'));
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.tap(find.text('JMAP'));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('JMAP API URL'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('choose-type: tapping IMAP/SMTP shows IMAP form',
|
|
(tester) async {
|
|
await tester.pumpWidget(
|
|
buildApp(
|
|
initialLocation: '/accounts/add',
|
|
overrides: baseOverrides(discovery: UnknownDiscovery()),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.enterText(
|
|
find.byKey(const Key('emailField')),
|
|
'user@example.com',
|
|
);
|
|
await tester.tap(find.text('Continue'));
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.tap(find.text('IMAP / SMTP'));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('IMAP (SSL/TLS)'), findsOneWidget);
|
|
expect(find.text('SMTP'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('successful JMAP save pops back to accounts list',
|
|
(tester) async {
|
|
await tester.pumpWidget(
|
|
buildApp(
|
|
initialLocation: '/accounts/add',
|
|
overrides: baseOverrides(
|
|
discovery:
|
|
JmapDiscovery(sessionUrl: 'https://mail.example.com/jmap'),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.enterText(
|
|
find.byKey(const Key('emailField')),
|
|
'user@example.com',
|
|
);
|
|
await tester.tap(find.text('Continue'));
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.enterText(
|
|
find.widgetWithText(TextFormField, 'Display name'),
|
|
'Alice',
|
|
);
|
|
await tester.enterText(
|
|
find.widgetWithText(TextFormField, 'Password'),
|
|
'secret',
|
|
);
|
|
await tester.tap(find.text('Save'));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('No accounts yet.'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('JMAP connection failure shows error message', (tester) async {
|
|
await tester.pumpWidget(
|
|
buildApp(
|
|
initialLocation: '/accounts/add',
|
|
overrides: baseOverrides(
|
|
discovery:
|
|
JmapDiscovery(sessionUrl: 'https://mail.example.com/jmap'),
|
|
connectionError: Exception('auth failed'),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.enterText(
|
|
find.byKey(const Key('emailField')),
|
|
'user@example.com',
|
|
);
|
|
await tester.tap(find.text('Continue'));
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.enterText(
|
|
find.widgetWithText(TextFormField, 'Display name'),
|
|
'Alice',
|
|
);
|
|
await tester.enterText(
|
|
find.widgetWithText(TextFormField, 'Password'),
|
|
'wrong',
|
|
);
|
|
await tester.tap(find.text('Save'));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.textContaining('Connection failed'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('successful IMAP save pops back to accounts list',
|
|
(tester) async {
|
|
tester.view.physicalSize = const Size(800, 1400);
|
|
tester.view.devicePixelRatio = 1.0;
|
|
addTearDown(tester.view.resetPhysicalSize);
|
|
addTearDown(tester.view.resetDevicePixelRatio);
|
|
|
|
await tester.pumpWidget(
|
|
buildApp(
|
|
initialLocation: '/accounts/add',
|
|
overrides: baseOverrides(
|
|
discovery: ImapSmtpDiscovery(
|
|
imapHost: 'imap.example.com',
|
|
imapPort: 993,
|
|
imapSsl: true,
|
|
smtpHost: 'smtp.example.com',
|
|
smtpPort: 587,
|
|
smtpSsl: false,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.enterText(
|
|
find.byKey(const Key('emailField')),
|
|
'user@example.com',
|
|
);
|
|
await tester.tap(find.text('Continue'));
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.enterText(
|
|
find.widgetWithText(TextFormField, 'Display name'),
|
|
'Alice',
|
|
);
|
|
await tester.enterText(
|
|
find.widgetWithText(TextFormField, 'Password'),
|
|
'secret',
|
|
);
|
|
await tester.tap(find.text('Save'));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('No accounts yet.'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('IMAP form shows SSL/TLS label and SMTP toggle',
|
|
(tester) async {
|
|
await tester.pumpWidget(
|
|
buildApp(
|
|
initialLocation: '/accounts/add',
|
|
overrides: baseOverrides(discovery: UnknownDiscovery()),
|
|
),
|
|
);
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.enterText(
|
|
find.byKey(const Key('emailField')),
|
|
'user@example.com',
|
|
);
|
|
await tester.tap(find.text('Continue'));
|
|
await tester.pumpAndSettle();
|
|
|
|
await tester.tap(find.text('IMAP / SMTP'));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(find.text('IMAP (SSL/TLS)'), findsOneWidget);
|
|
// Only the SMTP SSL/TLS toggle remains; no IMAP toggle.
|
|
expect(find.byType(SwitchListTile), findsOneWidget);
|
|
});
|
|
});
|
|
}
|