test: add widget tests for SettingsPage

- Add 14 widget tests covering:
  - Settings header and section displays
  - Appearance section with theme dropdown options
  - Navigation section with default room dropdown
  - Account section with user info (name, email, roles)
  - Theme icons for system/light/dark modes
  - Three section cards layout

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Jeroen Schweitzer
2026-01-05 22:31:13 +01:00
co-authored by Claude Opus 4.5
parent 837ccb6709
commit 422fac392c
@@ -0,0 +1,172 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:tatlock_ui/core/theme/theme_provider.dart';
import 'package:tatlock_ui/features/settings/presentation/pages/settings_page.dart';
import '../../../../harness/test_harness.dart';
void main() {
final harness = TestHarness();
setUp(() => harness.setUp());
tearDown(() => harness.tearDown());
group('SettingsPage', () {
testWidgets('displays Settings header', (tester) async {
harness.givenAuthenticatedUser();
await tester.pumpWidget(harness.wrap(const SettingsPage()));
await tester.pumpAndSettle();
expect(find.text('Settings'), findsOneWidget);
});
testWidgets('displays Appearance section', (tester) async {
harness.givenAuthenticatedUser();
await tester.pumpWidget(harness.wrap(const SettingsPage()));
await tester.pumpAndSettle();
expect(find.text('APPEARANCE'), findsOneWidget);
expect(find.text('Theme'), findsOneWidget);
expect(find.text('Choose your preferred color scheme'), findsOneWidget);
});
testWidgets('displays theme dropdown with options', (tester) async {
harness.givenAuthenticatedUser();
await tester.pumpWidget(harness.wrap(const SettingsPage()));
await tester.pumpAndSettle();
// Find and tap the theme dropdown
final dropdown = find.byType(DropdownButton<ThemeSetting>);
expect(dropdown, findsOneWidget);
await tester.tap(dropdown);
await tester.pumpAndSettle();
// Should show all theme options (may appear twice: selected + menu item)
expect(find.text('System'), findsWidgets);
expect(find.text('Light'), findsWidgets);
expect(find.text('Dark'), findsWidgets);
});
testWidgets('displays Navigation section', (tester) async {
harness.givenAuthenticatedUser();
await tester.pumpWidget(harness.wrap(const SettingsPage()));
await tester.pumpAndSettle();
expect(find.text('NAVIGATION'), findsOneWidget);
expect(find.text('Default Room'), findsOneWidget);
expect(find.text('Room to show when app opens'), findsOneWidget);
});
testWidgets('displays room dropdown with options', (tester) async {
harness.givenAuthenticatedUser();
await tester.pumpWidget(harness.wrap(const SettingsPage()));
await tester.pumpAndSettle();
// Find the room dropdown (second DropdownButton)
final dropdowns = find.byType(DropdownButton<String>);
expect(dropdowns, findsOneWidget);
await tester.tap(dropdowns);
await tester.pumpAndSettle();
// Should show room options from registry
expect(find.text('Front Hall'), findsWidgets);
});
testWidgets('displays Account section', (tester) async {
harness.givenAuthenticatedUser();
await tester.pumpWidget(harness.wrap(const SettingsPage()));
await tester.pumpAndSettle();
expect(find.text('ACCOUNT'), findsOneWidget);
expect(find.text('Name'), findsOneWidget);
expect(find.text('Email'), findsOneWidget);
});
testWidgets('displays user name from auth state', (tester) async {
harness.givenAuthenticatedUser(name: 'John Doe');
await tester.pumpWidget(harness.wrap(const SettingsPage()));
await tester.pumpAndSettle();
expect(find.text('John Doe'), findsOneWidget);
});
testWidgets('displays user email from auth state', (tester) async {
harness.givenAuthenticatedUser(email: 'john@example.com');
await tester.pumpWidget(harness.wrap(const SettingsPage()));
await tester.pumpAndSettle();
expect(find.text('john@example.com'), findsOneWidget);
});
testWidgets('displays admin role for admin user', (tester) async {
harness.givenAdminUser();
await tester.pumpWidget(harness.wrap(const SettingsPage()));
await tester.pumpAndSettle();
expect(find.text('Roles'), findsOneWidget);
expect(find.textContaining('admin.general:admin'), findsOneWidget);
});
testWidgets('displays theme icon for system theme', (tester) async {
harness.givenAuthenticatedUser();
harness.givenThemeMode(ThemeMode.system);
await tester.pumpWidget(harness.wrap(const SettingsPage()));
await tester.pumpAndSettle();
expect(find.byIcon(Icons.brightness_auto), findsOneWidget);
});
testWidgets('displays theme icon for light theme', (tester) async {
harness.givenAuthenticatedUser();
harness.givenThemeMode(ThemeMode.light);
await tester.pumpWidget(harness.wrap(const SettingsPage()));
await tester.pumpAndSettle();
expect(find.byIcon(Icons.light_mode), findsOneWidget);
});
testWidgets('displays theme icon for dark theme', (tester) async {
harness.givenAuthenticatedUser();
harness.givenThemeMode(ThemeMode.dark);
await tester.pumpWidget(harness.wrap(const SettingsPage()));
await tester.pumpAndSettle();
expect(find.byIcon(Icons.dark_mode), findsOneWidget);
});
testWidgets('displays account icons', (tester) async {
harness.givenAuthenticatedUser();
await tester.pumpWidget(harness.wrap(const SettingsPage()));
await tester.pumpAndSettle();
expect(find.byIcon(Icons.person_outline), findsOneWidget);
expect(find.byIcon(Icons.email_outlined), findsOneWidget);
expect(find.byIcon(Icons.home_outlined), findsOneWidget);
});
testWidgets('displays all three section cards', (tester) async {
harness.givenAuthenticatedUser();
await tester.pumpWidget(harness.wrap(const SettingsPage()));
await tester.pumpAndSettle();
// Should have 3 cards: Appearance, Navigation, Account
expect(find.byType(Card), findsNWidgets(3));
});
});
}