Skip to content

Commit 55be343

Browse files
committed
test wip
1 parent 9a268c8 commit 55be343

File tree

8 files changed

+53
-43
lines changed

8 files changed

+53
-43
lines changed

lib/layers/presentation/login/bloc/login_state.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
abstract class LoginState {}
1+
import 'package:equatable/equatable.dart';
2+
3+
abstract class LoginState extends Equatable {
4+
const LoginState();
5+
6+
@override
7+
List<Object> get props => [];
8+
}
29

310
abstract class LoginActionState extends LoginState {}
411

lib/layers/presentation/post/read_posts/bloc/read_posts_state.dart

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
import 'package:equatable/equatable.dart';
2+
13
import '../../../../../core/entities/post.dart';
24

3-
abstract class ReadPostsState {}
5+
abstract class ReadPostsState extends Equatable {
6+
const ReadPostsState();
7+
8+
@override
9+
List<Object> get props => [];
10+
}
411

512
abstract class PostActionState extends ReadPostsState {}
613

@@ -9,18 +16,18 @@ class PostInitialState extends ReadPostsState {}
916
class PostLoadingState extends ReadPostsState {}
1017

1118
class PostLoadedSuccessState extends ReadPostsState {
12-
bool isSearch;
19+
final bool isSearch;
1320
final List<Post> postList;
14-
List<Post> selectedPosts;
15-
PostLoadedSuccessState(this.postList, this.isSearch, this.selectedPosts);
21+
final List<Post> selectedPosts;
22+
const PostLoadedSuccessState(this.postList, this.isSearch, this.selectedPosts);
1623
PostLoadedSuccessState copyWith({List<Post>? postList}) {
1724
return PostLoadedSuccessState(postList ?? this.postList, isSearch, selectedPosts);
1825
}
1926
}
2027

2128
class PostErrorState extends ReadPostsState {
22-
String message;
23-
PostErrorState(this.message);
29+
final String message;
30+
const PostErrorState(this.message);
2431
}
2532

2633
class PostNavigateToAddPostActionState extends PostActionState {}
@@ -44,7 +51,7 @@ class PostItemSelectedActionState extends PostActionState {}
4451
class PostItemsDeletedActionState extends PostActionState {}
4552

4653
class PostSearchIconClickedState extends PostActionState {
47-
bool isSearch;
54+
final bool isSearch;
4855
PostSearchIconClickedState(this.isSearch);
4956
}
5057

test/core/model/post_model_test.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import '../../fixtures/fixture_reader.dart';
55

