Skip to content
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

feat: implement anschlussgleise, anschlussweichen und Zahnstangen (#136) #447

Merged
merged 7 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
56 changes: 50 additions & 6 deletions das_client/integration_test/test/train_journey_table_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,45 @@ import '../util/test_utils.dart';

void main() {
group('train journey table test', () {
testWidgets('test connection track is displayed correctly', (tester) async {
await prepareAndStartApp(tester);

// load train journey by filling out train selection page
await _loadTrainJourney(tester, trainNumber: '9999');

final scrollableFinder = find.byType(ListView);
expect(scrollableFinder, findsOneWidget);

final weicheRow = findDASTableRowByText('Weiche');
expect(weicheRow, findsOneWidget);

final weicheKilometre = find.descendant(of: weicheRow, matching: find.text('0.8'));
expect(weicheKilometre, findsOneWidget);

await tester.dragUntilVisible(find.text('AnG. WITZ'), scrollableFinder, const Offset(0, -50));

final connectionTrackRow = findDASTableRowByText('AnG. WITZ');
expect(connectionTrackRow, findsOneWidget);

await tester.dragUntilVisible(find.text('22-6 Uhr'), scrollableFinder, const Offset(0, -50));

final connectionTrackWithSpeedRow = findDASTableRowByText('22-6 Uhr');
expect(connectionTrackWithSpeedRow, findsOneWidget);

final speedInformation = find.descendant(of: connectionTrackWithSpeedRow, matching: find.text('45'));
expect(speedInformation, findsOneWidget);

await tester.dragUntilVisible(find.text('Zahnstangen Anfang'), scrollableFinder, const Offset(0, -50));

final zahnstangeAnfangRow = findDASTableRowByText('Zahnstangen Anfang');
expect(zahnstangeAnfangRow, findsOneWidget);

await tester.dragUntilVisible(find.text('Zahnstangen Ende'), scrollableFinder, const Offset(0, -50));

final zahnstangeEndeRow = findDASTableRowByText('Zahnstangen Ende');
expect(zahnstangeEndeRow, findsOneWidget);
});

testWidgets('test additional speed restriction row is displayed correctly', (tester) async {
await prepareAndStartApp(tester);

Expand Down Expand Up @@ -65,9 +104,10 @@ void main() {
final coloredCells = find.descendant(
of: testRow,
matching: find.byWidgetPredicate((it) =>
it is Container &&
it is Container &&
it.decoration is BoxDecoration &&
(it.decoration as BoxDecoration).color == AdditionalSpeedRestrictionRow.additionalSpeedRestrictionColor));
(it.decoration as BoxDecoration).color ==
AdditionalSpeedRestrictionRow.additionalSpeedRestrictionColor));
expect(coloredCells, findsNWidgets(3));
}
});
Expand Down Expand Up @@ -110,7 +150,8 @@ void main() {

// check stop circles
final stopRoute = find.descendant(of: stopRouteRow, matching: find.byKey(RouteCellBody.stopKey));
final nonStoppingPassRoute = find.descendant(of: nonStoppingPassRouteRow, matching: find.byKey(RouteCellBody.stopKey));
final nonStoppingPassRoute =
find.descendant(of: nonStoppingPassRouteRow, matching: find.byKey(RouteCellBody.stopKey));
expect(stopRoute, findsOneWidget);
expect(nonStoppingPassRoute, findsNothing);

Expand Down Expand Up @@ -349,23 +390,26 @@ void main() {
final langeChangeBlockSignalRow = findDASTableRowByText('S1');
expect(langeChangeBlockSignalRow, findsOneWidget);
expect(find.descendant(of: langeChangeBlockSignalRow, matching: find.text('Block')), findsOneWidget);
final laneChangeIcon = find.descendant(of: langeChangeBlockSignalRow, matching: find.byKey(SignalRow.signalLineChangeIconKey));
final laneChangeIcon =
find.descendant(of: langeChangeBlockSignalRow, matching: find.byKey(SignalRow.signalLineChangeIconKey));
expect(laneChangeIcon, findsOneWidget);

// check if basic signal is rendered correctly
await tester.dragUntilVisible(find.text('Deckungssignal'), scrollableFinder, const Offset(0, -50));
final protectionSignalRow = findDASTableRowByText('Deckungssignal');
expect(protectionSignalRow, findsOneWidget);
expect(find.descendant(of: protectionSignalRow, matching: find.text('D1')), findsOneWidget);
final noLaneChangeIcon = find.descendant(of: protectionSignalRow, matching: find.byKey(SignalRow.signalLineChangeIconKey));
final noLaneChangeIcon =
find.descendant(of: protectionSignalRow, matching: find.byKey(SignalRow.signalLineChangeIconKey));
expect(noLaneChangeIcon, findsNothing);

// check if signals with multiple functions are rendered correctly
await tester.dragUntilVisible(find.text('Block/Abschnittsignal'), scrollableFinder, const Offset(0, -50));
final blockIntermediateSignalRow = findDASTableRowByText('Block/Abschnittsignal');
expect(blockIntermediateSignalRow, findsOneWidget);
expect(find.descendant(of: blockIntermediateSignalRow, matching: find.text('BAB1')), findsOneWidget);
final noLaneChangeIcon2 = find.descendant(of: blockIntermediateSignalRow, matching: find.byKey(SignalRow.signalLineChangeIconKey));
final noLaneChangeIcon2 =
find.descendant(of: blockIntermediateSignalRow, matching: find.byKey(SignalRow.signalLineChangeIconKey));
expect(noLaneChangeIcon2, findsNothing);
});
});
Expand Down
3 changes: 2 additions & 1 deletion das_client/l10n/strings_de.arb
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@
"c_error_sfera_handshake_rejected": "Server hat die Verbindung abgelehnt",
"c_error_sfera_request_timeout": "Timeout bei der Anfrage",
"c_error_sfera_jp_unavailable": "Fahrordnung nicht vorhanden",
"c_error_sfera_sp_invalid": "Unvollständige Daten erhalten"
"c_error_sfera_sp_invalid": "Unvollständige Daten erhalten",
"c_connection_track_weiche": "Weiche"
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,14 @@ class BaseRowBuilder<T extends BaseData> extends DASTableRowBuilder {
}

