forked from eatvio/eatvio_app
feat(tests): test coverage is 70.5
This commit is contained in:
@@ -0,0 +1,169 @@
|
||||
import 'package:eatvio_app/features/bottom_navigation_bar/presentation/bloc/profile_avatar_cubit/profile_avatar_state.dart';
|
||||
import 'package:eatvio_app/features/profile/models/profile_model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('ProfileAvatarState', () {
|
||||
test('creates initial ProfileAvatarState', () {
|
||||
const state = ProfileAvatarState();
|
||||
expect(state, isA<ProfileAvatarState>());
|
||||
});
|
||||
|
||||
test('creates loading ProfileAvatarState', () {
|
||||
const state = ProfileAvatarState.loading();
|
||||
expect(state, isA<ProfileAvatarState>());
|
||||
expect(state, isA<ProfileAvatarStateLoading>());
|
||||
});
|
||||
|
||||
test('creates loaded ProfileAvatarState with profile', () {
|
||||
const profile = ProfileModel(
|
||||
id: 1,
|
||||
slug: 'test-user',
|
||||
name: 'Test User',
|
||||
email: 'test@example.com',
|
||||
phoneConfirmationState: 'confirmed',
|
||||
isPublicProfile: true,
|
||||
isBlockedByMe: false,
|
||||
isBlockedByAuthor: false,
|
||||
isBlockedByUser: false,
|
||||
isEntitySubscribedByMe: false,
|
||||
profilePhotoUrl: 'https://example.com/icon.jpg',
|
||||
roles: [],
|
||||
badges: [],
|
||||
subscriptions: [],
|
||||
subscribers: [],
|
||||
);
|
||||
const state = ProfileAvatarState.loaded(profile: profile);
|
||||
expect(state, isA<ProfileAvatarState>());
|
||||
expect(state, isA<ProfileAvatarStateLoaded>());
|
||||
expect((state as ProfileAvatarStateLoaded).profile, profile);
|
||||
});
|
||||
|
||||
test('creates error ProfileAvatarState with error message', () {
|
||||
const state = ProfileAvatarState.error(errorMessage: 'Test error');
|
||||
expect(state, isA<ProfileAvatarState>());
|
||||
expect(state, isA<ProfileAvatarStateError>());
|
||||
expect((state as ProfileAvatarStateError).errorMessage, 'Test error');
|
||||
});
|
||||
|
||||
test('different state types are not equal', () {
|
||||
const profile = ProfileModel(
|
||||
id: 1,
|
||||
slug: 'test-user',
|
||||
name: 'Test User',
|
||||
email: 'test@example.com',
|
||||
phoneConfirmationState: 'confirmed',
|
||||
isPublicProfile: true,
|
||||
isBlockedByMe: false,
|
||||
isBlockedByAuthor: false,
|
||||
isBlockedByUser: false,
|
||||
isEntitySubscribedByMe: false,
|
||||
profilePhotoUrl: 'https://example.com/icon.jpg',
|
||||
roles: [],
|
||||
badges: [],
|
||||
subscriptions: [],
|
||||
subscribers: [],
|
||||
);
|
||||
const loading = ProfileAvatarState.loading();
|
||||
const loaded = ProfileAvatarState.loaded(profile: profile);
|
||||
const error = ProfileAvatarState.error(errorMessage: 'Error');
|
||||
|
||||
expect(loading == loaded, isFalse);
|
||||
expect(loading == error, isFalse);
|
||||
expect(loaded == error, isFalse);
|
||||
});
|
||||
|
||||
test('same state types with same data are equal', () {
|
||||
const profile = ProfileModel(
|
||||
id: 1,
|
||||
slug: 'test-user',
|
||||
name: 'Test User',
|
||||
email: 'test@example.com',
|
||||
phoneConfirmationState: 'confirmed',
|
||||
isPublicProfile: true,
|
||||
isBlockedByMe: false,
|
||||
isBlockedByAuthor: false,
|
||||
isBlockedByUser: false,
|
||||
isEntitySubscribedByMe: false,
|
||||
profilePhotoUrl: 'https://example.com/icon.jpg',
|
||||
roles: [],
|
||||
badges: [],
|
||||
subscriptions: [],
|
||||
subscribers: [],
|
||||
);
|
||||
const state1 = ProfileAvatarState.loaded(profile: profile);
|
||||
const state2 = ProfileAvatarState.loaded(profile: profile);
|
||||
|
||||
expect(state1 == state2, isTrue);
|
||||
});
|
||||
|
||||
test('same state types with different data are not equal', () {
|
||||
const profile1 = ProfileModel(
|
||||
id: 1,
|
||||
slug: 'test-user',
|
||||
name: 'Test User',
|
||||
email: 'test@example.com',
|
||||
phoneConfirmationState: 'confirmed',
|
||||
isPublicProfile: true,
|
||||
isBlockedByMe: false,
|
||||
isBlockedByAuthor: false,
|
||||
isBlockedByUser: false,
|
||||
isEntitySubscribedByMe: false,
|
||||
profilePhotoUrl: 'https://example.com/icon.jpg',
|
||||
roles: [],
|
||||
badges: [],
|
||||
subscriptions: [],
|
||||
subscribers: [],
|
||||
);
|
||||
const profile2 = ProfileModel(
|
||||
id: 2,
|
||||
slug: 'other-user',
|
||||
name: 'Other User',
|
||||
email: 'other@example.com',
|
||||
phoneConfirmationState: 'confirmed',
|
||||
isPublicProfile: true,
|
||||
isBlockedByMe: false,
|
||||
isBlockedByAuthor: false,
|
||||
isBlockedByUser: false,
|
||||
isEntitySubscribedByMe: false,
|
||||
profilePhotoUrl: 'https://example.com/icon2.jpg',
|
||||
roles: [],
|
||||
badges: [],
|
||||
subscriptions: [],
|
||||
subscribers: [],
|
||||
);
|
||||
const state1 = ProfileAvatarState.loaded(profile: profile1);
|
||||
const state2 = ProfileAvatarState.loaded(profile: profile2);
|
||||
|
||||
expect(state1 == state2, isFalse);
|
||||
});
|
||||
|
||||
test('error states with different messages are not equal', () {
|
||||
const state1 = ProfileAvatarState.error(errorMessage: 'Error 1');
|
||||
const state2 = ProfileAvatarState.error(errorMessage: 'Error 2');
|
||||
|
||||
expect(state1 == state2, isFalse);
|
||||
});
|
||||
|
||||
test('error states with same messages are equal', () {
|
||||
const state1 = ProfileAvatarState.error(errorMessage: 'Error');
|
||||
const state2 = ProfileAvatarState.error(errorMessage: 'Error');
|
||||
|
||||
expect(state1 == state2, isTrue);
|
||||
});
|
||||
|
||||
test('initial ProfileAvatarState instances are equal', () {
|
||||
const state1 = ProfileAvatarState();
|
||||
const state2 = ProfileAvatarState();
|
||||
|
||||
expect(state1 == state2, isTrue);
|
||||
});
|
||||
|
||||
test('loading ProfileAvatarState instances are equal', () {
|
||||
const state1 = ProfileAvatarState.loading();
|
||||
const state2 = ProfileAvatarState.loading();
|
||||
|
||||
expect(state1 == state2, isTrue);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user