feat(tests): test coverage is 70.5

This commit is contained in:
misha
2026-01-26 16:38:15 +03:00
parent 92205c09d6
commit 29589ef6fd
49 changed files with 2690 additions and 18 deletions

View File

@@ -0,0 +1,90 @@
import 'package:eatvio_app/features/notifications/models/notification_model.dart';
import 'package:eatvio_app/features/notifications/presentation/notifications_cubit/notifications_state.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('NotificationsState', () {
test('creates initial NotificationsState', () {
const state = NotificationsState();
expect(state, isA<NotificationsState>());
});
test('creates empty NotificationsState', () {
const state = NotificationsState.empty();
expect(state, isA<NotificationsState>());
expect(state, isA<NotificationsStateEmpty>());
});
test('creates loaded NotificationsState with default values', () {
const state = NotificationsState.loaded(
notifications: [],
notificationsCount: 0,
);
expect(state, isA<NotificationsState>());
expect(state, isA<NotificationsStateLoaded>());
expect((state as NotificationsStateLoaded).notifications, isEmpty);
expect(state.notificationsCount, 0);
expect(state.isLoading, isFalse);
expect(state.hasUnreadNotifications, isFalse);
expect(state.currentPage, 1);
expect(state.hasNextPage, isTrue);
expect(state.isLoadingMore, isFalse);
});
test('creates loaded NotificationsState with custom values', () {
final notification = PlanSubscriptionStartedToAuthorNotification(
type: NotificationType.planSubscriptionStartedToAuthor,
planName: 'Test Plan',
customerName: 'Test Customer',
chatId: 'chat-123',
isRead: false,
createdAt: DateTime.now(),
);
final state = NotificationsState.loaded(
notifications: [notification],
notificationsCount: 1,
isLoading: true,
hasUnreadNotifications: true,
currentPage: 2,
hasNextPage: false,
isLoadingMore: true,
);
expect(state, isA<NotificationsStateLoaded>());
expect((state as NotificationsStateLoaded).notifications.length, 1);
expect(state.notificationsCount, 1);
expect(state.isLoading, isTrue);
expect(state.hasUnreadNotifications, isTrue);
expect(state.currentPage, 2);
expect(state.hasNextPage, isFalse);
expect(state.isLoadingMore, isTrue);
});
test('creates error NotificationsState', () {
const state = NotificationsState.error(errorMessage: 'Test error');
expect(state, isA<NotificationsState>());
expect(state, isA<NotificationsStateError>());
expect((state as NotificationsStateError).errorMessage, 'Test error');
});
test('different state types are not equal', () {
const empty = NotificationsState.empty();
const loaded = NotificationsState.loaded(notifications: [], notificationsCount: 0);
const error = NotificationsState.error(errorMessage: 'Error');
expect(empty == loaded, isFalse);
expect(empty == error, isFalse);
expect(loaded == error, isFalse);
});
test('same state types with same data are equal', () {
const state1 = NotificationsState.loaded(notifications: [], notificationsCount: 0);
const state2 = NotificationsState.loaded(notifications: [], notificationsCount: 0);
expect(state1 == state2, isTrue);
});
});
}