Skip to content

Commit

Permalink
chore: inputs from code review, added tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
rawi-coding committed Jan 20, 2025
1 parent 02723d1 commit e596af1
Show file tree
Hide file tree
Showing 29 changed files with 215 additions and 131 deletions.
59 changes: 41 additions & 18 deletions das_client/integration_test/test/train_journey_table_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import '../util/test_utils.dart';

void main() {
group('train journey table test', () {

testWidgets('test balise multiple level crossings', (tester) async {
await prepareAndStartApp(tester);

Expand Down Expand Up @@ -80,7 +79,8 @@ void main() {
final countText = find.descendant(of: groupOf5BaliseRow, matching: find.text('5'));
expect(countText, findsOneWidget);

final levelCrossingText = find.descendant(of: groupOf5BaliseRow, matching: find.text(l10n.p_train_journey_table_level_crossing));
final levelCrossingText =
find.descendant(of: groupOf5BaliseRow, matching: find.text(l10n.p_train_journey_table_level_crossing));
expect(levelCrossingText, findsOneWidget);

var detailRowBalise = findDASTableRowByText('41.552');
Expand All @@ -99,7 +99,9 @@ void main() {
expect(detailRowBalise, findsOneWidget);

expect(find.descendant(of: detailRowBalise, matching: find.byKey(BaliseRow.baliseIconKey)), findsOneWidget);
expect(find.descendant(of: detailRowLevelCrossing, matching: find.text(l10n.p_train_journey_table_level_crossing)), findsOneWidget);
expect(
find.descendant(of: detailRowLevelCrossing, matching: find.text(l10n.p_train_journey_table_level_crossing)),
findsOneWidget);

// collapse group
await tapElement(tester, groupOf5BaliseRow);
Expand Down Expand Up @@ -317,7 +319,7 @@ void main() {
it is Container &&
it.decoration is BoxDecoration &&
(it.decoration as BoxDecoration).color == AdditionalSpeedRestrictionRow.additionalSpeedRestrictionColor));
expect(coloredCells, findsNWidgets(12));
expect(coloredCells, findsNWidgets(13));
});

testWidgets('test other rows are displayed correctly', (tester) async {
Expand Down Expand Up @@ -540,21 +542,33 @@ void main() {
await tester.dragUntilVisible(find.text('Klammerbahnhof D1'), scrollableFinder, const Offset(0, -50));

final bracketStationD = findDASTableRowByText('Klammerbahnhof D');
final zahnstangenEnde = findDASTableRowByText('Zahnstangen Ende');
final deckungssignal = findDASTableRowByText('Deckungssignal');
final bracketStationD1 = findDASTableRowByText('Klammerbahnhof D1');
expect(bracketStationD, findsOneWidget);
expect(zahnstangenEnde, findsOneWidget);
expect(deckungssignal, findsOneWidget);
expect(bracketStationD1, findsOneWidget);

// check if the bracket station widget is displayed
final bracketStationDWidget =
find.descendant(of: bracketStationD, matching: find.byKey(BracketStationCellBody.bracketStationKey));
final zahnstangenEndeWidget =
find.descendant(of: zahnstangenEnde, matching: find.byKey(BracketStationCellBody.bracketStationKey));
final deckungssignalWidget =
find.descendant(of: deckungssignal, matching: find.byKey(BracketStationCellBody.bracketStationKey));
final bracketStationD1Widget =
find.descendant(of: bracketStationD1, matching: find.byKey(BracketStationCellBody.bracketStationKey));
expect(bracketStationDWidget, findsOneWidget);
expect(zahnstangenEndeWidget, findsOneWidget);
expect(deckungssignalWidget, findsOneWidget);
expect(bracketStationD1Widget, findsOneWidget);

// check that the abbreviation is displayed correctly
expect(find.descendant(of: bracketStationDWidget, matching: find.text('D')), findsNothing);
expect(find.descendant(of: bracketStationD1Widget, matching: find.text('D')), findsOneWidget);
expect(find.descendant(of: bracketStationDWidget, matching: find.text('D')), findsOneWidget);
expect(find.descendant(of: zahnstangenEndeWidget, matching: find.text('D')), findsNothing);
expect(find.descendant(of: deckungssignalWidget, matching: find.text('D')), findsNothing);
expect(find.descendant(of: bracketStationD1Widget, matching: find.text('D')), findsNothing);
});

testWidgets('test halt on request is displayed correctly', (tester) async {
Expand All @@ -566,7 +580,7 @@ void main() {
final scrollableFinder = find.byType(ListView);
expect(scrollableFinder, findsOneWidget);

await tester.dragUntilVisible(find.text('Halt auf Verlangen C'), scrollableFinder, const Offset(0, -50));
await tester.dragUntilVisible(find.text('Klammerbahnhof D'), scrollableFinder, const Offset(0, -50));

final stopOnDemandRow = findDASTableRowByText('Halt auf Verlangen C');
expect(stopOnDemandRow, findsOneWidget);
Expand Down Expand Up @@ -783,50 +797,59 @@ void main() {

final bernStationRow = findDASTableRowByText('Bern');
expect(bernStationRow, findsOneWidget);
final bernIncomingSpeeds = find.descendant(of: bernStationRow, matching: find.byKey(GraduatedSpeedsCellBody.incomingSpeedsKey));
final bernIncomingSpeeds =
find.descendant(of: bernStationRow, matching: find.byKey(GraduatedSpeedsCellBody.incomingSpeedsKey));
expect(bernIncomingSpeeds, findsNWidgets(2));
final bernIncomingSpeedsText = find.descendant(of: bernStationRow, matching: find.text('75-70-60'));
expect(bernIncomingSpeedsText, findsOneWidget);
final bernOutgoingSpeeds = find.descendant(of: bernStationRow, matching: find.byKey(GraduatedSpeedsCellBody.outgoingSpeedsKey));
final bernOutgoingSpeeds =
find.descendant(of: bernStationRow, matching: find.byKey(GraduatedSpeedsCellBody.outgoingSpeedsKey));
expect(bernOutgoingSpeeds, findsNothing);

// check station speeds for Wankdorf, no station speeds given

final wankdorfStationRow = findDASTableRowByText('Wankdorf');
expect(wankdorfStationRow, findsOneWidget);
final wankdorfIncomingSpeeds = find.descendant(of: wankdorfStationRow, matching: find.byKey(GraduatedSpeedsCellBody.incomingSpeedsKey));
final wankdorfIncomingSpeeds =
find.descendant(of: wankdorfStationRow, matching: find.byKey(GraduatedSpeedsCellBody.incomingSpeedsKey));
expect(wankdorfIncomingSpeeds, findsNothing);
final wankdorfOutgoingSpeeds = find.descendant(of: wankdorfStationRow, matching: find.byKey(GraduatedSpeedsCellBody.outgoingSpeedsKey));
final wankdorfOutgoingSpeeds =
find.descendant(of: wankdorfStationRow, matching: find.byKey(GraduatedSpeedsCellBody.outgoingSpeedsKey));
expect(wankdorfOutgoingSpeeds, findsNothing);

// check station speeds for Burgdorf

final burgdorfStationRow = findDASTableRowByText('Burgdorf');
expect(burgdorfStationRow, findsOneWidget);
final burgdorfIncomingSpeeds = find.descendant(of: burgdorfStationRow, matching: find.byKey(GraduatedSpeedsCellBody.incomingSpeedsKey));
final burgdorfIncomingSpeeds =
find.descendant(of: burgdorfStationRow, matching: find.byKey(GraduatedSpeedsCellBody.incomingSpeedsKey));
expect(burgdorfIncomingSpeeds, findsNWidgets(2));
final burgdorfIncomingSpeeds75 = find.descendant(of: burgdorfIncomingSpeeds, matching: find.text('75'));
expect(burgdorfIncomingSpeeds75, findsOneWidget);
final burgdorfIncomingSpeeds70 = find.descendant(of: burgdorfIncomingSpeeds, matching: find.text('70'));
expect(burgdorfIncomingSpeeds70, findsOneWidget);
final burgdorfIncomingSpeeds70Circled = find.ancestor(of: burgdorfIncomingSpeeds70, matching: find.byKey(GraduatedSpeedsCellBody.circledSpeedKey));
final burgdorfIncomingSpeeds70Circled =
find.ancestor(of: burgdorfIncomingSpeeds70, matching: find.byKey(GraduatedSpeedsCellBody.circledSpeedKey));
expect(burgdorfIncomingSpeeds70Circled, findsOneWidget);
final burgdorfOutgoingSpeeds = find.descendant(of: burgdorfStationRow, matching: find.byKey(GraduatedSpeedsCellBody.outgoingSpeedsKey));
final burgdorfOutgoingSpeeds =
find.descendant(of: burgdorfStationRow, matching: find.byKey(GraduatedSpeedsCellBody.outgoingSpeedsKey));
expect(burgdorfOutgoingSpeeds, findsOneWidget);
final burgdorfOutgoingSpeeds60 = find.descendant(of: burgdorfOutgoingSpeeds, matching: find.text('60'));
expect(burgdorfOutgoingSpeeds60, findsOneWidget);
final burgdorfOutgoingSpeeds60Squared = find.ancestor(of: burgdorfOutgoingSpeeds60, matching: find.byKey(GraduatedSpeedsCellBody.squaredSpeedKey));
final burgdorfOutgoingSpeeds60Squared =
find.ancestor(of: burgdorfOutgoingSpeeds60, matching: find.byKey(GraduatedSpeedsCellBody.squaredSpeedKey));
expect(burgdorfOutgoingSpeeds60Squared, findsOneWidget);

// check station speeds for Olten, no graduated speed for train series R

final oltenStationRow = findDASTableRowByText('Olten');
expect(oltenStationRow, findsOneWidget);
final oltenIncomingSpeeds = find.descendant(of: oltenStationRow, matching: find.byKey(GraduatedSpeedsCellBody.incomingSpeedsKey));
final oltenIncomingSpeeds =
find.descendant(of: oltenStationRow, matching: find.byKey(GraduatedSpeedsCellBody.incomingSpeedsKey));
expect(oltenIncomingSpeeds, findsOneWidget);
final oltenOutgoingSpeeds = find.descendant(of: oltenStationRow, matching: find.byKey(GraduatedSpeedsCellBody.outgoingSpeedsKey));
final oltenOutgoingSpeeds =
find.descendant(of: oltenStationRow, matching: find.byKey(GraduatedSpeedsCellBody.outgoingSpeedsKey));
expect(oltenOutgoingSpeeds, findsNothing);

});
});
}
Expand Down
2 changes: 1 addition & 1 deletion das_client/lib/app/bloc/train_journey_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:async';

import 'package:das_client/app/model/ru.dart';
import 'package:das_client/app/pages/journey/train_journey/widgets/table/render_data/train_journey_settings.dart';
import 'package:das_client/app/pages/journey/train_journey/widgets/table/config/train_journey_settings.dart';
import 'package:das_client/model/journey/break_series.dart';
import 'package:das_client/model/journey/journey.dart';
import 'package:das_client/sfera/sfera_component.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AdditionalSpeedRestrictionRow extends BaseRowBuilder<AdditionalSpeedRestri
const AdditionalSpeedRestrictionRow({
required super.metadata,
required super.data,
super.renderData,
super.config,
}) : super(rowColor: additionalSpeedRestrictionColor);

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class BaliseLevelCrossingGroupRow extends BaseRowBuilder<BaliseLevelCrossingGrou
const BaliseLevelCrossingGroupRow({
required super.metadata,
required super.data,
super.renderData,
super.config,
super.onTap,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class BaliseRow extends BaseRowBuilder<Balise> {
const BaliseRow({
required super.metadata,
required super.data,
super.renderData,
super.config,
super.isGrouped,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:das_client/app/pages/journey/train_journey/widgets/table/cells/g
import 'package:das_client/app/pages/journey/train_journey/widgets/table/cells/bracket_station_cell_body.dart';
import 'package:das_client/app/pages/journey/train_journey/widgets/table/cells/route_cell_body.dart';
import 'package:das_client/app/pages/journey/train_journey/widgets/table/cells/track_equipment_cell_body.dart';
import 'package:das_client/app/pages/journey/train_journey/widgets/table/render_data/train_journey_render_data.dart';
import 'package:das_client/app/pages/journey/train_journey/widgets/table/config/train_journey_config.dart';
import 'package:das_client/app/widgets/table/das_table_cell.dart';
import 'package:das_client/app/widgets/table/das_table_row.dart';
import 'package:das_client/model/journey/additional_speed_restriction.dart';
Expand All @@ -20,7 +20,7 @@ class BaseRowBuilder<T extends BaseData> extends DASTableRowBuilder {
required this.metadata,
required this.data,
super.height = rowHeight,
this.renderData = const TrainJourneyRenderData(),
this.config = const TrainJourneyConfig(),
this.defaultAlignment = Alignment.bottomCenter,
this.rowColor,
this.onTap,
Expand All @@ -31,7 +31,7 @@ class BaseRowBuilder<T extends BaseData> extends DASTableRowBuilder {
final Color? rowColor;
final Metadata metadata;
final T data;
final TrainJourneyRenderData renderData;
final TrainJourneyConfig config;
final VoidCallback? onTap;
final bool isGrouped;

Expand Down Expand Up @@ -92,12 +92,16 @@ class BaseRowBuilder<T extends BaseData> extends DASTableRowBuilder {
}

DASTableCell trackEquipment(BuildContext context) {
if (config.trackEquipmentRenderData == null) {
return DASTableCell.empty(color: specialCellColor);
}

return DASTableCell(
color: specialCellColor,
padding: EdgeInsets.all(0.0),
alignment: null,
child: TrackEquipmentCellBody(
renderData: renderData.trackEquipmentRenderData,
renderData: config.trackEquipmentRenderData!,
),
);
}
Expand Down Expand Up @@ -128,9 +132,9 @@ class BaseRowBuilder<T extends BaseData> extends DASTableRowBuilder {
}

final currentTrainSeries =
renderData.settings.selectedBreakSeries?.trainSeries ?? metadata.breakSeries?.trainSeries;
config.settings.selectedBreakSeries?.trainSeries ?? metadata.breakSeries?.trainSeries;
final currentBreakSeries =
renderData.settings.selectedBreakSeries?.breakSeries ?? metadata.breakSeries?.breakSeries;
config.settings.selectedBreakSeries?.breakSeries ?? metadata.breakSeries?.breakSeries;

final graduatedSpeeds = speedData.speedsFor(currentTrainSeries, currentBreakSeries);
if (graduatedSpeeds == null) {
Expand All @@ -152,15 +156,15 @@ class BaseRowBuilder<T extends BaseData> extends DASTableRowBuilder {
}

DASTableCell bracketStation(BuildContext context) {
final bracketStationRenderData = renderData.bracketStationRenderData;
if (!bracketStationRenderData.isWithin) return DASTableCell.empty();
final bracketStationRenderData = config.bracketStationRenderData;
if (bracketStationRenderData == null) return DASTableCell.empty();

return DASTableCell(
padding: EdgeInsets.all(0.0),
clipBehaviour: Clip.none,
child: BracketStationCellBody(
stationAbbreviation:
renderData.bracketStationRenderData.isStart ? bracketStationRenderData.stationAbbreviation : null,
config.bracketStationRenderData!.isStart ? bracketStationRenderData.stationAbbreviation : null,
height: height,
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CABSignalingRow extends BaseRowBuilder<CABSignaling> {
const CABSignalingRow({
required super.metadata,
required super.data,
super.renderData,
super.config,
});

@override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:das_client/app/pages/journey/train_journey/widgets/table/render_data/track_equipment_render_data.dart';
import 'package:das_client/app/pages/journey/train_journey/widgets/table/config/track_equipment_render_data.dart';
import 'package:das_client/app/widgets/table/das_table_theme.dart';
import 'package:das_client/model/journey/track_equipment_segment.dart';
import 'package:flutter/material.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,19 @@ class BracketStationRenderData {
const BracketStationRenderData({
this.stationAbbreviation,
this.isStart = false,
this.isWithin = false,
});

final String? stationAbbreviation;
final bool isStart;
final bool isWithin;

factory BracketStationRenderData.from(List<BaseData> rowData, Metadata metadata, int index) {
final data = rowData[index];
static BracketStationRenderData? from(BaseData data, Metadata metadata) {
final bracketStationSegments = metadata.bracketStationSegments;
final segment = bracketStationSegments.appliesToOrder(data.order);
if (segment == null) return BracketStationRenderData();
if (segment == null) return null;

return BracketStationRenderData(
stationAbbreviation: segment.mainStationAbbreviation,
isStart: data.order == segment.startOrder,
isWithin: true,
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class TrackEquipmentRenderData {
final bool isConventionalExtendedSpeedBorder;
final TrackEquipmentType? trackEquipmentType;

factory TrackEquipmentRenderData.from(List<BaseData> rowData, Metadata metadata, int index) {
static TrackEquipmentRenderData? from(List<BaseData> rowData, Metadata metadata, int index) {
final data = rowData[index];
final nonStandardTrackEquipmentSegments = metadata.nonStandardTrackEquipmentSegments;
final trackEquipment = nonStandardTrackEquipmentSegments.appliesToOrder(data.order).firstOrNull;
if (trackEquipment == null || !trackEquipment.isEtcsL2Segment) return TrackEquipmentRenderData();
if (trackEquipment == null || !trackEquipment.isEtcsL2Segment) return null;

return TrackEquipmentRenderData(
trackEquipmentType: trackEquipment.type,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import 'package:das_client/app/pages/journey/train_journey/widgets/table/config/bracket_station_render_data.dart';
import 'package:das_client/app/pages/journey/train_journey/widgets/table/config/track_equipment_render_data.dart';
import 'package:das_client/app/pages/journey/train_journey/widgets/table/config/train_journey_settings.dart';

/// Data class to hold all the information to visualize the train journey.
class TrainJourneyConfig {
const TrainJourneyConfig({
this.trackEquipmentRenderData,
this.bracketStationRenderData,
this.settings = const TrainJourneySettings(),
});

final TrainJourneySettings settings;
final TrackEquipmentRenderData? trackEquipmentRenderData;
final BracketStationRenderData? bracketStationRenderData;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ConnectionTrackRow extends BaseRowBuilder<ConnectionTrack> {
const ConnectionTrackRow({
required super.metadata,
required super.data,
super.renderData,
super.config,
});

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CurvePointRow extends BaseRowBuilder<CurvePoint> {
const CurvePointRow({
required super.metadata,
required super.data,
super.renderData,
super.config,
});

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class LevelCrossingRow extends BaseRowBuilder<LevelCrossing> {
const LevelCrossingRow({
required super.metadata,
required super.data,
super.renderData,
super.config,
super.isGrouped,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ProtectionSectionRow extends BaseRowBuilder<ProtectionSection> {
const ProtectionSectionRow({
required super.metadata,
required super.data,
super.renderData,
super.config,
}) : super(rowColor: SBBColors.peach);

@override
Expand Down

This file was deleted.

Loading

0 comments on commit e596af1

Please sign in to comment.