appsok/test/settings_page_test.dart
toki 7ad88fb236 feat: jenkins credential milestone update and reauth UI implementation
- Update jenkins-credential.md milestone progress
- Implement ReAuthUi and related fixes
- Archive completed subtasks (02+01, 03)
- Add new 04+03_reauth_ui subtask with PLAN and CODE_REVIEW
- Update app, settings, and session related files
- Add auth bridge and app auth tests
2026-06-13 17:03:42 +09:00

130 lines
3.8 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:appsok/src/features/settings/settings_page.dart';
import 'package:appsok/src/theme/app_theme.dart';
Widget _wrap(Widget child) => MaterialApp(
theme: AppTheme.light(),
home: Scaffold(body: child),
);
void main() {
group('SettingsPage web login', () {
testWidgets('disables web login for invalid Jenkins URL', (tester) async {
await tester.pumpWidget(_wrap(const SettingsPage()));
final button = tester.widget<ElevatedButton>(
find.byKey(const ValueKey('jenkins-web-login-button')),
);
expect(button.onPressed, isNull);
// Empty URL — still disabled
await tester.enterText(find.byType(TextField).first, '');
await tester.pump();
final buttonAfterEmpty = tester.widget<ElevatedButton>(
find.byKey(const ValueKey('jenkins-web-login-button')),
);
expect(buttonAfterEmpty.onPressed, isNull);
// Non-URL text — still disabled
await tester.enterText(find.byType(TextField).first, 'not-a-url');
await tester.pump();
final buttonAfterInvalid = tester.widget<ElevatedButton>(
find.byKey(const ValueKey('jenkins-web-login-button')),
);
expect(buttonAfterInvalid.onPressed, isNull);
});
testWidgets('calls web login launcher with normalized base URL', (
tester,
) async {
String? capturedUrl;
await tester.pumpWidget(
_wrap(
SettingsPage(
webLoginLauncher: (url) async {
capturedUrl = url;
return null;
},
),
),
);
await tester.enterText(
find.byType(TextField).first,
'https://jenkins.example.com',
);
await tester.pump();
final button = tester.widget<ElevatedButton>(
find.byKey(const ValueKey('jenkins-web-login-button')),
);
expect(button.onPressed, isNotNull);
await tester.tap(find.byKey(const ValueKey('jenkins-web-login-button')));
await tester.pumpAndSettle();
expect(capturedUrl, 'https://jenkins.example.com');
});
testWidgets('shows completed login user without token text', (
tester,
) async {
await tester.pumpWidget(
_wrap(
SettingsPage(
webLoginLauncher: (_) async => const JenkinsWebLoginResult(
username: 'toki',
displayName: 'Toki Lab',
),
),
),
);
await tester.enterText(
find.byType(TextField).first,
'https://jenkins.example.com',
);
await tester.pump();
await tester.tap(find.byKey(const ValueKey('jenkins-web-login-button')));
await tester.pumpAndSettle();
// Result label must show displayName
expect(find.byKey(const ValueKey('web-login-result')), findsOneWidget);
expect(find.textContaining('Toki Lab'), findsOneWidget);
// No token-like text should appear
expect(find.textContaining('token'), findsNothing);
expect(find.textContaining('apiToken'), findsNothing);
});
testWidgets('clears stored credential through sessionClearer', (
tester,
) async {
var clearCalled = false;
await tester.pumpWidget(
_wrap(
SettingsPage(
sessionClearer: () async {
clearCalled = true;
},
),
),
);
await tester.tap(
find.byKey(const ValueKey('jenkins-clear-session-button')),
);
await tester.pumpAndSettle();
expect(clearCalled, isTrue);
expect(
find.byKey(const ValueKey('session-cleared-label')),
findsOneWidget,
);
expect(find.byKey(const ValueKey('session-clear-error')), findsNothing);
});
});
}