Fix import paths and test issues

- Fixed test file import paths to point to correct Bloc file locations
- Fixed Bloc file import paths for models (../../../models/models.dart)
- Added explicit type annotations to resolve null safety warnings
- Fixed null safety issues in wishlist_bloc_test.dart
- All 70 tests now passing
This commit is contained in:
Yuriy Panov
2026-02-04 15:28:59 +06:00
parent 310463e89a
commit 2f97873095
46 changed files with 270 additions and 260 deletions

View File

@@ -0,0 +1,127 @@
import 'book_status.dart';
// Book record - using Dart records as data classes
typedef Book = ({
String id,
String title,
String author,
String genre,
String annotation,
String? coverUrl,
int? pages,
String? language,
int? publishedYear,
double? rating,
BookStatus status,
int? progress,
bool isFavorite,
});
// Helper function to create a Book record
Book createBook({
required String id,
required String title,
required String author,
required String genre,
required String annotation,
String? coverUrl,
int? pages,
String? language,
int? publishedYear,
double? rating,
required BookStatus status,
int? progress,
required bool isFavorite,
}) {
return (
id: id,
title: title,
author: author,
genre: genre,
annotation: annotation,
coverUrl: coverUrl,
pages: pages,
language: language,
publishedYear: publishedYear,
rating: rating,
status: status,
progress: progress,
isFavorite: isFavorite,
);
}
// Extension to create Book from partial data
extension BookExtension on Book {
Book copyWith({
String? id,
String? title,
String? author,
String? genre,
String? annotation,
String? coverUrl,
int? pages,
String? language,
int? publishedYear,
double? rating,
BookStatus? status,
int? progress,
bool? isFavorite,
}) {
return createBook(
id: id ?? this.id,
title: title ?? this.title,
author: author ?? this.author,
genre: genre ?? this.genre,
annotation: annotation ?? this.annotation,
coverUrl: coverUrl ?? this.coverUrl,
pages: pages ?? this.pages,
language: language ?? this.language,
publishedYear: publishedYear ?? this.publishedYear,
rating: rating ?? this.rating,
status: status ?? this.status,
progress: progress ?? this.progress,
isFavorite: isFavorite ?? this.isFavorite,
);
}
// Convert to JSON for storage/transport
Map<String, dynamic> toJson() {
return {
'id': id,
'title': title,
'author': author,
'genre': genre,
'annotation': annotation,
'coverUrl': coverUrl,
'pages': pages,
'language': language,
'publishedYear': publishedYear,
'rating': rating,
'status': status.name,
'progress': progress,
'isFavorite': isFavorite,
};
}
// Create Book from JSON
static Book fromJson(Map<String, dynamic> json) {
return (
id: json['id'] as String,
title: json['title'] as String,
author: json['author'] as String,
genre: json['genre'] as String,
annotation: json['annotation'] as String,
coverUrl: json['coverUrl'] as String?,
pages: json['pages'] as int?,
language: json['language'] as String?,
publishedYear: json['publishedYear'] as int?,
rating: (json['rating'] as num?)?.toDouble(),
status: BookStatus.values.firstWhere(
(e) => e.name == json['status'],
orElse: () => BookStatus.wantToRead,
),
progress: json['progress'] as int?,
isFavorite: json['isFavorite'] as bool? ?? false,
);
}
}