From 7f00c15470a4ed925143baf754bec9025fbbbf37 Mon Sep 17 00:00:00 2001 From: u221711 Date: Tue, 17 Dec 2024 10:53:01 +0100 Subject: [PATCH] add tests --- .../test/train_journey_table_test.dart | 150 +++++++++++++++++- .../train_journey/widgets/train_journey.dart | 10 +- .../lib/app/widgets/table/das_table.dart | 1 + .../app/widgets/table/das_table_column.dart | 4 + das_client/lib/model/journey/metadata.dart | 1 - .../src/db/train_characteristics_entity.dart | 1 - .../task/request_journey_profile_task.dart | 4 +- das_client/pubspec.lock | 11 +- das_client/pubspec.yaml | 6 +- .../9999_Mixed_journey/SFERA_JP_9999.xml | 3 + .../9999_Mixed_journey/SFERA_TC_9999_1.xml | 8 + 11 files changed, 176 insertions(+), 23 deletions(-) create mode 100644 sfera-mock/src/main/resources/static_sfera_resources/9999_Mixed_journey/SFERA_TC_9999_1.xml diff --git a/das_client/integration_test/test/train_journey_table_test.dart b/das_client/integration_test/test/train_journey_table_test.dart index 39db74e7..cc574f20 100644 --- a/das_client/integration_test/test/train_journey_table_test.dart +++ b/das_client/integration_test/test/train_journey_table_test.dart @@ -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 { @@ -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 @@ -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'); @@ -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); }); }); @@ -498,3 +620,15 @@ Future _loadTrainJourney(WidgetTester tester, {required String trainNumber // wait for train journey to load await tester.pumpAndSettle(); } + +Future _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)); +} diff --git a/das_client/lib/app/pages/journey/train_journey/widgets/train_journey.dart b/das_client/lib/app/pages/journey/train_journey/widgets/train_journey.dart index 2610e847..c7c4ee5d 100644 --- a/das_client/lib/app/pages/journey/train_journey/widgets/train_journey.dart +++ b/das_client/lib/app/pages/journey/train_journey/widgets/train_journey.dart @@ -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; @@ -97,7 +99,7 @@ class TrainJourney extends StatelessWidget { List _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), @@ -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 ]; diff --git a/das_client/lib/app/widgets/table/das_table.dart b/das_client/lib/app/widgets/table/das_table.dart index ae5b11cb..0388bfd2 100644 --- a/das_client/lib/app/widgets/table/das_table.dart +++ b/das_client/lib/app/widgets/table/das_table.dart @@ -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, diff --git a/das_client/lib/app/widgets/table/das_table_column.dart b/das_client/lib/app/widgets/table/das_table_column.dart index b4bd4f21..729acdf9 100644 --- a/das_client/lib/app/widgets/table/das_table_column.dart +++ b/das_client/lib/app/widgets/table/das_table_column.dart @@ -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. @@ -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; } diff --git a/das_client/lib/model/journey/metadata.dart b/das_client/lib/model/journey/metadata.dart index 75d2562e..a4be5262 100644 --- a/das_client/lib/model/journey/metadata.dart +++ b/das_client/lib/model/journey/metadata.dart @@ -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({ diff --git a/das_client/lib/sfera/src/db/train_characteristics_entity.dart b/das_client/lib/sfera/src/db/train_characteristics_entity.dart index eefced34..dbc99b54 100644 --- a/das_client/lib/sfera/src/db/train_characteristics_entity.dart +++ b/das_client/lib/sfera/src/db/train_characteristics_entity.dart @@ -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'; diff --git a/das_client/lib/sfera/src/service/task/request_journey_profile_task.dart b/das_client/lib/sfera/src/service/task/request_journey_profile_task.dart index a6b0f45e..a955d351 100644 --- a/das_client/lib/sfera/src/service/task/request_journey_profile_task.dart +++ b/das_client/lib/sfera/src/service/task/request_journey_profile_task.dart @@ -61,7 +61,9 @@ class RequestJourneyProfileTask extends SferaTask { } 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) { diff --git a/das_client/pubspec.lock b/das_client/pubspec.lock index ba35a59c..7f8c4506 100644 --- a/das_client/pubspec.lock +++ b/das_client/pubspec.lock @@ -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: diff --git a/das_client/pubspec.yaml b/das_client/pubspec.yaml index 4fde64b5..532aaea3 100644 --- a/das_client/pubspec.yaml +++ b/das_client/pubspec.yaml @@ -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 diff --git a/sfera-mock/src/main/resources/static_sfera_resources/9999_Mixed_journey/SFERA_JP_9999.xml b/sfera-mock/src/main/resources/static_sfera_resources/9999_Mixed_journey/SFERA_JP_9999.xml index 36902805..69ddc7b3 100644 --- a/sfera-mock/src/main/resources/static_sfera_resources/9999_Mixed_journey/SFERA_JP_9999.xml +++ b/sfera-mock/src/main/resources/static_sfera_resources/9999_Mixed_journey/SFERA_JP_9999.xml @@ -18,6 +18,9 @@ + + 1085 + diff --git a/sfera-mock/src/main/resources/static_sfera_resources/9999_Mixed_journey/SFERA_TC_9999_1.xml b/sfera-mock/src/main/resources/static_sfera_resources/9999_Mixed_journey/SFERA_TC_9999_1.xml new file mode 100644 index 00000000..3c4e44b9 --- /dev/null +++ b/sfera-mock/src/main/resources/static_sfera_resources/9999_Mixed_journey/SFERA_TC_9999_1.xml @@ -0,0 +1,8 @@ + + + 1085 + + +