Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Grodien committed Dec 17, 2024
1 parent 4d4f9d3 commit 7f00c15
Show file tree
Hide file tree
Showing 11 changed files with 176 additions and 23 deletions.
150 changes: 142 additions & 8 deletions das_client/integration_test/test/train_journey_table_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,145 @@ import 'package:das_client/app/pages/journey/train_journey/widgets/table/curve_p
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/train_journey.dart';
import 'package:das_client/app/pages/profile/profile_page.dart';
import 'package:das_client/app/widgets/table/das_table.dart';
import 'package:sbb_design_system_mobile/sbb_design_system_mobile.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:sbb_design_system_mobile/sbb_design_system_mobile.dart';

import '../app_test.dart';
import '../util/test_utils.dart';

void main() {
group('train journey table test', () {
testWidgets('test breaking series defaults to ??', (tester) async {
await prepareAndStartApp(tester);

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

testWidgets('test breaking series defaults to R150', (tester) async {
final breakingSeriesHeaderCell = find.byKey(TrainJourney.breakingSeriesHeaderKey);
expect(breakingSeriesHeaderCell, findsOneWidget);
expect(find.descendant(of: breakingSeriesHeaderCell, matching: find.text('??')), findsNWidgets(1));
});

testWidgets('test default breaking series is taken from train characteristics (R115)', (tester) async {
await prepareAndStartApp(tester);

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

final scrollableFinder = find.byType(ListView);
expect(scrollableFinder, findsOneWidget);
final breakingSeriesHeaderCell = find.byKey(TrainJourney.breakingSeriesHeaderKey);
expect(breakingSeriesHeaderCell, findsOneWidget);
expect(find.descendant(of: breakingSeriesHeaderCell, matching: find.text('R115')), findsNWidgets(1));
});

testWidgets('test all breakseries options are displayed', (tester) async {
await prepareAndStartApp(tester);

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

// Open break series bottom sheet
await tapElement(tester, find.byKey(TrainJourney.breakingSeriesHeaderKey));

final expectedCategories = {'R', 'A', 'D'};

for (final entry in expectedCategories) {
expect(find.text(entry), findsOneWidget);
}

final expectedOptions = {
'R105',
'R115',
'R125',
'R135',
'R150',
'A50',
'A60',
'A65',
'A70',
'A75',
'A80',
'A85',
'A95',
'A105',
'A115',
'D30'
};

for (final entry in expectedOptions) {
expect(find.text(entry), findsAtLeast(1));
}
});

testWidgets('test speed values of default breakSeries (R115)', (tester) async {
await prepareAndStartApp(tester);

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

final expectedSpeeds = {
'Genève-Aéroport': '60',
'65.3': '44', // 1. Curve
'New Line Speed All': '60',
'Genève': '60',
'New Line Speed A Missing': '60',
'42.5': '44', // 2. Curve
'40.5': null, // 3. Curve
'Gland': '60',
};

for (final entry in expectedSpeeds.entries) {
final tableRow = findDASTableRowByText(entry.key);
expect(tableRow, findsOneWidget);

if (entry.value != null) {
final speedText = find.descendant(of: tableRow, matching: find.text(entry.value!));
expect(speedText, findsOneWidget);
} else {
final textWidgets = find.descendant(of: tableRow, matching: find.byWidgetPredicate((it) => it is Text));
expect(textWidgets, findsNWidgets(2)); // KM and Kurve text widgets
}
}
});

testWidgets('test speed values of missing break Series', (tester) async {
await prepareAndStartApp(tester);

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

await _selectBreakSeries(tester, breakSeries: 'A85');

final breakingSeriesHeaderCell = find.byKey(TrainJourney.breakingSeriesHeaderKey);
expect(breakingSeriesHeaderCell, findsOneWidget);
expect(find.descendant(of: breakingSeriesHeaderCell, matching: find.text('A85')), findsNWidgets(1));

final expectedSpeeds = {
'Genève-Aéroport': '90',
'65.3': '55', // 1. Curve
'New Line Speed All': '90',
'Genève': 'XX',
'New Line Speed A Missing': 'XX',
'42.5': 'XX', // 2. Curve
'40.5': null, // 3. Curve
'Gland': '90',
};

for (final entry in expectedSpeeds.entries) {
final tableRow = findDASTableRowByText(entry.key);
expect(tableRow, findsOneWidget);

if (entry.value != null) {
final speedText = find.descendant(of: tableRow, matching: find.text(entry.value!));
expect(speedText, findsOneWidget);
} else {
final textWidgets = find.descendant(of: tableRow, matching: find.byWidgetPredicate((it) => it is Text));
expect(textWidgets, findsNWidgets(2)); // KM and Kurve text widgets
}
}
});

testWidgets('test connection track is displayed correctly', (tester) async {
Expand Down Expand Up @@ -448,7 +566,8 @@ void main() {
final rowsAtKm33_8 = findDASTableRowByText('33.8');
expect(rowsAtKm33_8, findsExactly(2));
final segment1CABStop = rowsAtKm33_8.last; // end should be after other elements at same location
final segment1CABStopIcon = find.descendant(of: segment1CABStop, matching: find.byKey(CABSignalingRow.cabSignalingEndIconKey));
final segment1CABStopIcon =
find.descendant(of: segment1CABStop, matching: find.byKey(CABSignalingRow.cabSignalingEndIconKey));
expect(segment1CABStopIcon, findsOneWidget);

// Track equipment segment without ETCS level 2 should be ignored
Expand All @@ -460,7 +579,8 @@ void main() {
final rowsAtKm12_5 = findDASTableRowByText('12.5');
expect(rowsAtKm12_5, findsExactly(2));
final segment2CABStart = rowsAtKm12_5.first; // start should be before other elements at same location
final segment2CABStartIcon = find.descendant(of: segment2CABStart, matching: find.byKey(CABSignalingRow.cabSignalingStartIconKey));
final segment2CABStartIcon =
find.descendant(of: segment2CABStart, matching: find.byKey(CABSignalingRow.cabSignalingStartIconKey));
expect(segment2CABStartIcon, findsOneWidget);
await tester.dragUntilVisible(find.text('75.3'), scrollableFinder, const Offset(0, -50));
final trackEquipmentTypeChange = findDASTableRowByText('56.8');
Expand All @@ -469,13 +589,15 @@ void main() {
final rothristServicePointRow = findDASTableRowByText('46.2');
expect(rothristServicePointRow, findsOneWidget); // no CAB signaling at connecting ETCS L2 segments
final segment2CABEnd = findDASTableRowByText('39.9');
final segment2CABEndIcon = find.descendant(of: segment2CABEnd, matching: find.byKey(CABSignalingRow.cabSignalingEndIconKey));
final segment2CABEndIcon =
find.descendant(of: segment2CABEnd, matching: find.byKey(CABSignalingRow.cabSignalingEndIconKey));
expect(segment2CABEndIcon, findsOneWidget);

// CAB segment with end outside train journey and start at 8.3 km
await tester.dragUntilVisible(find.text('9.5'), scrollableFinder, const Offset(0, -50));
final segment3CABStart = findDASTableRowByText('8.3');
final segment3CABStartIcon = find.descendant(of: segment3CABStart, matching: find.byKey(CABSignalingRow.cabSignalingStartIconKey));
final segment3CABStartIcon =
find.descendant(of: segment3CABStart, matching: find.byKey(CABSignalingRow.cabSignalingStartIconKey));
expect(segment3CABStartIcon, findsOneWidget);
});
});
Expand All @@ -498,3 +620,15 @@ Future<void> _loadTrainJourney(WidgetTester tester, {required String trainNumber
// wait for train journey to load
await tester.pumpAndSettle();
}

Future<void> _selectBreakSeries(WidgetTester tester, {required String breakSeries}) async {
// Open break series bottom sheet
await tapElement(tester, find.byKey(TrainJourney.breakingSeriesHeaderKey));

// Check if the bottom sheeet is opened
expect(find.text(l10n.p_train_journey_break_series), findsOneWidget);
await tapElement(tester, find.text(breakSeries));

// confirm button
await tapElement(tester, find.text(l10n.c_button_confirm));
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import 'package:sbb_design_system_mobile/sbb_design_system_mobile.dart';
class TrainJourney extends StatelessWidget {
const TrainJourney({super.key});

static const Key breakingSeriesHeaderKey = Key('breaking_series_header_key');

@override
Widget build(BuildContext context) {
final bloc = context.trainJourneyCubit;
Expand Down Expand Up @@ -97,7 +99,7 @@ class TrainJourney extends StatelessWidget {
List<DASTableColumn> _columns(BuildContext context, Journey journey, TrainJourneySettings settings) {
final speedLabel = settings.selectedBreakSeries != null
? '${settings.selectedBreakSeries!.trainSeries.name}${settings.selectedBreakSeries!.breakSeries}'
: '${journey.metadata.breakSeries?.trainSeries.name}${journey.metadata.breakSeries?.breakSeries}';
: '${journey.metadata.breakSeries?.trainSeries.name ?? '?'}${journey.metadata.breakSeries?.breakSeries ?? '?'}';

return [
DASTableColumn(child: Text(context.l10n.p_train_journey_table_kilometre_label), width: 64.0),
Expand All @@ -120,7 +122,11 @@ class TrainJourney extends StatelessWidget {
),
),
// TODO: find out what to do when break series is not defined
DASTableColumn(child: Text(speedLabel.isNotEmpty ? speedLabel : '??'), width: 62.0, onTap: () => _onBreakSeriesTap(context, journey, settings)),
DASTableColumn(
child: Text(speedLabel),
width: 62.0,
onTap: () => _onBreakSeriesTap(context, journey, settings),
headerKey: breakingSeriesHeaderKey),
DASTableColumn(child: Text(context.l10n.p_train_journey_table_advised_speed_label), width: 62.0),
DASTableColumn(width: 40.0), // actions
];
Expand Down
1 change: 1 addition & 0 deletions das_client/lib/app/widgets/table/das_table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class DASTable extends StatelessWidget {
expanded: column.expanded,
width: column.width,
child: Container(
key: column.headerKey,
decoration: BoxDecoration(
border: tableThemeData?.headingRowBorder ?? column.border,
color: column.color ?? tableThemeData?.headingRowColor,
Expand Down
4 changes: 4 additions & 0 deletions das_client/lib/app/widgets/table/das_table_column.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class DASTableColumn {
this.hidden = false,
this.alignment = Alignment.center,
this.onTap,
this.headerKey,
}) : assert((width != null && width > 0) || expanded);

/// The content of the column header as a widget.
Expand Down Expand Up @@ -46,5 +47,8 @@ class DASTableColumn {
/// Callback for tap events on the column header.
final GestureTapCallback? onTap;

/// Key for the header cell
final Key? headerKey;

get isVisible => !hidden;
}
1 change: 0 additions & 1 deletion das_client/lib/model/journey/metadata.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'package:das_client/model/journey/base_data.dart';
import 'package:das_client/model/journey/break_series.dart';
import 'package:das_client/model/journey/service_point.dart';
import 'package:das_client/model/journey/track_equipment.dart';
import 'package:das_client/model/journey/train_series.dart';

class Metadata {
Metadata({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:das_client/sfera/src/model/segment_profile.dart';
import 'package:das_client/sfera/src/model/train_characteristics.dart';
import 'package:das_client/sfera/src/sfera_reply_parser.dart';
import 'package:isar/isar.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ class RequestJourneyProfileTask extends SferaTask<JourneyProfile> {
}

Fimber.i(
'Received G2bReplyPayload response with ${replyMessage.payload!.journeyProfiles.length} JourneyProfiles and ${replyMessage.payload!.segmentProfiles.length} SegmentProfiles...',
'Received G2bReplyPayload response with ${replyMessage.payload!.journeyProfiles.length} JourneyProfiles, '
'${replyMessage.payload!.segmentProfiles.length} SegmentProfiles and '
'${replyMessage.payload!.trainCharacteristics.length} TrainCharacteristics...',
);

for (final element in replyMessage.payload!.segmentProfiles) {
Expand Down
11 changes: 5 additions & 6 deletions das_client/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -899,12 +899,11 @@ packages:
sbb_design_system_mobile:
dependency: "direct main"
description:
path: "."
ref: HEAD
resolved-ref: c051e3019f7ffb78d6628f1914a92946b810878d
url: "https://github.com/SchweizerischeBundesbahnen/design_system_flutter.git"
source: git
version: "2.0.0"
name: sbb_design_system_mobile
sha256: "9231baa5e51b5bda186e3bdfe2949ea932141557793ffb7aeb2062a9d88b790e"
url: "https://pub.dev"
source: hosted
version: "2.1.1"
sbb_oidc:
dependency: "direct main"
description:
Expand Down
6 changes: 2 additions & 4 deletions das_client/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ dependencies:
path: sbb_oidc
ref: 3.4.0

sbb_design_system_mobile:
git:
url: https://github.com/SchweizerischeBundesbahnen/design_system_flutter.git

# https://pub.dev/packages/sbb_design_system_mobile
sbb_design_system_mobile: ^2.1.1
# https://pub.dev/packages/collection
collection: ^1.18.0
# https://pub.dev/packages/meta
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<TP_ID_Reference TP_ID="Bahnhof_A"/>
</TimingPointReference>
</TimingPointConstraints>
<TrainCharacteristicsRef TC_ID="9999_1" TC_VersionMajor="1" TC_VersionMinor="0" location="0">
<TC_RU_ID>1085</TC_RU_ID>
</TrainCharacteristicsRef>
</SegmentProfileList>
<SegmentProfileList SP_ID="9999_2" SP_VersionMajor="1" SP_VersionMinor="0" SP_Direction="Nominal">
<SP_Zone>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0"?>
<TrainCharacteristics xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../SFERA_3.0_custom.xsd"
TC_ID="9999_1" TC_VersionMajor="1" TC_VersionMinor="0">
<TC_RU_ID>1085</TC_RU_ID>
<TC_Features trainCategoryCode="R" brakedWeightPercentage="150">
</TC_Features>
</TrainCharacteristics>

0 comments on commit 7f00c15

Please sign in to comment.