Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ jobs:

- name: Set up Flutter
uses: ./.github/actions/setup-flutter


- name: Generate code
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a new step before run the tests considering Mock framework generates code

run: dart run build_runner build --delete-conflicting-outputs

- name: Run tests
run: flutter test

Expand Down
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ linter:
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule

# Additional information about this file can be found at
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class BookDetailsViewModel extends Bloc<BookDetailsEvent, BookDetailsState> {
final bookDetails = await _getBookDetails(id: bookId!);
return BookDetailsUI.fromDomain(bookDetails);
} else {
emit(state.copyWith(errorMessage: "Book ID is null"));
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this considering we are already emitting the state in the proper method caller (dart analyze pointed an issue here, we cannot emit without being in a scope of event (on ...)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well considered 👍

return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:auto_route/annotations.dart';
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BookSearchViewModel extends Bloc<BookSearchEvent, BookSearchState> {
);
print('Click search with text: ${state.searchText}');
final response = await _search(state.searchText);
print('Response received with ${response}');
print('Response received with $response');
emit(
state.copyWith(
books: response,
Expand Down
152 changes: 0 additions & 152 deletions test/api_client_test.dart
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove commented test

This file was deleted.

22 changes: 18 additions & 4 deletions test/search_data_source_test.dart
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solve unit tests issue

Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,18 @@ void main() {
when(
mockApiClient.get(
endpoint: 'volumes',
queryParameters: {'q': 'intitle:harry potter'},
queryParameters: {
'q': 'intitle:harry potter',
'startIndex': 0,
'maxResults': 40,
},
),
).thenAnswer((_) async => mockJson);

final result = await dataSource.searchByTitle(initTitle: 'harry potter');
final result = await dataSource.searchByTitle(
startIndex: 0,
initTitle: 'harry potter',
);
expect(result.kind, expectedBookList.kind);
expect(result.totalItems, expectedBookList.totalItems);
expect(result.items, expectedBookList.items);
Expand All @@ -43,12 +50,19 @@ void main() {
when(
mockApiClient.get(
endpoint: 'volumes',
queryParameters: {'q': 'intitle:harry potter'},
queryParameters: {
'q': 'intitle:harry potter',
'startIndex': 0,
'maxResults': 40,
},
),
).thenThrow(Exception('API error'));

expect(
() => dataSource.searchByTitle(initTitle: 'harry potter'),
() => dataSource.searchByTitle(
startIndex: 0,
initTitle: 'harry potter',
),
throwsException,
);
});
Expand Down
30 changes: 0 additions & 30 deletions test/widget_test.dart
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove generated test (not used)

This file was deleted.