forked from eatvio/eatvio_app
feat(tests): test coverage is 70.5
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
||||
import 'package:eatvio_app/features/feed/models/feed_blog_post_model.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/bloc/feed_cubit/feed_state.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('FeedState', () {
|
||||
test('creates initial FeedState', () {
|
||||
const state = FeedState();
|
||||
expect(state, isA<FeedState>());
|
||||
});
|
||||
|
||||
test('creates loading FeedState', () {
|
||||
const state = FeedState.loading();
|
||||
expect(state, isA<FeedState>());
|
||||
expect(state, isA<FeedStateLoading>());
|
||||
});
|
||||
|
||||
test('creates loaded FeedState with data', () {
|
||||
const state = FeedState.loaded(feedBlogPostList: [], isLoading: false);
|
||||
|
||||
expect(state, isA<FeedState>());
|
||||
expect(state, isA<FeedStateLoaded>());
|
||||
expect((state as FeedStateLoaded).feedBlogPostList, isEmpty);
|
||||
expect(state.isLoading, isFalse);
|
||||
});
|
||||
|
||||
test('creates loaded FeedState with blog posts', () {
|
||||
const author = Author(authorSlug: 'test-author', authorName: 'Test Author', authorProfileIcon: 'https://example.com/icon.jpg', authorIsMe: false);
|
||||
|
||||
final blogPost = FeedBlogPostModel(
|
||||
id: 1,
|
||||
title: 'Test Post',
|
||||
state: 'active',
|
||||
image: 'https://example.com/image.jpg',
|
||||
description: 'Test Description',
|
||||
author: author,
|
||||
videoUrl: 'https://example.com/video.mp4',
|
||||
createdAt: DateTime.now(),
|
||||
updatedAt: DateTime.now(),
|
||||
totalLikes: 0,
|
||||
totalViews: 0,
|
||||
totalComments: 0,
|
||||
wasLikedByMe: false,
|
||||
);
|
||||
|
||||
final state = FeedState.loaded(feedBlogPostList: [blogPost], isLoading: true);
|
||||
|
||||
expect(state, isA<FeedStateLoaded>());
|
||||
expect((state as FeedStateLoaded).feedBlogPostList.length, 1);
|
||||
expect(state.isLoading, isTrue);
|
||||
});
|
||||
|
||||
test('creates error FeedState', () {
|
||||
const state = FeedState.error(errorMessage: 'Test error');
|
||||
|
||||
expect(state, isA<FeedState>());
|
||||
expect(state, isA<FeedStateError>());
|
||||
expect((state as FeedStateError).errorMessage, 'Test error');
|
||||
});
|
||||
|
||||
test('different state types are not equal', () {
|
||||
const loading = FeedState.loading();
|
||||
const loaded = FeedState.loaded(feedBlogPostList: [], isLoading: false);
|
||||
const error = FeedState.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 state1 = FeedState.loaded(feedBlogPostList: [], isLoading: false);
|
||||
const state2 = FeedState.loaded(feedBlogPostList: [], isLoading: false);
|
||||
|
||||
expect(state1 == state2, isTrue);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user