-
Notifications
You must be signed in to change notification settings - Fork 45
Implement cores #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Implement cores #42
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
cee9658
Add core models + API service
ashtanko 55546d0
Add cores repository
ashtanko 4bca4cc
Add cores repository impl
ashtanko 86c199b
Add cores bloc
ashtanko 3518aea
Add filter bloc event
ashtanko 093ba8c
Implement cores screen
ashtanko 94aab38
Add unit tests
ashtanko 4b49882
Add unit tests
ashtanko ce27203
Add unit tests
ashtanko d55043f
Add unit tests
ashtanko d04feae
Merge branch 'main' into feature/cores
ashtanko a6cfecb
Fix conflicts + add integration tests
ashtanko df5715f
Small refactor + add search widget tests
ashtanko 423a50a
Merge branch 'main' into feature/cores
ashtanko c4a92ab
Fix after merge
ashtanko 5dd4198
Small fixes
ashtanko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,5 +3,5 @@ coverage: | |
| status: | ||
| project: | ||
| default: | ||
| target: 59% | ||
| target: 50% | ||
| threshold: 1% | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter_bloc_app_template/main.dart' as app; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:integration_test/integration_test.dart'; | ||
|
|
||
| void main() { | ||
| IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
|
||
| setUp(() {}); | ||
|
|
||
| testWidgets('cores test', ( | ||
| WidgetTester tester, | ||
| ) async { | ||
| app.main([]); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| expect(find.byKey(const Key('cores_screen')), findsOneWidget); | ||
|
|
||
| final coresTab = find.byKey(const Key('cores_screen')); | ||
| await tester.ensureVisible(coresTab); | ||
| await tester.tap(coresTab); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| final firstItem = find.byKey(const Key('Merlin1A0')); | ||
|
|
||
| expect(firstItem, findsOneWidget); | ||
| await tester.ensureVisible(firstItem); | ||
|
|
||
| final allFilterChip = find.byKey(const Key('core_status_filter_all')); | ||
| await tester.ensureVisible(allFilterChip); | ||
|
|
||
| await tester.tap(allFilterChip); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| expect(find.text('Merlin1A'), findsOneWidget); | ||
|
|
||
| final activeFilterChip = find.byKey(const Key('core_status_filter_active')); | ||
| await tester.ensureVisible(activeFilterChip); | ||
|
|
||
| await tester.tap(activeFilterChip); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| expect(find.text('active'), findsAtLeast(1)); | ||
|
|
||
| final lostFilterChip = find.byKey(const Key('core_status_filter_lost')); | ||
| await tester.ensureVisible(lostFilterChip); | ||
|
|
||
| await tester.tap(lostFilterChip); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| expect(find.text('lost'), findsAtLeast(1)); | ||
|
|
||
| final inactiveFilterChip = find.byKey( | ||
| const Key('core_status_filter_inactive'), | ||
| ); | ||
| await tester.ensureVisible(inactiveFilterChip); | ||
|
|
||
| await tester.tap(inactiveFilterChip); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| expect(find.text('inactive'), findsAtLeast(1)); | ||
|
|
||
| final unknownFilterChip = find.byKey( | ||
| const Key('core_status_filter_unknown'), | ||
| ); | ||
| await tester.ensureVisible(unknownFilterChip); | ||
|
|
||
| await tester.tap(unknownFilterChip); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| expect(find.text('unknown'), findsAtLeast(1)); | ||
|
|
||
| final searchField = find.byType(TextField); | ||
| expect(searchField, findsOneWidget); | ||
|
|
||
| await tester.enterText(searchField, 'flutter'); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| expect(find.text('No cores found for "flutter"'), findsOneWidget); | ||
|
|
||
| await tester.tap(allFilterChip); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| await tester.enterText(searchField, 'Merlin'); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| expect(find.text('Merlin'), findsAtLeast(1)); | ||
|
|
||
| // await tester.tap(find.byType(CoreItemWidget).first); | ||
| // await tester.pumpAndSettle(); | ||
| // todo replace with details screen text | ||
| // expect(find.text('Merlin1A'), findsOneWidget); | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| import 'package:bloc_test/bloc_test.dart'; | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter_bloc_app_template/features/cores/bloc/cores_bloc.dart'; | ||
| import 'package:flutter_bloc_app_template/features/cores/cores_screen.dart'; | ||
| import 'package:flutter_bloc_app_template/features/cores/widget/core_loading_content.dart'; | ||
| import 'package:flutter_bloc_app_template/features/cores/widget/cores_empty_widget.dart'; | ||
| import 'package:flutter_bloc_app_template/features/cores/widget/cores_error_widget.dart'; | ||
| import 'package:flutter_bloc_app_template/features/cores/widget/cores_not_found_widget.dart'; | ||
| import 'package:flutter_bloc_app_template/models/core/core_resource.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:integration_test/integration_test.dart'; | ||
| import 'package:mocktail/mocktail.dart'; | ||
|
|
||
| import '../test/bloc/utils.dart'; | ||
|
|
||
| class MockCoresBloc extends MockBloc<CoresEvent, CoresState> | ||
| implements CoresBloc {} | ||
|
|
||
| void main() { | ||
| IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
|
||
| late MockCoresBloc mockBloc; | ||
|
|
||
| setUp(() { | ||
| mockBloc = MockCoresBloc(); | ||
| }); | ||
|
|
||
| testWidgets('renders LoadingContent when state is CoresLoadingState', | ||
| (tester) async { | ||
| when(() => mockBloc.state).thenReturn(const CoresLoadingState()); | ||
|
|
||
| await tester.pumpLocalizedWidgetWithBloc<CoresBloc>( | ||
| bloc: mockBloc, | ||
| child: const CustomScrollView( | ||
| slivers: [CoresBlocContent()], | ||
| ), | ||
| locale: const Locale('en'), | ||
| ); | ||
| await tester.pump(); | ||
|
|
||
| expect(find.byType(CoreLoadingContent), findsOneWidget); | ||
| }); | ||
|
|
||
| testWidgets('renders CoresListWidget when state is CoresSuccessState', | ||
| (tester) async { | ||
| final cores = <CoreResource>[ | ||
| const CoreResource( | ||
| coreSerial: 'B1051', | ||
| missions: [MissionResource(name: null, flight: 1)], | ||
| status: 'active', | ||
| ), | ||
| ]; // provide mock cores | ||
| when(() => mockBloc.state) | ||
| .thenReturn(CoresSuccessState(filteredCores: cores)); | ||
|
|
||
| await tester.pumpLocalizedWidgetWithBloc<CoresBloc>( | ||
| bloc: mockBloc, | ||
| child: const CustomScrollView( | ||
| slivers: [CoresBlocContent()], | ||
| ), | ||
| locale: const Locale('en'), | ||
| ); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| expect(find.byType(CoresListWidget), findsOneWidget); | ||
| }); | ||
|
|
||
| testWidgets('renders CoresErrorWidget when state is CoresErrorState', | ||
| (tester) async { | ||
| const errorMessage = 'Error occurred'; | ||
| when(() => mockBloc.state).thenReturn(const CoresErrorState(errorMessage)); | ||
|
|
||
| await tester.pumpLocalizedWidgetWithBloc<CoresBloc>( | ||
| bloc: mockBloc, | ||
| child: const CustomScrollView( | ||
| slivers: [CoresBlocContent()], | ||
| ), | ||
| locale: const Locale('en'), | ||
| ); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| expect(find.byType(CoresErrorWidget), findsOneWidget); | ||
| //expect(find.text(errorMessage), findsOneWidget); | ||
| }); | ||
|
|
||
| testWidgets('renders CoresEmptyWidget when state is CoresEmptyState', | ||
| (tester) async { | ||
| when(() => mockBloc.state).thenReturn(const CoresEmptyState()); | ||
|
|
||
| await tester.pumpLocalizedWidgetWithBloc<CoresBloc>( | ||
| bloc: mockBloc, | ||
| child: const CustomScrollView( | ||
| slivers: [CoresBlocContent()], | ||
| ), | ||
| locale: const Locale('en'), | ||
| ); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| expect(find.byType(CoresEmptyWidget), findsOneWidget); | ||
| }); | ||
|
|
||
| testWidgets('renders CoresNotFoundWidget when state is CoresNotFoundState', | ||
| (tester) async { | ||
| const query = 'Falcon'; | ||
| when(() => mockBloc.state) | ||
| .thenReturn(const CoresNotFoundState(searchQuery: query)); | ||
|
|
||
| await tester.pumpLocalizedWidgetWithBloc<CoresBloc>( | ||
| bloc: mockBloc, | ||
| child: const CustomScrollView( | ||
| slivers: [CoresBlocContent()], | ||
| ), | ||
| locale: const Locale('en'), | ||
| ); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| expect(find.byType(CoresNotFoundWidget), findsOneWidget); | ||
| expect(find.textContaining(query), findsOneWidget); | ||
| }); | ||
| } |
48 changes: 48 additions & 0 deletions
48
lib/data/network/data_source/cores_network_data_source.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import 'package:flutter_bloc_app_template/data/network/api_result.dart'; | ||
| import 'package:flutter_bloc_app_template/data/network/model/core/network_core_model.dart'; | ||
| import 'package:flutter_bloc_app_template/data/network/service/cores/cores_service.dart'; | ||
|
|
||
| abstract class CoresDataSource { | ||
| Future<ApiResult<List<NetworkCoreModel>>> getCores({ | ||
| bool? hasId = true, | ||
| int? limit, | ||
| int? offset, | ||
| }); | ||
|
|
||
| Future<ApiResult<NetworkCoreModel>> getCore(String coreSerial); | ||
| } | ||
|
|
||
| class CoresNetworkDataSource implements CoresDataSource { | ||
| CoresNetworkDataSource(this._service); | ||
|
|
||
| final CoresService _service; | ||
|
|
||
| @override | ||
| Future<ApiResult<List<NetworkCoreModel>>> getCores({ | ||
| bool? hasId = true, | ||
| int? limit, | ||
| int? offset, | ||
| }) async { | ||
| try { | ||
| final list = await _service.fetchCores( | ||
| hasId: hasId, | ||
| limit: limit, | ||
| offset: offset, | ||
| ); | ||
|
|
||
| return ApiResult.success(list); | ||
| } catch (e) { | ||
| return Future.value(ApiResult.error(e.toString())); | ||
| } | ||
| } | ||
|
|
||
| @override | ||
| Future<ApiResult<NetworkCoreModel>> getCore(String coreSerial) async { | ||
| try { | ||
| final result = await _service.fetchCore(coreSerial); | ||
| return ApiResult.success(result); | ||
| } catch (e) { | ||
| return Future.value(ApiResult.error(e.toString())); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Use localized string instead of hard-coded English
Avoid locale-coupled flakiness; assert using l10n.
Apply:
📝 Committable suggestion
🤖 Prompt for AI Agents