DASTableCell graduatedSpeedCell(BuildContext context) {
return DASTableCell.empty();
if (data.speedData == null) {
return DASTableCell.empty();
}

return DASTableCell(
child: Text(data.speedData!.resolvedSpeed(metadata.trainSeries, metadata.breakSeries) ?? ''),
alignment: Alignment.center,
);
}

DASTableCell advisedSpeedCell(BuildContext context) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:das_client/app/i18n/i18n.dart';
import 'package:das_client/app/pages/journey/train_journey/widgets/table/base_row_builder.dart';
import 'package:das_client/app/widgets/table/das_table_cell.dart';
import 'package:das_client/model/journey/connection_track.dart';
import 'package:flutter/material.dart';

class ConnectionTrackRow extends BaseRowBuilder<ConnectionTrack> {
ConnectionTrackRow({
required super.metadata,
required super.data,
});

@override
DASTableCell informationCell(BuildContext context) {
return DASTableCell(
child: Text(data.text ?? context.l10n.c_connection_track_weiche),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ class ServicePointRow extends BaseRowBuilder<ServicePoint> {
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(servicePointName, style: textStyle),
Spacer(),
Text('B12'),
],
),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'package:das_client/app/pages/journey/train_journey/widgets/table/base_row_builder.dart';
import 'package:das_client/app/widgets/table/das_table_cell.dart';
import 'package:das_client/model/journey/speed_change.dart';
import 'package:flutter/material.dart';

class SpeedChangeRow extends BaseRowBuilder<SpeedChange> {
SpeedChangeRow({
required super.metadata,
required super.data,
});

@override
DASTableCell informationCell(BuildContext context) {
return DASTableCell(
child: Text(data.text ?? ''),
);
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import 'package:das_client/app/bloc/train_journey_cubit.dart';
import 'package:das_client/app/i18n/i18n.dart';
import 'package:das_client/app/pages/journey/train_journey/widgets/table/additional_speed_restriction_row.dart';
import 'package:das_client/app/pages/journey/train_journey/widgets/table/connection_track_row.dart';
import 'package:das_client/app/pages/journey/train_journey/widgets/table/curve_point_row.dart';
import 'package:das_client/app/pages/journey/train_journey/widgets/table/protection_section_row.dart';
import 'package:das_client/app/pages/journey/train_journey/widgets/table/service_point_row.dart';
import 'package:das_client/app/pages/journey/train_journey/widgets/table/signal_row.dart';
import 'package:das_client/app/pages/journey/train_journey/widgets/table/speed_change_row.dart';
import 'package:das_client/app/widgets/table/das_table.dart';
import 'package:das_client/app/widgets/table/das_table_column.dart';
import 'package:das_client/app/widgets/table/das_table_row.dart';
import 'package:das_client/model/journey/additional_speed_restriction_data.dart';
import 'package:das_client/model/journey/connection_track.dart';
import 'package:das_client/model/journey/curve_point.dart';
import 'package:das_client/model/journey/datatype.dart';
import 'package:das_client/model/journey/journey.dart';
import 'package:das_client/model/journey/protection_section.dart';
import 'package:das_client/model/journey/service_point.dart';
import 'package:das_client/model/journey/signal.dart';
import 'package:das_client/model/journey/speed_change.dart';
import 'package:design_system_flutter/design_system_flutter.dart';
import 'package:flutter/material.dart';

Expand Down Expand Up @@ -65,6 +69,10 @@ class TrainJourney extends StatelessWidget {
return AdditionalSpeedRestrictionRow(
metadata: journey.metadata, data: rowData as AdditionalSpeedRestrictionData)
.build(context);
case Datatype.connectionTrack:
return ConnectionTrackRow(metadata: journey.metadata, data: rowData as ConnectionTrack).build(context);
case Datatype.speedChange:
return SpeedChangeRow(metadata: journey.metadata, data: rowData as SpeedChange).build(context);
}
});
}
Expand Down
3 changes: 3 additions & 0 deletions das_client/lib/model/journey/base_data.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:das_client/model/journey/datatype.dart';
import 'package:das_client/model/journey/speed_data.dart';
import 'package:das_client/model/journey/track_equipment.dart';

abstract class BaseData {
Expand All @@ -7,10 +8,12 @@ abstract class BaseData {
required this.order,
required this.kilometre,
this.trackEquipment = const [],
this.speedData,
});

final Datatype type;
final int order;
final List<double> kilometre;
final List<TrackEquipment> trackEquipment;
final SpeedData? speedData;
}
9 changes: 9 additions & 0 deletions das_client/lib/model/journey/connection_track.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:das_client/model/journey/base_data.dart';
import 'package:das_client/model/journey/datatype.dart';