66
void main() {
77
final tPostModel = PostModel(
8-
id: 37,
8+
id: 1,
99
content: '',
1010
isSelected: 0,
1111
title: '',
@@ -19,19 +19,19 @@ void main() {
1919
group('fromJson', () {
2020
test('should return a valid model', () async {
2121
//arrange
22-
final Map<String, dynamic> jsonMap = json.decode(fixture('Post.json'));
22+
final Map<String, dynamic> jsonMap = json.decode(fixture('post.json'));
2323
//act
2424
final result = PostModel.fromJson(jsonMap);
2525
//assert
2626
expect(result.id, equals(tPostModel.id));
2727
});
28-
test('should return a valid model when the JSON duration is regarded as a double', () async {
28+
test('should return a valid model when the JSON title is regarded as a long', () async {
2929
//arrange
30-
final Map<String, dynamic> jsonMap = json.decode(fixture('Post_duration_double.json'));
30+
final Map<String, dynamic> jsonMap = json.decode(fixture('post_title_long.json'));
3131
//act
3232
final result = PostModel.fromJson(jsonMap);
3333
//assert
34-
expect(result, equals(tPostModel));
34+
expect(result.id, equals(tPostModel.id));
3535
});
3636
});
3737

@@ -41,9 +41,9 @@ void main() {
4141
final result = tPostModel.toMap();
4242
//assert
4343
final expectedMap = {
44-
"id": 37,
4544
"content": '',
4645
"isSelected": 0,
46+
"imagePath": null,
4747
"title": '',
4848
};
4949
expect(result, equals(expectedMap));

test/fixtures/post.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{
2-
"id": 37,
3-
"name": "string",
4-
"description": "This is for random",
5-
"difficulty": "easy",
6-
"duration": 10,
7-
"source": "pre_loaded",
8-
"exercises": []
2+
"id": 1,
3+
"title": " ",
4+
"content": " ",
5+
"imagePath": " ",
6+
"isSelected": 0
97
}

test/fixtures/post_cached.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{
2-
"id": 37,
3-
"name": "string",
4-
"description": "This is for random",
5-
"difficulty": "easy",
6-
"duration": 10,
7-
"source": "pre_loaded",
8-
"exercises": []
2+
"id": 1,
3+
"title": " ",
4+
"content": " ",
5+
"imagePath": " ",
6+
"isSelected": 0
97
}

test/fixtures/post_title_long.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{
2-
"id": 37,
3-
"name": "string",
4-
"description": "This is for random",
5-
"difficulty": "easy",
6-
"duration": 10.0,
7-
"source": "pre_loaded",
8-
"exercises": []
2+
"id": 1,
3+
"title": " ",
4+
"content": " ",
5+
"imagePath": " ",
6+
"isSelected": 0
97
}

test/layers/data/posts/datasources/posts_local_data_source_test.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import '../../../../fixtures/fixture_reader.dart';
1111
@GenerateMocks([
1212
DatabaseHelper
1313
], customMocks: [
14-
MockSpec<DatabaseHelper>(as: #MockDatabaseHelperForTest, onMissingStub:OnMissingStub.returnDefault),
14+
MockSpec<DatabaseHelper>(as: #MockDatabaseHelperForTest, onMissingStub: OnMissingStub.returnDefault),
1515
])
1616
void main() {
1717
late PostLocalDataSourceImpl dataSource;
@@ -44,12 +44,14 @@ void main() {
4444

4545
group('cachePostModel', () {
4646
final tPostModel = PostModel(
47-
id: 37,
4847
content: '',
4948
isSelected: 0,
49+
imagePath: null,
5050
title: '',
5151
);
5252
test('should call db to cache the data', () async {
53+
//arrange
54+
when(await DatabaseHelper.insertPost(tPostModel)).thenReturn(1);
5355
//act
5456
dataSource.createPost(tPostModel);
5557
//assert

test/layers/presentation/routine/bloc/routine_bloc_test.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void main() {
6363
when(mockGetPosts(any)).thenAnswer((_) async => Right(tPostModel));
6464

6565
//assert later
66-
final expected = [PostInitialState(), PostLoadingState(), PostLoadedSuccessState(tPostModel, false, [])];
66+
final expected = [PostInitialState(), PostLoadingState(), PostLoadedSuccessState(tPostModel, false, const [])];
6767
expectLater(bloc, emitsInOrder(expected));
6868
//act
6969
bloc.add(PostInitialEvent());
@@ -74,7 +74,7 @@ void main() {
7474
when(mockGetPosts(any)).thenAnswer((_) async => Left(ServerFailure()));
7575

7676
//assert later
77-
final expected = [PostInitialState(), PostLoadingState(), PostErrorState(AppStrings.serverFailureMessage)];
77+
final expected = [PostInitialState(), PostLoadingState(), const PostErrorState(AppStrings.serverFailureMessage)];
7878
expectLater(bloc, emitsInOrder(expected));
7979
//act
8080
bloc.add(PostInitialEvent());
@@ -86,7 +86,7 @@ void main() {
8686
when(mockGetPosts(any)).thenAnswer((_) async => Left(CacheFailure()));
8787

8888
//assert later
89-
final expected = [PostInitialState(), PostLoadingState(), PostErrorState(AppStrings.cacheFailureMessage)];
89+
final expected = [PostInitialState(), PostLoadingState(), const PostErrorState(AppStrings.cacheFailureMessage)];
9090
expectLater(bloc, emitsInOrder(expected));
9191
//act
9292
bloc.add(PostInitialEvent());
@@ -119,7 +119,7 @@ void main() {
119119
final expected = [
120120
PostInitialState(),
121121
PostLoadingState(),
122-
PostLoadedSuccessState([tPost], false, [])
122+
PostLoadedSuccessState([tPost], false, const [])
123123
];
124124
expectLater(bloc, emitsInOrder(expected));
125125
//act
@@ -130,7 +130,7 @@ void main() {
130130
when(mockDeletePost(tPost)).thenAnswer((_) async => Left(ServerFailure()));
131131

132132
//assert later
133-
final expected = [PostInitialState(), PostLoadingState(), PostErrorState(AppStrings.serverFailureMessage)];
133+
final expected = [PostInitialState(), PostLoadingState(), const PostErrorState(AppStrings.serverFailureMessage)];
134134
expectLater(bloc, emitsInOrder(expected));
135135
//act
136136
bloc.add(PostDeleteButtonClickedEvent(tPost));
@@ -141,7 +141,7 @@ void main() {
141141
when(mockDeletePost(tPost)).thenAnswer((_) async => Left(CacheFailure()));
142142

143143
//assert later
144-
final expected = [PostInitialState(), PostLoadingState(), PostErrorState(AppStrings.cacheFailureMessage)];
144+
final expected = [PostInitialState(), PostLoadingState(), const PostErrorState(AppStrings.cacheFailureMessage)];
145145
expectLater(bloc, emitsInOrder(expected));
146146
//act
147147
bloc.add(PostDeleteButtonClickedEvent(tPost));

0 commit comments

Comments
 (0)