feat(tests): blog post create

This commit is contained in:
mso7nueh
2025-10-22 18:42:01 +03:00
parent 4c7dd4a12a
commit 14e4d7973e
3 changed files with 38 additions and 17 deletions

View File

@@ -266,7 +266,7 @@ void main() {
testWidgets('should handle loading state during blog post creation', (WidgetTester tester) async {
// Arrange
when(mockBlogPostRepository.createBlogPost(any, any, any, any)).thenAnswer((_) async {
await Future.delayed(const Duration(milliseconds: 100));
await Future.delayed(const Duration(milliseconds: 50));
});
Widget loadingWidget = BlocBuilder<BlogPostCreateCubit, BlogPostCreateState>(
@@ -283,11 +283,16 @@ void main() {
await tester.pumpAndSettle();
// Trigger loading state
blogPostCreateCubit.createBlogPost(title: 'Test Title', description: 'Test Description', videoUrl: null, image: null);
blogPostCreateCubit.createBlogPost(title: 'Test Title', videoUrl: null, description: 'Test Description', image: null);
await tester.pump();
await tester.pump(); // Need to pump twice to get the loading state
// Assert
expect(find.byType(CircularProgressIndicator), findsOneWidget);
// Wait for the async operation to complete
await tester.pump(const Duration(milliseconds: 100));
await tester.pumpAndSettle();
});
testWidgets('should handle error state during blog post creation', (WidgetTester tester) async {
@@ -308,8 +313,9 @@ void main() {
await tester.pumpAndSettle();
// Trigger error state
blogPostCreateCubit.createBlogPost(title: 'Test Title', description: 'Test Description', videoUrl: null, image: null);
blogPostCreateCubit.createBlogPost(title: 'Test Title', videoUrl: null, description: 'Test Description', image: null);
await tester.pump();
await tester.pump(); // Need to pump twice to get the error state
// Assert
expect(find.textContaining('Error:'), findsOneWidget);
@@ -333,8 +339,9 @@ void main() {
await tester.pumpAndSettle();
// Trigger success state
blogPostCreateCubit.createBlogPost(title: 'Test Title', description: 'Test Description', videoUrl: null, image: null);
blogPostCreateCubit.createBlogPost(title: 'Test Title', videoUrl: null, description: 'Test Description', image: null);
await tester.pump();
await tester.pump(); // Need to pump twice to get the success state
// Assert
expect(find.text('Blog post created successfully!'), findsOneWidget);
@@ -448,7 +455,7 @@ void main() {
ElevatedButton(
key: AppKeys.blogPostCreateScreenCreateButton,
onPressed: () async {
await blogPostCreateCubit.createBlogPost(title: '', description: '', videoUrl: '', image: null);
await blogPostCreateCubit.createBlogPost(title: '', videoUrl: '', description: '', image: null);
},
child: const Text('Опубликовать'),
),
@@ -492,7 +499,7 @@ void main() {
ElevatedButton(
key: AppKeys.blogPostCreateScreenCreateButton,
onPressed: () async {
await blogPostCreateCubit.createBlogPost(title: 'Test Title', description: longContent, videoUrl: null, image: null);
await blogPostCreateCubit.createBlogPost(title: 'Test Title', videoUrl: null, description: longContent, image: null);
},
child: const Text('Опубликовать'),
),