Skip to content

Commit bdae65a

Browse files
authored
Merge pull request #39 from ashtanko/feature/rockets
Implement rocket list
2 parents 2ddf4ec + 7c4a790 commit bdae65a

File tree

130 files changed

+11256
-730
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+11256
-730
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,4 @@ jobs:
133133
flutter test integration_test/launches_mock_test.dart --flavor dev
134134
flutter test integration_test/launches_test.dart --flavor dev
135135
flutter test integration_test/settings_test.dart --flavor dev
136+
flutter test integration_test/rockets_screen_integration_test.dart --flavor dev

integration_test/app_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void main() {
1515
await tester.pumpAndSettle();
1616

1717
expect(find.text('Launches'), findsAtLeast(1));
18-
expect(find.text('Emails'), findsOneWidget);
18+
expect(find.text('Rockets'), findsOneWidget);
1919
expect(find.text('Settings'), findsOneWidget);
2020

2121
expect(find.textContaining('Mission'), findsAtLeast(1));

integration_test/launches_mock_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
22
import 'package:flutter_bloc_app_template/features/launches/bloc/launches_bloc.dart';
33
import 'package:flutter_bloc_app_template/features/launches/launches_screen.dart';
44
import 'package:flutter_bloc_app_template/index.dart';
5+
import 'package:flutter_bloc_app_template/models/launch/launch_rocket_resource.dart';
56
import 'package:flutter_test/flutter_test.dart';
67
import 'package:integration_test/integration_test.dart';
78
import 'package:mocktail/mocktail.dart';
@@ -66,7 +67,7 @@ void main() {
6667
'2021-10-01T00:00:00Z',
6768
),
6869
launchTime: '00:00',
69-
rocket: RocketResource(
70+
rocket: LaunchRocketResource(
7071
rocketName: 'Rocket 1',
7172
rocketType: 'Type 1',
7273
),
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_bloc_app_template/features/rockets/bloc/rockets_bloc.dart';
3+
import 'package:flutter_bloc_app_template/features/rockets/rockets_screen.dart';
4+
import 'package:flutter_bloc_app_template/features/rockets/widget/rocket_item/rocket_item.dart';
5+
import 'package:flutter_test/flutter_test.dart';
6+
import 'package:integration_test/integration_test.dart';
7+
import 'package:mocktail/mocktail.dart';
8+
9+
import '../test/bloc/utils.dart';
10+
import '../test/features/rockets/rockets_screen_test.dart';
11+
import '../test/repository/rocket_repository_test.dart';
12+
13+
void main() {
14+
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
15+
16+
late RocketsBloc rocketsBloc;
17+
18+
setUp(() {
19+
rocketsBloc = MockRocketsBloc();
20+
});
21+
22+
group('Rockets Screen Tests', () {
23+
testWidgets(
24+
'renders CircularProgressIndicator '
25+
'when rocket list state is initial', (tester) async {
26+
when(() => rocketsBloc.state).thenReturn(const RocketsLoadingState());
27+
28+
await tester.pumpLocalizedWidgetWithBloc<RocketsBloc>(
29+
bloc: rocketsBloc,
30+
child: const RocketsBlocContent(),
31+
locale: const Locale('en'),
32+
);
33+
34+
await tester.pump();
35+
36+
expect(find.byType(CircularProgressIndicator), findsOneWidget);
37+
});
38+
39+
testWidgets(
40+
'renders Empty list text '
41+
'when rocket list state is success but with 0 items', (tester) async {
42+
when(() => rocketsBloc.state).thenReturn(const RocketsEmptyState());
43+
await tester.pumpLocalizedWidgetWithBloc<RocketsBloc>(
44+
bloc: rocketsBloc,
45+
child: const RocketsBlocContent(),
46+
locale: const Locale('en'),
47+
);
48+
await tester.pumpAndSettle();
49+
50+
expect(find.text('Empty list'), findsOneWidget);
51+
});
52+
53+
testWidgets('renders 1 item', (tester) async {
54+
when(() => rocketsBloc.state).thenReturn(
55+
RocketsSuccessState(
56+
rockets: [
57+
getRocketResource(),
58+
],
59+
),
60+
);
61+
await tester.pumpLocalizedWidgetWithBloc<RocketsBloc>(
62+
bloc: rocketsBloc,
63+
child: const RocketsBlocContent(),
64+
locale: const Locale('en'),
65+
);
66+
await tester.pumpAndSettle();
67+
68+
expect(find.byType(RocketItemWidget), findsNWidgets(1));
69+
});
70+
71+
testWidgets('renders error text', (tester) async {
72+
when(() => rocketsBloc.state).thenReturn(const RocketsErrorState());
73+
await tester.pumpLocalizedWidgetWithBloc<RocketsBloc>(
74+
bloc: rocketsBloc,
75+
child: const RocketsBlocContent(),
76+
locale: const Locale('en'),
77+
);
78+
await tester.pumpAndSettle();
79+
80+
expect(find.text('Try Again'), findsOneWidget);
81+
});
82+
});
83+
}

lib/bloc/email_list/email_list_bloc.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import 'package:flutter_bloc_app_template/models/email.dart';
44
import 'package:flutter_bloc_app_template/repository/email_list_repository.dart';
55

66
part 'email_list_event.dart';
7-
87
part 'email_list_state.dart';
98

109
class EmailListBloc extends Bloc<EmailListEvent, EmailListState> {

lib/bloc/init/init_bloc.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import 'package:bloc/bloc.dart';
22
import 'package:equatable/equatable.dart';
33

44
part 'init_event.dart';
5-
65
part 'init_state.dart';
76

87
class InitBloc extends Bloc<InitEvent, InitState> {

lib/data/network/data_source/launches_network_data_source.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'package:flutter_bloc_app_template/data/network/api_result.dart';
22
import 'package:flutter_bloc_app_template/data/network/model/launch/full/network_launch_full_model.dart';
33
import 'package:flutter_bloc_app_template/data/network/model/launch/network_launch_model.dart';
4-
import 'package:flutter_bloc_app_template/data/network/service/launch_service.dart';
4+
import 'package:flutter_bloc_app_template/data/network/service/launch/launch_service.dart';
55

66
abstract class LaunchesDataSource {
77
Future<ApiResult<List<NetworkLaunchModel>>> getLaunches({
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import 'package:flutter_bloc_app_template/data/network/api_result.dart';
2+
import 'package:flutter_bloc_app_template/data/network/model/rocket/network_rocket_model.dart';
3+
import 'package:flutter_bloc_app_template/data/network/service/rocket/rocket_service.dart';
4+
5+
abstract class RocketDataSource {
6+
Future<ApiResult<List<NetworkRocketModel>>> getRockets({
7+
bool? hasId = true,
8+
int? limit,
9+
int? offset,
10+
});
11+
12+
Future<ApiResult<NetworkRocketModel>> getRocket(String rocketId);
13+
}
14+
15+
class RocketNetworkDataSource implements RocketDataSource {
16+
RocketNetworkDataSource(this._service);
17+
18+
final RocketService _service;
19+
20+
@override
21+
Future<ApiResult<List<NetworkRocketModel>>> getRockets(
22+
{bool? hasId = true,
23+
int? limit,
24+
int? offset,
25+
int? launchYear,
26+
int? launchSuccess,
27+
String? order}) async {
28+
try {
29+
final response = await _service.fetchRockets(
30+
hasId: hasId,
31+
limit: limit,
32+
offset: offset,
33+
);
34+
35+
return ApiResult.success(response.toList());
36+
} catch (e) {
37+
return Future.value(ApiResult.error(e.toString()));
38+
}
39+
}
40+
41+
@override
42+
Future<ApiResult<NetworkRocketModel>> getRocket(String rocketId) async {
43+
try {
44+
final result = await _service.fetchRocket(rocketId);
45+
return ApiResult.success(result);
46+
} catch (e) {
47+
return Future.value(ApiResult.error(e.toString()));
48+
}
49+
}
50+
}

lib/data/network/model/core/network_core_model.freezed.dart

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/data/network/model/launch/full/network_launch_full_model.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ abstract class NetworkLaunchFullModel with _$NetworkLaunchFullModel {
2323
@JsonKey(name: 'tentative_max_precision') String? tentativeMaxPrecision,
2424
@JsonKey(name: 'tbd') bool? tbd,
2525
@JsonKey(name: 'launch_window') int? launchWindow,
26-
@JsonKey(name: 'rocket') NetworkRocketModel? rocket,
26+
@JsonKey(name: 'rocket') NetworkLaunchRocketModel? rocket,
2727
@JsonKey(name: 'ships') List<String>? ships,
2828
@JsonKey(name: 'telemetry') NetworkTelemetry? telemetry,
2929
@JsonKey(name: 'launch_site') NetworkLaunchSite? launchSite,

0 commit comments

Comments
 (0)