/
opt
/
canhelp
/
apps
/
mobile
/
test
/
routing
/
/opt/canhelp/apps/mobile/test/routing
mkdir
upload
Name
Size
Mode
Actions
auth_redirect_test.dart
2898
0644
edit
dl
rm
Edit:
/opt/canhelp/apps/mobile/test/routing/auth_redirect_test.dart
(2898B)
import 'package:canhelp/routing/auth_redirect.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { group('resolveAuthRedirect', () { test('does not redirect while auth state is loading', () { expect( resolveAuthRedirect( isAuthLoading: true, isAuthenticated: false, matchedLocation: '/profile', ), isNull, ); }); group('guest smoke paths', () { test('allows public routes', () { expect( resolveAuthRedirect( isAuthLoading: false, isAuthenticated: false, matchedLocation: '/', ), isNull, ); expect( resolveAuthRedirect( isAuthLoading: false, isAuthenticated: false, matchedLocation: '/tasks', ), isNull, ); expect( resolveAuthRedirect( isAuthLoading: false, isAuthenticated: false, matchedLocation: '/specialists/42', ), isNull, ); }); test('redirects protected routes to login', () { for (final path in defaultProtectedPaths) { expect( resolveAuthRedirect( isAuthLoading: false, isAuthenticated: false, matchedLocation: path, ), '/login', ); } expect( resolveAuthRedirect( isAuthLoading: false, isAuthenticated: false, matchedLocation: '/profile/topup', ), '/login', ); }); }); group('authenticated customer/specialist smoke paths', () { test('allows protected routes when user is authenticated', () { expect( resolveAuthRedirect( isAuthLoading: false, isAuthenticated: true, matchedLocation: '/dashboard', ), isNull, ); expect( resolveAuthRedirect( isAuthLoading: false, isAuthenticated: true, matchedLocation: '/profile/reviews', ), isNull, ); expect( resolveAuthRedirect( isAuthLoading: false, isAuthenticated: true, matchedLocation: '/chat', ), isNull, ); }); test('redirects auth pages to home when user is authenticated', () { const authPages = [ '/login', '/register', '/forgot-password', '/reset-password', ]; for (final path in authPages) { expect( resolveAuthRedirect( isAuthLoading: false, isAuthenticated: true, matchedLocation: path, ), '/', ); } }); }); }); }
Save
cmd:
run