智慧水务管理系统 - 精河县供水工程综合管理平台

auth_service_test.dart 1.1KB

123456789101112131415161718192021222324252627282930313233343536
  1. import 'package:flutter_test/flutter_test.dart';
  2. import 'package:shared_preferences/shared_preferences.dart';
  3. import 'package:water_management_system/services/auth_service.dart';
  4. void main() {
  5. group('AuthService', () {
  6. late AuthService authService;
  7. setUp(() {
  8. SharedPreferences.setMockInitialValues({});
  9. authService = AuthService();
  10. });
  11. test('initial state should not be authenticated', () {
  12. expect(authService.isAuthenticated, false);
  13. expect(authService.token, null);
  14. expect(authService.isLoading, false);
  15. });
  16. test('login failure should keep not authenticated', () async {
  17. final result = await authService.login('invalid', 'wrong');
  18. expect(result, false);
  19. expect(authService.isAuthenticated, false);
  20. });
  21. test('logout should clear auth data', () async {
  22. await authService.logout();
  23. expect(authService.isAuthenticated, false);
  24. expect(authService.token, null);
  25. });
  26. test('isLoading should be false after operation', () async {
  27. await authService.login('test', 'test');
  28. expect(authService.isLoading, false);
  29. });
  30. });
  31. }