Skip to content

Commit 809ae18

Browse files
committed
Add roadster resource
1 parent 16308c6 commit 809ae18

File tree

4 files changed

+215
-0
lines changed

4 files changed

+215
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import 'package:flutter_bloc_app_template/data/network/model/roadster/network_roadster_model.dart';
2+
import 'package:flutter_bloc_app_template/models/roadster/roadster_resource.dart';
3+
4+
extension RoadsterExt on NetworkRoadsterModel {
5+
RoadsterResource toResource() {
6+
return RoadsterResource(
7+
name: name,
8+
launchDateUtc: launchDateUtc,
9+
launchDateUnix: launchDateUnix,
10+
launchMassKg: launchMassKg,
11+
launchMassLbs: launchMassLbs,
12+
noradId: noradId,
13+
epochJd: epochJd,
14+
orbitType: orbitType,
15+
apoapsisAu: apoapsisAu,
16+
periapsisAu: periapsisAu,
17+
semiMajorAxisAu: semiMajorAxisAu,
18+
eccentricity: eccentricity,
19+
inclination: inclination,
20+
longitude: longitude,
21+
periapsisArg: periapsisArg,
22+
periodDays: periodDays,
23+
speedKph: speedKph,
24+
speedMph: speedMph,
25+
earthDistanceKm: earthDistanceKm,
26+
earthDistanceMi: earthDistanceMi,
27+
marsDistanceKm: marsDistanceKm,
28+
marsDistanceMi: marsDistanceMi,
29+
flickrImages: flickrImages,
30+
wikipedia: wikipedia,
31+
video: video,
32+
details: details,
33+
id: id,
34+
);
35+
}
36+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import 'package:equatable/equatable.dart';
2+
import 'package:flutter/foundation.dart';
3+
4+
@immutable
5+
class RoadsterResource extends Equatable {
6+
const RoadsterResource({
7+
this.name,
8+
this.launchDateUtc,
9+
this.launchDateUnix,
10+
this.launchMassKg,
11+
this.launchMassLbs,
12+
this.noradId,
13+
this.epochJd,
14+
this.orbitType,
15+
this.apoapsisAu,
16+
this.periapsisAu,
17+
this.semiMajorAxisAu,
18+
this.eccentricity,
19+
this.inclination,
20+
this.longitude,
21+
this.periapsisArg,
22+
this.periodDays,
23+
this.speedKph,
24+
this.speedMph,
25+
this.earthDistanceKm,
26+
this.earthDistanceMi,
27+
this.marsDistanceKm,
28+
this.marsDistanceMi,
29+
this.flickrImages,
30+
this.wikipedia,
31+
this.video,
32+
this.details,
33+
this.id,
34+
});
35+
36+
final String? name;
37+
final String? launchDateUtc;
38+
final int? launchDateUnix;
39+
final int? launchMassKg;
40+
final int? launchMassLbs;
41+
final int? noradId;
42+
final double? epochJd;
43+
final String? orbitType;
44+
final double? apoapsisAu;
45+
final double? periapsisAu;
46+
final double? semiMajorAxisAu;
47+
final double? eccentricity;
48+
final double? inclination;
49+
final double? longitude;
50+
final double? periapsisArg;
51+
final double? periodDays;
52+
final double? speedKph;
53+
final double? speedMph;
54+
final double? earthDistanceKm;
55+
final double? earthDistanceMi;
56+
final double? marsDistanceKm;
57+
final double? marsDistanceMi;
58+
final List<String>? flickrImages;
59+
final String? wikipedia;
60+
final String? video;
61+
final String? details;
62+
final String? id;
63+
64+
@override
65+
List<Object?> get props => [
66+
name,
67+
launchDateUtc,
68+
launchDateUnix,
69+
launchMassKg,
70+
launchMassLbs,
71+
noradId,
72+
epochJd,
73+
orbitType,
74+
apoapsisAu,
75+
periapsisAu,
76+
semiMajorAxisAu,
77+
eccentricity,
78+
inclination,
79+
longitude,
80+
periapsisArg,
81+
periodDays,
82+
speedKph,
83+
speedMph,
84+
earthDistanceKm,
85+
earthDistanceMi,
86+
marsDistanceKm,
87+
marsDistanceMi,
88+
flickrImages,
89+
wikipedia,
90+
video,
91+
details,
92+
id,
93+
];
94+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import 'package:flutter_bloc_app_template/data/network/model/roadster/network_roadster_model.dart';
2+
import 'package:flutter_bloc_app_template/models/roadster/roadster_ext.dart';
3+
import 'package:flutter_test/flutter_test.dart';
4+
5+
void main() {
6+
test('NetworkRoadsterModel.toResource maps correctly', () {
7+
final model = const NetworkRoadsterModel(
8+
name: "Elon Musk's Tesla Roadster",
9+
launchDateUtc: '2018-02-06T20:45:00.000Z',
10+
launchMassKg: 1350,
11+
flickrImages: ['url1', 'url2'],
12+
id: '123',
13+
);
14+
15+
final resource = model.toResource();
16+
17+
expect(resource.name, model.name);
18+
expect(resource.launchDateUtc, model.launchDateUtc);
19+
expect(resource.launchMassKg, model.launchMassKg);
20+
expect(resource.flickrImages, model.flickrImages);
21+
expect(resource.id, model.id);
22+
});
23+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import 'package:flutter_bloc_app_template/models/roadster/roadster_resource.dart';
2+
import 'package:flutter_test/flutter_test.dart';
3+
4+
void main() {
5+
group('RoadsterResource', () {
6+
test('can be instantiated with all fields', () {
7+
final resource = const RoadsterResource(
8+
name: "Elon Musk's Tesla Roadster",
9+
launchDateUtc: '2018-02-06T20:45:00.000Z',
10+
launchDateUnix: 1517949900,
11+
launchMassKg: 1350,
12+
launchMassLbs: 2976,
13+
noradId: 43205,
14+
epochJd: 2459914.263888889,
15+
orbitType: 'heliocentric',
16+
apoapsisAu: 1.664332332453025,
17+
periapsisAu: 0.986015924224046,
18+
semiMajorAxisAu: 57.70686413577451,
19+
eccentricity: 0.2559348215918733,
20+
inclination: 1.075052357364693,
21+
longitude: 316.9112133411523,
22+
periapsisArg: 177.75981116285,
23+
periodDays: 557.1958197697352,
24+
speedKph: 9520.88362029108,
25+
speedMph: 5916.000976023889,
26+
earthDistanceKm: 320593735.82924163,
27+
earthDistanceMi: 199207650.2259517,
28+
marsDistanceKm: 395640511.90355814,
29+
marsDistanceMi: 245839540.52202582,
30+
flickrImages: [
31+
'url1',
32+
'url2',
33+
],
34+
wikipedia: 'https://en.wikipedia.org/wiki/Elon_Musk%27s_Tesla_Roadster',
35+
video: 'https://youtu.be/wbSwFU6tY1c',
36+
details: 'Some details about Roadster',
37+
id: '5eb75f0842fea42237d7f3f4',
38+
);
39+
40+
expect(resource.name, "Elon Musk's Tesla Roadster");
41+
expect(resource.launchMassKg, 1350);
42+
expect(resource.flickrImages?.length, 2);
43+
});
44+
45+
test('supports equality', () {
46+
final r1 = const RoadsterResource(name: 'Roadster', launchMassKg: 1350);
47+
final r2 = const RoadsterResource(name: 'Roadster', launchMassKg: 1350);
48+
final r3 = const RoadsterResource(name: 'Roadster', launchMassKg: 1400);
49+
50+
expect(r1, r2); // same values -> equal
51+
expect(r1 == r3, false); // different launchMassKg -> not equal
52+
});
53+
54+
test('handles null values', () {
55+
final resource = const RoadsterResource();
56+
57+
expect(resource.name, isNull);
58+
expect(resource.launchMassKg, isNull);
59+
expect(resource.flickrImages, isNull);
60+
});
61+
});
62+
}

0 commit comments

Comments
 (0)