Files
Jeroen SchweitzerandClaude Opus 4.5 d6fd9aea60 test: add test harness and widget tests for DataGrid pages
Add comprehensive testing infrastructure:
- Test harness with mock auth, API client, and fixtures
- Mock Dio interceptor for canned API responses
- Fixtures for containers, domains, users, groups

Add widget tests for all DataGrid pages:
- ContainersListPage (21 tests)
- ProxyHostsPage (16 tests)
- UsersListPage (21 tests)
- GroupsListPage (18 tests)

Add unit tests:
- RoomRegistry (28 tests)
- DataGrid components (35 tests)

Test count: 282 -> 357 (+75 tests)
Coverage: 5.7% -> 19.1% (+504 lines)

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-05 21:18:34 +01:00

119 lines
3.2 KiB
Dart

import 'package:tatlock_ui/core/auth/auth_state.dart';
import 'package:tatlock_ui/core/auth/permissions.dart';
import 'package:tatlock_ui/core/auth/user_preferences.dart';
/// Mock authentication states for testing.
class MockAuth {
MockAuth._();
/// Unauthenticated state.
static const guest = AuthState();
/// Basic authenticated user with no special permissions.
static AuthState user({
String id = 'test-user-id',
String name = 'Test User',
String email = 'test@example.com',
String defaultRoom = 'front-hall',
String theme = 'system',
}) {
return AuthState(
isAuthenticated: true,
accessToken: 'mock-access-token-${DateTime.now().millisecondsSinceEpoch}',
refreshToken: 'mock-refresh-token',
expiresAt: DateTime.now().add(const Duration(hours: 1)),
userId: id,
authentikId: 'authentik-$id',
userName: name,
userEmail: email,
roles: [],
preferences: UserPreferences(
defaultRoom: defaultRoom,
theme: theme,
),
);
}
/// Admin user with full permissions.
static AuthState admin({
String id = 'admin-user-id',
String name = 'Admin User',
String email = 'admin@example.com',
}) {
return AuthState(
isAuthenticated: true,
accessToken: 'mock-admin-token-${DateTime.now().millisecondsSinceEpoch}',
refreshToken: 'mock-admin-refresh-token',
expiresAt: DateTime.now().add(const Duration(hours: 1)),
userId: id,
authentikId: 'authentik-$id',
userName: name,
userEmail: email,
roles: [
Role(
id: 'admin-role',
name: 'admin.general:admin',
domain: Domain.admin,
category: 'general',
action: Action.admin,
),
],
preferences: const UserPreferences(),
);
}
/// User with specific permissions.
static AuthState withPermissions({
String id = 'perm-user-id',
String name = 'Permission User',
String email = 'perm@example.com',
required List<Role> roles,
}) {
return AuthState(
isAuthenticated: true,
accessToken: 'mock-perm-token-${DateTime.now().millisecondsSinceEpoch}',
refreshToken: 'mock-perm-refresh-token',
expiresAt: DateTime.now().add(const Duration(hours: 1)),
userId: id,
authentikId: 'authentik-$id',
userName: name,
userEmail: email,
roles: roles,
preferences: const UserPreferences(),
);
}
/// User with expired token (for refresh testing).
static AuthState expired({
String id = 'expired-user-id',
String name = 'Expired User',
}) {
return AuthState(
isAuthenticated: true,
accessToken: 'mock-expired-token',
refreshToken: 'mock-refresh-token',
expiresAt: DateTime.now().subtract(const Duration(hours: 1)),
userId: id,
userName: name,
roles: [],
preferences: const UserPreferences(),
);
}
/// Create a role for testing.
static Role role({
String id = 'test-role',
required Domain domain,
String category = 'general',
required Action action,
}) {
return Role(
id: id,
name: '${domain.value}.$category:${action.name}',
domain: domain,
category: category,
action: action,
);
}
}