import 'package:flutter_test/flutter_test.dart'; import 'package:tatlock_ui/routing/room_registry.dart'; import 'harness/test_harness.dart'; void main() { final harness = TestHarness(); setUp(() => harness.setUp()); tearDown(() => harness.tearDown()); group('Room Registry', () { test('is initialized with all rooms', () { expect(roomRegistry.all.isNotEmpty, isTrue); expect(roomRegistry.all.length, greaterThanOrEqualTo(5)); }); test('contains expected rooms', () { final roomIds = roomRegistry.all.map((r) => r.id).toList(); expect(roomIds, contains('front-hall')); expect(roomIds, contains('control-room')); expect(roomIds, contains('security')); expect(roomIds, contains('parlor')); expect(roomIds, contains('media-room')); }); test('returns correct index for route', () { expect(roomRegistry.indexOfRoute('/front-hall'), 0); expect(roomRegistry.indexOfRoute('/control-room/containers'), 1); expect(roomRegistry.indexOfRoute('/security/users'), 2); expect(roomRegistry.indexOfRoute('/parlor'), 3); expect(roomRegistry.indexOfRoute('/media-room'), 4); }); test('finds room by ID', () { final frontHall = roomRegistry.byId('front-hall'); expect(frontHall, isNotNull); expect(frontHall!.label, 'Front Hall'); expect(frontHall.defaultRoute, '/front-hall'); final controlRoom = roomRegistry.byId('control-room'); expect(controlRoom, isNotNull); expect(controlRoom!.label, 'Control Room'); final nonExistent = roomRegistry.byId('non-existent'); expect(nonExistent, isNull); }); test('returns default route for room', () { final frontHall = roomRegistry.byId('front-hall'); expect(frontHall?.defaultRoute, '/front-hall'); final controlRoom = roomRegistry.byId('control-room'); expect(controlRoom?.defaultRoute, '/control-room/containers'); final security = roomRegistry.byId('security'); expect(security?.defaultRoute, '/security/users'); }); }); group('Test Harness', () { test('provides guest auth state by default', () async { harness.givenGuestUser(); expect(MockAuth.guest.isAuthenticated, isFalse); }); test('provides authenticated user state', () { harness.givenAuthenticatedUser(name: 'John Doe'); // The auth state is set internally, verified via wrap() }); test('provides admin user state', () { harness.givenAdminUser(); final adminState = MockAuth.admin(); expect(adminState.isGlobalAdmin, isTrue); }); test('mock API client registers responses', () { harness.givenContainers(); // Verify the mock is registered (would be called during widget tests) }); }); group('Mock Auth', () { test('guest state is not authenticated', () { expect(MockAuth.guest.isAuthenticated, isFalse); expect(MockAuth.guest.accessToken, isNull); }); test('user state is authenticated', () { final user = MockAuth.user(); expect(user.isAuthenticated, isTrue); expect(user.accessToken, isNotNull); expect(user.userName, 'Test User'); }); test('admin state has admin role', () { final admin = MockAuth.admin(); expect(admin.isAuthenticated, isTrue); expect(admin.isGlobalAdmin, isTrue); expect(admin.roles.length, 1); }); test('expired state has past expiry', () { final expired = MockAuth.expired(); expect(expired.isTokenExpired, isTrue); }); }); group('Mock API Client', () { test('returns registered response', () async { final client = MockApiClient(); client.whenGet('/test', {'message': 'hello'}); final response = await client.dio.get>('/test'); expect(response.data?['message'], 'hello'); }); test('returns 404 for unregistered endpoint', () async { final client = MockApiClient(); expect( () => client.dio.get('/unknown'), throwsA(isA()), ); }); test('records requests', () async { final client = MockApiClient(); client.whenGet('/test1', {}); client.whenGet('/test2', {}); await client.dio.get('/test1'); await client.dio.get('/test2'); expect(client.requests.length, 2); expect(client.requests[0].path, '/test1'); expect(client.requests[1].path, '/test2'); }); test('supports error responses', () async { final client = MockApiClient(); client.whenError(method: 'GET', path: '/error', statusCode: 500); expect( () => client.dio.get('/error'), throwsA(isA()), ); }); }); group('Fixtures', () { test('provides container data', () { expect(Fixtures.containers.length, 4); expect(Fixtures.containers[0]['Names'], contains('/nginx-proxy')); }); test('provides proxy host data', () { expect(Fixtures.proxyHosts.length, 3); expect(Fixtures.proxyHosts[0]['domain_names'], contains('home.schweitz.net')); }); test('provides user data', () { expect(Fixtures.users.length, 3); expect(Fixtures.users[0]['name'], 'Admin User'); }); test('provides group data', () { expect(Fixtures.groups.length, 3); expect(Fixtures.groups[0]['name'], 'admins'); }); test('provides auth sync response', () { final response = Fixtures.authSyncResponse(name: 'Test'); expect(response['name'], 'Test'); expect(response['preferences'], isNotNull); }); }); }