Initial commit: unionflow-mobile-apps
Application Flutter complète (sans build artifacts). Signed-off-by: lions dev Team
This commit is contained in:
268
test/features/dashboard/dashboard_test.dart
Normal file
268
test/features/dashboard/dashboard_test.dart
Normal file
@@ -0,0 +1,268 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
// Imports du dashboard (à adapter selon la structure réelle)
|
||||
// import 'package:unionflow_mobile_apps/features/dashboard/domain/entities/dashboard_entity.dart';
|
||||
// import 'package:unionflow_mobile_apps/features/dashboard/domain/usecases/get_dashboard_data.dart';
|
||||
// import 'package:unionflow_mobile_apps/features/dashboard/presentation/bloc/dashboard_bloc.dart';
|
||||
// import 'package:unionflow_mobile_apps/core/error/failures.dart';
|
||||
|
||||
/// Tests unitaires pour le Dashboard UnionFlow
|
||||
void main() {
|
||||
group('Dashboard Tests', () {
|
||||
|
||||
group('DashboardEntity', () {
|
||||
test('should create dashboard entity with correct properties', () {
|
||||
// TODO: Implémenter le test d'entité
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
|
||||
test('should calculate today events count correctly', () {
|
||||
// TODO: Implémenter le test de calcul d'événements
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
|
||||
test('should format contribution amount correctly', () {
|
||||
// TODO: Implémenter le test de formatage
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
});
|
||||
|
||||
group('DashboardRepository', () {
|
||||
test('should return dashboard data when call is successful', () async {
|
||||
// TODO: Implémenter le test de repository
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
|
||||
test('should return failure when call fails', () async {
|
||||
// TODO: Implémenter le test d'échec
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
});
|
||||
|
||||
group('GetDashboardData UseCase', () {
|
||||
test('should get dashboard data from repository', () async {
|
||||
// TODO: Implémenter le test de use case
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
|
||||
test('should return failure when repository fails', () async {
|
||||
// TODO: Implémenter le test d'échec use case
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
});
|
||||
|
||||
group('DashboardBloc', () {
|
||||
// TODO: Implémenter les tests BLoC quand les mocks seront prêts
|
||||
test('should be implemented', () {
|
||||
// Placeholder test
|
||||
expect(true, isTrue);
|
||||
});
|
||||
});
|
||||
|
||||
group('DashboardMockDataSource', () {
|
||||
test('should generate realistic mock stats', () async {
|
||||
// TODO: Tester la génération de données mock
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
|
||||
test('should generate mock activities with correct format', () async {
|
||||
// TODO: Tester la génération d'activités
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
|
||||
test('should generate mock events with future dates', () async {
|
||||
// TODO: Tester la génération d'événements
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
});
|
||||
|
||||
group('DashboardConfig', () {
|
||||
test('should have correct default values', () {
|
||||
// TODO: Tester la configuration par défaut
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
|
||||
test('should return correct API endpoints', () {
|
||||
// TODO: Tester les endpoints API
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
|
||||
test('should return correct theme colors', () {
|
||||
// TODO: Tester les couleurs du thème
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
});
|
||||
|
||||
group('DashboardTheme', () {
|
||||
test('should have royal blue and teal blue colors', () {
|
||||
// TODO: Tester les couleurs du design system
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
|
||||
test('should have correct spacing values', () {
|
||||
// TODO: Tester les espacements
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
|
||||
test('should have correct typography styles', () {
|
||||
// TODO: Tester la typographie
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
});
|
||||
|
||||
group('Performance Tests', () {
|
||||
test('should handle large datasets efficiently', () async {
|
||||
// TODO: Tester les performances avec de gros datasets
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
|
||||
test('should not exceed memory limits', () async {
|
||||
// TODO: Tester l'utilisation mémoire
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
|
||||
test('should complete operations within time limits', () async {
|
||||
// TODO: Tester les performances temporelles
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
});
|
||||
|
||||
group('Integration Tests', () {
|
||||
test('should integrate with backend API correctly', () async {
|
||||
// TODO: Tester l'intégration backend
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
|
||||
test('should handle network errors gracefully', () async {
|
||||
// TODO: Tester la gestion d'erreurs réseau
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
|
||||
test('should cache data appropriately', () async {
|
||||
// TODO: Tester le cache
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
});
|
||||
|
||||
group('Widget Tests', () {
|
||||
testWidgets('ConnectedStatsCard should display stats correctly', (tester) async {
|
||||
// TODO: Tester le widget de statistiques
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
|
||||
testWidgets('DashboardChartWidget should render charts', (tester) async {
|
||||
// TODO: Tester le widget de graphiques
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
|
||||
testWidgets('RealTimeMetricsWidget should animate correctly', (tester) async {
|
||||
// TODO: Tester les animations des métriques
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
|
||||
testWidgets('DashboardSearchWidget should handle search input', (tester) async {
|
||||
// TODO: Tester le widget de recherche
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
});
|
||||
|
||||
group('Error Handling Tests', () {
|
||||
test('should handle server errors gracefully', () async {
|
||||
// TODO: Tester la gestion d'erreurs serveur
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
|
||||
test('should handle network timeouts', () async {
|
||||
// TODO: Tester les timeouts réseau
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
|
||||
test('should handle malformed data', () async {
|
||||
// TODO: Tester les données malformées
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
});
|
||||
|
||||
group('Accessibility Tests', () {
|
||||
testWidgets('should have proper semantic labels', (tester) async {
|
||||
// TODO: Tester l'accessibilité
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
|
||||
testWidgets('should support screen readers', (tester) async {
|
||||
// TODO: Tester le support des lecteurs d'écran
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
|
||||
testWidgets('should have sufficient color contrast', (tester) async {
|
||||
// TODO: Tester le contraste des couleurs
|
||||
expect(true, true); // Placeholder
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// Mocks pour les tests
|
||||
class MockDashboardRepository extends Mock {
|
||||
// TODO: Implémenter les mocks
|
||||
}
|
||||
|
||||
class MockGetDashboardData extends Mock {
|
||||
// TODO: Implémenter les mocks
|
||||
}
|
||||
|
||||
class MockDashboardRemoteDataSource extends Mock {
|
||||
// TODO: Implémenter les mocks
|
||||
}
|
||||
|
||||
class MockNetworkInfo extends Mock {
|
||||
// TODO: Implémenter les mocks
|
||||
}
|
||||
|
||||
/// Helpers pour les tests
|
||||
class DashboardTestHelpers {
|
||||
static createMockDashboardEntity() {
|
||||
// TODO: Créer une entité mock pour les tests
|
||||
return null;
|
||||
}
|
||||
|
||||
static createMockDashboardStats() {
|
||||
// TODO: Créer des stats mock pour les tests
|
||||
return null;
|
||||
}
|
||||
|
||||
static createMockActivities() {
|
||||
// TODO: Créer des activités mock pour les tests
|
||||
return [];
|
||||
}
|
||||
|
||||
static createMockEvents() {
|
||||
// TODO: Créer des événements mock pour les tests
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/// Matchers personnalisés pour les tests
|
||||
class DashboardMatchers {
|
||||
static Matcher hasValidDashboardData() {
|
||||
return predicate((dynamic data) {
|
||||
// TODO: Implémenter la validation des données dashboard
|
||||
return true;
|
||||
}, 'has valid dashboard data');
|
||||
}
|
||||
|
||||
static Matcher hasCorrectThemeColors() {
|
||||
return predicate((dynamic theme) {
|
||||
// TODO: Implémenter la validation des couleurs
|
||||
return true;
|
||||
}, 'has correct theme colors');
|
||||
}
|
||||
|
||||
static Matcher isWithinPerformanceLimits() {
|
||||
return predicate((dynamic metrics) {
|
||||
// TODO: Implémenter la validation des performances
|
||||
return true;
|
||||
}, 'is within performance limits');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
/// Tests unitaires pour GetCompteAdherent use case
|
||||
library get_compte_adherent_test;
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:unionflow_mobile_apps/features/dashboard/domain/usecases/get_compte_adherent.dart';
|
||||
import 'package:unionflow_mobile_apps/features/dashboard/domain/repositories/dashboard_repository.dart';
|
||||
import 'package:unionflow_mobile_apps/features/dashboard/domain/entities/compte_adherent_entity.dart';
|
||||
import 'package:unionflow_mobile_apps/core/error/failures.dart';
|
||||
import 'package:unionflow_mobile_apps/core/usecases/usecase.dart';
|
||||
|
||||
@GenerateMocks([DashboardRepository])
|
||||
import 'get_compte_adherent_test.mocks.dart';
|
||||
|
||||
void main() {
|
||||
late GetCompteAdherent useCase;
|
||||
late MockDashboardRepository mockRepository;
|
||||
|
||||
setUp(() {
|
||||
mockRepository = MockDashboardRepository();
|
||||
useCase = GetCompteAdherent(mockRepository);
|
||||
});
|
||||
|
||||
group('GetCompteAdherent Use Case', () {
|
||||
final tCompteAdherent = CompteAdherentEntity(
|
||||
numeroMembre: 'M-2024-001',
|
||||
nomComplet: 'Amadou Diallo',
|
||||
organisationNom: 'Association Alpha',
|
||||
dateAdhesion: DateTime(2024, 1, 15),
|
||||
statutCompte: 'ACTIF',
|
||||
soldeCotisations: 50000.0,
|
||||
soldeEpargne: 125000.0,
|
||||
soldeBloque: 15000.0,
|
||||
soldeTotalDisponible: 160000.0,
|
||||
encoursCreditTotal: 75000.0,
|
||||
capaciteEmprunt: 200000.0,
|
||||
nombreCotisationsPayees: 12,
|
||||
nombreCotisationsTotal: 12,
|
||||
nombreCotisationsEnRetard: 0,
|
||||
engagementRate: 1.0,
|
||||
nombreComptesEpargne: 2,
|
||||
dateCalcul: DateTime(2024, 12, 15),
|
||||
);
|
||||
|
||||
test('should return compte adherent successfully', () async {
|
||||
// Arrange
|
||||
when(mockRepository.getCompteAdherent())
|
||||
.thenAnswer((_) async => Right(tCompteAdherent));
|
||||
|
||||
// Act
|
||||
final result = await useCase(NoParams());
|
||||
|
||||
// Assert
|
||||
expect(result, Right(tCompteAdherent));
|
||||
result.fold(
|
||||
(failure) => fail('Should not return failure'),
|
||||
(compte) {
|
||||
expect(compte.numeroMembre, equals('M-2024-001'));
|
||||
expect(compte.nomComplet, equals('Amadou Diallo'));
|
||||
expect(compte.soldeTotalDisponible, equals(160000.0));
|
||||
expect(compte.capaciteEmprunt, equals(200000.0));
|
||||
},
|
||||
);
|
||||
verify(mockRepository.getCompteAdherent());
|
||||
verifyNoMoreInteractions(mockRepository);
|
||||
});
|
||||
|
||||
test('should return compte with multiple epargne accounts', () async {
|
||||
// Arrange
|
||||
when(mockRepository.getCompteAdherent())
|
||||
.thenAnswer((_) async => Right(tCompteAdherent));
|
||||
|
||||
// Act
|
||||
final result = await useCase(NoParams());
|
||||
|
||||
// Assert
|
||||
result.fold(
|
||||
(failure) => fail('Should not return failure'),
|
||||
(compte) {
|
||||
expect(compte.nombreComptesEpargne, equals(2));
|
||||
expect(compte.soldeEpargne, equals(125000.0));
|
||||
expect(compte.engagementRate, equals(1.0));
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test('should return compte with overdue contributions', () async {
|
||||
// Arrange
|
||||
final compteWithOverdue = CompteAdherentEntity(
|
||||
numeroMembre: 'M-2024-002',
|
||||
nomComplet: 'Fatou Ndiaye',
|
||||
statutCompte: 'ACTIF',
|
||||
soldeCotisations: 25000.0,
|
||||
soldeEpargne: 50000.0,
|
||||
soldeBloque: 0.0,
|
||||
soldeTotalDisponible: 75000.0,
|
||||
encoursCreditTotal: 0.0,
|
||||
capaciteEmprunt: 100000.0,
|
||||
nombreCotisationsPayees: 8,
|
||||
nombreCotisationsTotal: 12,
|
||||
nombreCotisationsEnRetard: 4,
|
||||
engagementRate: 0.67,
|
||||
nombreComptesEpargne: 1,
|
||||
dateCalcul: DateTime(2024, 12, 15),
|
||||
);
|
||||
when(mockRepository.getCompteAdherent())
|
||||
.thenAnswer((_) async => Right(compteWithOverdue));
|
||||
|
||||
// Act
|
||||
final result = await useCase(NoParams());
|
||||
|
||||
// Assert
|
||||
result.fold(
|
||||
(failure) => fail('Should not return failure'),
|
||||
(compte) {
|
||||
expect(compte.nombreCotisationsEnRetard, equals(4));
|
||||
expect(compte.engagementRate, lessThan(1.0));
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test('should return ServerFailure when repository fails', () async {
|
||||
// Arrange
|
||||
final tFailure = ServerFailure('Erreur serveur');
|
||||
when(mockRepository.getCompteAdherent())
|
||||
.thenAnswer((_) async => Left(tFailure));
|
||||
|
||||
// Act
|
||||
final result = await useCase(NoParams());
|
||||
|
||||
// Assert
|
||||
expect(result, Left(tFailure));
|
||||
result.fold(
|
||||
(failure) => expect(failure, isA<ServerFailure>()),
|
||||
(compte) => fail('Should not return compte'),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
// Mocks generated by Mockito 5.4.4 from annotations
|
||||
// in unionflow_mobile_apps/test/features/dashboard/domain/usecases/get_compte_adherent_test.dart.
|
||||
// Do not manually edit this file.
|
||||
|
||||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||
import 'dart:async' as _i4;
|
||||
|
||||
import 'package:dartz/dartz.dart' as _i2;
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:unionflow_mobile_apps/core/error/failures.dart' as _i5;
|
||||
import 'package:unionflow_mobile_apps/features/dashboard/domain/entities/compte_adherent_entity.dart'
|
||||
as _i6;
|
||||
import 'package:unionflow_mobile_apps/features/dashboard/domain/entities/dashboard_entity.dart'
|
||||
as _i7;
|
||||
import 'package:unionflow_mobile_apps/features/dashboard/domain/repositories/dashboard_repository.dart'
|
||||
as _i3;
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: avoid_redundant_argument_values
|
||||
// ignore_for_file: avoid_setters_without_getters
|
||||
// ignore_for_file: comment_references
|
||||
// ignore_for_file: deprecated_member_use
|
||||
// ignore_for_file: deprecated_member_use_from_same_package
|
||||
// ignore_for_file: implementation_imports
|
||||
// ignore_for_file: invalid_use_of_visible_for_testing_member
|
||||
// ignore_for_file: prefer_const_constructors
|
||||
// ignore_for_file: unnecessary_parenthesis
|
||||
// ignore_for_file: camel_case_types
|
||||
// ignore_for_file: subtype_of_sealed_class
|
||||
|
||||
class _FakeEither_0<L, R> extends _i1.SmartFake implements _i2.Either<L, R> {
|
||||
_FakeEither_0(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
/// A class which mocks [DashboardRepository].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockDashboardRepository extends _i1.Mock
|
||||
implements _i3.DashboardRepository {
|
||||
MockDashboardRepository() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.Either<_i5.Failure, _i6.CompteAdherentEntity>>
|
||||
getCompteAdherent() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getCompteAdherent,
|
||||
[],
|
||||
),
|
||||
returnValue: _i4.Future<
|
||||
_i2.Either<_i5.Failure, _i6.CompteAdherentEntity>>.value(
|
||||
_FakeEither_0<_i5.Failure, _i6.CompteAdherentEntity>(
|
||||
this,
|
||||
Invocation.method(
|
||||
#getCompteAdherent,
|
||||
[],
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.Either<_i5.Failure, _i6.CompteAdherentEntity>>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.Either<_i5.Failure, _i7.DashboardEntity>> getDashboardData(
|
||||
String? organizationId,
|
||||
String? userId,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getDashboardData,
|
||||
[
|
||||
organizationId,
|
||||
userId,
|
||||
],
|
||||
),
|
||||
returnValue:
|
||||
_i4.Future<_i2.Either<_i5.Failure, _i7.DashboardEntity>>.value(
|
||||
_FakeEither_0<_i5.Failure, _i7.DashboardEntity>(
|
||||
this,
|
||||
Invocation.method(
|
||||
#getDashboardData,
|
||||
[
|
||||
organizationId,
|
||||
userId,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.Either<_i5.Failure, _i7.DashboardEntity>>);
|
||||
|
||||
@override
|
||||
_i4.Future<
|
||||
_i2.Either<_i5.Failure, _i7.DashboardStatsEntity>> getDashboardStats(
|
||||
String? organizationId,
|
||||
String? userId,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getDashboardStats,
|
||||
[
|
||||
organizationId,
|
||||
userId,
|
||||
],
|
||||
),
|
||||
returnValue:
|
||||
_i4.Future<_i2.Either<_i5.Failure, _i7.DashboardStatsEntity>>.value(
|
||||
_FakeEither_0<_i5.Failure, _i7.DashboardStatsEntity>(
|
||||
this,
|
||||
Invocation.method(
|
||||
#getDashboardStats,
|
||||
[
|
||||
organizationId,
|
||||
userId,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.Either<_i5.Failure, _i7.DashboardStatsEntity>>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.Either<_i5.Failure, List<_i7.RecentActivityEntity>>>
|
||||
getRecentActivities(
|
||||
String? organizationId,
|
||||
String? userId, {
|
||||
int? limit = 10,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getRecentActivities,
|
||||
[
|
||||
organizationId,
|
||||
userId,
|
||||
],
|
||||
{#limit: limit},
|
||||
),
|
||||
returnValue: _i4.Future<
|
||||
_i2
|
||||
.Either<_i5.Failure, List<_i7.RecentActivityEntity>>>.value(
|
||||
_FakeEither_0<_i5.Failure, List<_i7.RecentActivityEntity>>(
|
||||
this,
|
||||
Invocation.method(
|
||||
#getRecentActivities,
|
||||
[
|
||||
organizationId,
|
||||
userId,
|
||||
],
|
||||
{#limit: limit},
|
||||
),
|
||||
)),
|
||||
) as _i4
|
||||
.Future<_i2.Either<_i5.Failure, List<_i7.RecentActivityEntity>>>);
|
||||
|
||||
@override
|
||||
_i4.Future<
|
||||
_i2.Either<_i5.Failure, List<_i7.UpcomingEventEntity>>> getUpcomingEvents(
|
||||
String? organizationId,
|
||||
String? userId, {
|
||||
int? limit = 5,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getUpcomingEvents,
|
||||
[
|
||||
organizationId,
|
||||
userId,
|
||||
],
|
||||
{#limit: limit},
|
||||
),
|
||||
returnValue: _i4.Future<
|
||||
_i2.Either<_i5.Failure, List<_i7.UpcomingEventEntity>>>.value(
|
||||
_FakeEither_0<_i5.Failure, List<_i7.UpcomingEventEntity>>(
|
||||
this,
|
||||
Invocation.method(
|
||||
#getUpcomingEvents,
|
||||
[
|
||||
organizationId,
|
||||
userId,
|
||||
],
|
||||
{#limit: limit},
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.Either<_i5.Failure, List<_i7.UpcomingEventEntity>>>);
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
/// Tests unitaires pour GetDashboardData use case
|
||||
library get_dashboard_data_test;
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:unionflow_mobile_apps/features/dashboard/domain/usecases/get_dashboard_data.dart';
|
||||
import 'package:unionflow_mobile_apps/features/dashboard/domain/repositories/dashboard_repository.dart';
|
||||
import 'package:unionflow_mobile_apps/features/dashboard/domain/entities/dashboard_entity.dart';
|
||||
import 'package:unionflow_mobile_apps/core/error/failures.dart';
|
||||
|
||||
@GenerateMocks([DashboardRepository])
|
||||
import 'get_dashboard_data_test.mocks.dart';
|
||||
|
||||
void main() {
|
||||
late GetDashboardData useCase;
|
||||
late MockDashboardRepository mockRepository;
|
||||
|
||||
setUp(() {
|
||||
mockRepository = MockDashboardRepository();
|
||||
useCase = GetDashboardData(mockRepository);
|
||||
});
|
||||
|
||||
group('GetDashboardData Use Case', () {
|
||||
const tOrgId = 'org-123';
|
||||
const tUserId = 'user-456';
|
||||
final tParams = GetDashboardDataParams(
|
||||
organizationId: tOrgId,
|
||||
userId: tUserId,
|
||||
);
|
||||
|
||||
final tDashboardStats = DashboardStatsEntity(
|
||||
totalMembers: 250,
|
||||
activeMembers: 180,
|
||||
totalEvents: 45,
|
||||
upcomingEvents: 12,
|
||||
totalContributions: 1200,
|
||||
totalContributionAmount: 5750000.0,
|
||||
contributionsAmountOnly: 3250000.0,
|
||||
pendingRequests: 8,
|
||||
completedProjects: 23,
|
||||
monthlyGrowth: 0.15,
|
||||
engagementRate: 0.72,
|
||||
lastUpdated: DateTime(2024, 12, 15, 10, 30),
|
||||
totalOrganizations: 5,
|
||||
organizationTypeDistribution: {
|
||||
'association': 3,
|
||||
'cooperative': 2,
|
||||
},
|
||||
);
|
||||
|
||||
test('should return dashboard stats successfully', () async {
|
||||
// Arrange
|
||||
when(mockRepository.getDashboardStats(tOrgId, tUserId))
|
||||
.thenAnswer((_) async => Right(tDashboardStats));
|
||||
|
||||
// Act
|
||||
final result = await GetDashboardStats(mockRepository)(
|
||||
GetDashboardStatsParams(organizationId: tOrgId, userId: tUserId),
|
||||
);
|
||||
|
||||
// Assert
|
||||
expect(result, Right(tDashboardStats));
|
||||
result.fold(
|
||||
(failure) => fail('Should not return failure'),
|
||||
(stats) {
|
||||
expect(stats.totalMembers, equals(250));
|
||||
expect(stats.activeMembers, equals(180));
|
||||
expect(stats.totalContributionAmount, equals(5750000.0));
|
||||
expect(stats.monthlyGrowth, equals(0.15));
|
||||
expect(stats.hasGrowth, isTrue);
|
||||
},
|
||||
);
|
||||
verify(mockRepository.getDashboardStats(tOrgId, tUserId));
|
||||
verifyNoMoreInteractions(mockRepository);
|
||||
});
|
||||
|
||||
test('should return stats with high engagement rate', () async {
|
||||
// Arrange
|
||||
when(mockRepository.getDashboardStats(tOrgId, tUserId))
|
||||
.thenAnswer((_) async => Right(tDashboardStats));
|
||||
|
||||
// Act
|
||||
final result = await GetDashboardStats(mockRepository)(
|
||||
GetDashboardStatsParams(organizationId: tOrgId, userId: tUserId),
|
||||
);
|
||||
|
||||
// Assert
|
||||
result.fold(
|
||||
(failure) => fail('Should not return failure'),
|
||||
(stats) {
|
||||
expect(stats.engagementRate, equals(0.72));
|
||||
expect(stats.isHighEngagement, isTrue);
|
||||
expect(stats.memberActivityRate, closeTo(0.72, 0.01));
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test('should format contribution amount correctly', () async {
|
||||
// Arrange
|
||||
when(mockRepository.getDashboardStats(tOrgId, tUserId))
|
||||
.thenAnswer((_) async => Right(tDashboardStats));
|
||||
|
||||
// Act
|
||||
final result = await GetDashboardStats(mockRepository)(
|
||||
GetDashboardStatsParams(organizationId: tOrgId, userId: tUserId),
|
||||
);
|
||||
|
||||
// Assert
|
||||
result.fold(
|
||||
(failure) => fail('Should not return failure'),
|
||||
(stats) {
|
||||
expect(stats.formattedContributionAmount, equals('5.8M'));
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test('should return ServerFailure when repository fails', () async {
|
||||
// Arrange
|
||||
final tFailure = ServerFailure('Erreur serveur');
|
||||
when(mockRepository.getDashboardStats(any, any))
|
||||
.thenAnswer((_) async => Left(tFailure));
|
||||
|
||||
// Act
|
||||
final result = await GetDashboardStats(mockRepository)(
|
||||
GetDashboardStatsParams(organizationId: tOrgId, userId: tUserId),
|
||||
);
|
||||
|
||||
// Assert
|
||||
expect(result, Left(tFailure));
|
||||
result.fold(
|
||||
(failure) => expect(failure, isA<ServerFailure>()),
|
||||
(stats) => fail('Should not return stats'),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
// Mocks generated by Mockito 5.4.4 from annotations
|
||||
// in unionflow_mobile_apps/test/features/dashboard/domain/usecases/get_dashboard_data_test.dart.
|
||||
// Do not manually edit this file.
|
||||
|
||||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||
import 'dart:async' as _i4;
|
||||
|
||||
import 'package:dartz/dartz.dart' as _i2;
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:unionflow_mobile_apps/core/error/failures.dart' as _i5;
|
||||
import 'package:unionflow_mobile_apps/features/dashboard/domain/entities/compte_adherent_entity.dart'
|
||||
as _i6;
|
||||
import 'package:unionflow_mobile_apps/features/dashboard/domain/entities/dashboard_entity.dart'
|
||||
as _i7;
|
||||
import 'package:unionflow_mobile_apps/features/dashboard/domain/repositories/dashboard_repository.dart'
|
||||
as _i3;
|
||||
|
||||
// ignore_for_file: type=lint
|
||||
// ignore_for_file: avoid_redundant_argument_values
|
||||
// ignore_for_file: avoid_setters_without_getters
|
||||
// ignore_for_file: comment_references
|
||||
// ignore_for_file: deprecated_member_use
|
||||
// ignore_for_file: deprecated_member_use_from_same_package
|
||||
// ignore_for_file: implementation_imports
|
||||
// ignore_for_file: invalid_use_of_visible_for_testing_member
|
||||
// ignore_for_file: prefer_const_constructors
|
||||
// ignore_for_file: unnecessary_parenthesis
|
||||
// ignore_for_file: camel_case_types
|
||||
// ignore_for_file: subtype_of_sealed_class
|
||||
|
||||
class _FakeEither_0<L, R> extends _i1.SmartFake implements _i2.Either<L, R> {
|
||||
_FakeEither_0(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
/// A class which mocks [DashboardRepository].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockDashboardRepository extends _i1.Mock
|
||||
implements _i3.DashboardRepository {
|
||||
MockDashboardRepository() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.Either<_i5.Failure, _i6.CompteAdherentEntity>>
|
||||
getCompteAdherent() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getCompteAdherent,
|
||||
[],
|
||||
),
|
||||
returnValue: _i4.Future<
|
||||
_i2.Either<_i5.Failure, _i6.CompteAdherentEntity>>.value(
|
||||
_FakeEither_0<_i5.Failure, _i6.CompteAdherentEntity>(
|
||||
this,
|
||||
Invocation.method(
|
||||
#getCompteAdherent,
|
||||
[],
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.Either<_i5.Failure, _i6.CompteAdherentEntity>>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.Either<_i5.Failure, _i7.DashboardEntity>> getDashboardData(
|
||||
String? organizationId,
|
||||
String? userId,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getDashboardData,
|
||||
[
|
||||
organizationId,
|
||||
userId,
|
||||
],
|
||||
),
|
||||
returnValue:
|
||||
_i4.Future<_i2.Either<_i5.Failure, _i7.DashboardEntity>>.value(
|
||||
_FakeEither_0<_i5.Failure, _i7.DashboardEntity>(
|
||||
this,
|
||||
Invocation.method(
|
||||
#getDashboardData,
|
||||
[
|
||||
organizationId,
|
||||
userId,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.Either<_i5.Failure, _i7.DashboardEntity>>);
|
||||
|
||||
@override
|
||||
_i4.Future<
|
||||
_i2.Either<_i5.Failure, _i7.DashboardStatsEntity>> getDashboardStats(
|
||||
String? organizationId,
|
||||
String? userId,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getDashboardStats,
|
||||
[
|
||||
organizationId,
|
||||
userId,
|
||||
],
|
||||
),
|
||||
returnValue:
|
||||
_i4.Future<_i2.Either<_i5.Failure, _i7.DashboardStatsEntity>>.value(
|
||||
_FakeEither_0<_i5.Failure, _i7.DashboardStatsEntity>(
|
||||
this,
|
||||
Invocation.method(
|
||||
#getDashboardStats,
|
||||
[
|
||||
organizationId,
|
||||
userId,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.Either<_i5.Failure, _i7.DashboardStatsEntity>>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.Either<_i5.Failure, List<_i7.RecentActivityEntity>>>
|
||||
getRecentActivities(
|
||||
String? organizationId,
|
||||
String? userId, {
|
||||
int? limit = 10,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getRecentActivities,
|
||||
[
|
||||
organizationId,
|
||||
userId,
|
||||
],
|
||||
{#limit: limit},
|
||||
),
|
||||
returnValue: _i4.Future<
|
||||
_i2
|
||||
.Either<_i5.Failure, List<_i7.RecentActivityEntity>>>.value(
|
||||
_FakeEither_0<_i5.Failure, List<_i7.RecentActivityEntity>>(
|
||||
this,
|
||||
Invocation.method(
|
||||
#getRecentActivities,
|
||||
[
|
||||
organizationId,
|
||||
userId,
|
||||
],
|
||||
{#limit: limit},
|
||||
),
|
||||
)),
|
||||
) as _i4
|
||||
.Future<_i2.Either<_i5.Failure, List<_i7.RecentActivityEntity>>>);
|
||||
|
||||
@override
|
||||
_i4.Future<
|
||||
_i2.Either<_i5.Failure, List<_i7.UpcomingEventEntity>>> getUpcomingEvents(
|
||||
String? organizationId,
|
||||
String? userId, {
|
||||
int? limit = 5,
|
||||
}) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getUpcomingEvents,
|
||||
[
|
||||
organizationId,
|
||||
userId,
|
||||
],
|
||||
{#limit: limit},
|
||||
),
|
||||
returnValue: _i4.Future<
|
||||
_i2.Either<_i5.Failure, List<_i7.UpcomingEventEntity>>>.value(
|
||||
_FakeEither_0<_i5.Failure, List<_i7.UpcomingEventEntity>>(
|
||||
this,
|
||||
Invocation.method(
|
||||
#getUpcomingEvents,
|
||||
[
|
||||
organizationId,
|
||||
userId,
|
||||
],
|
||||
{#limit: limit},
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.Either<_i5.Failure, List<_i7.UpcomingEventEntity>>>);
|
||||
}
|
||||
Reference in New Issue
Block a user