class ConnectionTrack extends BaseData {
ConnectionTrack({required super.order, required super.kilometre, this.text, super.speedData})
: super(type: Datatype.connectionTrack);

final String? text;
}
4 changes: 3 additions & 1 deletion das_client/lib/model/journey/datatype.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ enum Datatype {
protectionSection,
signal,
curvePoint,
additionalSpeedRestriction;
additionalSpeedRestriction,
connectionTrack,
speedChange;
}
7 changes: 6 additions & 1 deletion das_client/lib/model/journey/metadata.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import 'package:das_client/model/journey/additional_speed_restriction.dart';
import 'package:das_client/model/journey/base_data.dart';
import 'package:das_client/model/journey/service_point.dart';
import 'package:das_client/model/journey/train_series.dart';

class Metadata {
Metadata(
{this.nextStop,
this.currentPosition,
this.routeStart,
this.routeEnd,
List<AdditionalSpeedRestriction>? additionalSpeedRestrictions})
List<AdditionalSpeedRestriction>? additionalSpeedRestrictions,
this.trainSeries = TrainSeries.R,
this.breakSeries = 150})
: additionalSpeedRestrictions = additionalSpeedRestrictions ?? [];

final ServicePoint? nextStop;
final BaseData? currentPosition;
final List<AdditionalSpeedRestriction> additionalSpeedRestrictions;
final BaseData? routeStart;
final BaseData? routeEnd;
final TrainSeries trainSeries;
final int breakSeries;
rawi-coding marked this conversation as resolved.
Show resolved Hide resolved
}
9 changes: 9 additions & 0 deletions das_client/lib/model/journey/speed_change.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:das_client/model/journey/base_data.dart';
import 'package:das_client/model/journey/datatype.dart';

class SpeedChange extends BaseData {
SpeedChange({required super.order, required super.kilometre, required super.speedData, this.text})
: super(type: Datatype.speedChange);

final String? text;
}
16 changes: 16 additions & 0 deletions das_client/lib/model/journey/speed_data.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:collection/collection.dart';
import 'package:das_client/model/journey/train_series.dart';
import 'package:das_client/model/journey/velocity.dart';

class SpeedData {
SpeedData({this.velocities = const []});

final List<Velocity> velocities;

String? resolvedSpeed(TrainSeries trainSeries, int breakSeries) {
final trainSeriesVelocities = velocities.where((it) => it.trainSeries == trainSeries);
final exactMatchingVelocity = trainSeriesVelocities.firstWhereOrNull((it) => it.breakSeries == breakSeries);
return exactMatchingVelocity?.speed ??
trainSeriesVelocities.firstWhereOrNull((it) => it.breakSeries == null)?.speed;
}
}
15 changes: 15 additions & 0 deletions das_client/lib/model/journey/train_series.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
enum TrainSeries {
A,
D,
N,
O,
R,
W,
S;

factory TrainSeries.from(String value) {
return values.firstWhere(
(e) => e.name.toLowerCase() == value.toLowerCase(),
);
}
}
15 changes: 15 additions & 0 deletions das_client/lib/model/journey/velocity.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import 'package:das_client/model/journey/train_series.dart';

class Velocity {
Velocity({
required this.trainSeries,
required this.reduced,
this.breakSeries,
this.speed,
});

final TrainSeries trainSeries;
final int? breakSeries;
final String? speed;
final bool reduced;
}
Loading
Loading