Skip to content

Commit

Permalink
fix: fixed the padding in the punctuality display (#122) (#501)
Browse files Browse the repository at this point in the history
Co-authored-by: u221638 <[email protected]>
Co-authored-by: u221711 <[email protected]>
  • Loading branch information
3 people authored Jan 17, 2025
1 parent dba2801 commit 17511ff
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 66 deletions.
109 changes: 51 additions & 58 deletions das_client/integration_test/test/train_journey_table_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,57 @@ import '../util/test_utils.dart';

void main() {
group('train journey table test', () {
testWidgets('check if update sent is correct', (tester) async {
// Load app widget.
await prepareAndStartApp(tester);

// Select the correct train number
final trainNumberText = findTextFieldByLabel(l10n.p_train_selection_trainnumber_description);
expect(trainNumberText, findsOneWidget);

await enterText(tester, trainNumberText, 'T9999');

// Log into the journey
final primaryButton = find.byWidgetPredicate((widget) => widget is SBBPrimaryButton).first;
await tester.tap(primaryButton);

// Wait for train journey to load
await tester.pumpAndSettle();

// Find the header and check if it is existent
final headerFinder = find.byType(Header);
expect(headerFinder, findsOneWidget);

// Timer logic: increase timer every second, rerun the base every 100 ms and check if the UI changed
int counter = 0;

final completer = Completer<void>();

expect(find.descendant(of: headerFinder, matching: find.text('+00:00')), findsOneWidget);

while (!completer.isCompleted) {
await tester.pumpAndSettle();

if (!find.descendant(of: headerFinder, matching: find.text('+00:00')).evaluate().isNotEmpty) {
expect(find.descendant(of: headerFinder, matching: find.text('+00:30')), findsOneWidget);
completer.complete();
break;
}

// cancel after 10 seconds
if (counter++ > 10 * 10) {
completer
.completeError(Exception('UI did not change from the base value to the updated value (+00:00 -> +00:30)'));
break;
}

await Future.delayed(const Duration(milliseconds: 100));
}

await completer.future;

await tester.pumpAndSettle();
});

testWidgets('test balise multiple level crossings', (tester) async {
await prepareAndStartApp(tester);
Expand Down Expand Up @@ -895,64 +946,6 @@ void main() {

await tester.pumpAndSettle();
});

testWidgets('check if update sent is correct', (tester) async {
// Load app widget.
await prepareAndStartApp(tester);

// Select the correct train number
final trainNumberText = findTextFieldByLabel(l10n.p_train_selection_trainnumber_description);
expect(trainNumberText, findsOneWidget);

await enterText(tester, trainNumberText, 'T9999');

// Log into the journey
final primaryButton = find.byWidgetPredicate((widget) => widget is SBBPrimaryButton).first;
await tester.tap(primaryButton);

// Wait for train journey to load
await tester.pumpAndSettle();

// Find the header and check if it is existent
final headerFinder = find.byType(Header);
expect(headerFinder, findsOneWidget);

// Timer logic: increase timer every second, rerun the base every 100 ms and check if the UI changed
int timer = 0;
const maxTime = 10;
int millisecondsCounter = 0;

final completer = Completer<void>();

expect(find.descendant(of: headerFinder, matching: find.text('+00:00')), findsOneWidget);

while (!completer.isCompleted) {
await tester.pumpAndSettle();

if (!find.descendant(of: headerFinder, matching: find.text('+00:00')).evaluate().isNotEmpty) {
expect(find.descendant(of: headerFinder, matching: find.text('+00:30')), findsOneWidget);
completer.complete();
break;
}

millisecondsCounter += 100;
if (millisecondsCounter % 1000 == 0) {
timer++;
}

if (timer > maxTime) {
completer
.completeError(Exception('UI did not change from the base value to the updated value (+00:00 -> +00:30)'));
break;
}

await Future.delayed(const Duration(milliseconds: 100));
}

await completer.future;

await tester.pumpAndSettle();
});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TimeContainer extends StatelessWidget {
height: 112.0,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Flexible(child: _currentTime()),
_divider(),
Expand All @@ -50,7 +50,11 @@ Widget _punctualityDisplay(BuildContext context) {
stream: bloc.journeyStream,
builder: (context, snapshot) {
if (!snapshot.hasData || snapshot.data == null || snapshot.data!.metadata.delay == null) {
return Text('+00:00', style: DASTextStyles.xLargeLight);
return Padding(
padding:
const EdgeInsets.fromLTRB(sbbDefaultSpacing * 0.5, 0.0, sbbDefaultSpacing * 0.5, sbbDefaultSpacing * 0.5),
child: Text('+00:00', style: DASTextStyles.xLargeLight),
);
}

final Journey journey = snapshot.data!;
Expand All @@ -60,9 +64,10 @@ Widget _punctualityDisplay(BuildContext context) {
final String seconds = NumberFormat('00').format(delay.inSeconds.abs() % 60);
final String formattedDuration = '${delay.isNegative ? '-' : '+'}$minutes:$seconds';

return Text(
formattedDuration,
style: DASTextStyles.xLargeLight,
return Padding(
padding:
const EdgeInsets.fromLTRB(sbbDefaultSpacing * 0.5, 0.0, sbbDefaultSpacing * 0.5, sbbDefaultSpacing * 0.5),
child: Text(formattedDuration, style: DASTextStyles.xLargeLight),
);
},
);
Expand All @@ -72,9 +77,13 @@ StreamBuilder _currentTime() {
return StreamBuilder(
stream: Stream.periodic(const Duration(milliseconds: 200)),
builder: (context, snapshot) {
return Text(
DateFormat('HH:mm:ss').format(DateTime.now().toLocal()),
style: DASTextStyles.xLargeBold,
return Padding(
padding:
const EdgeInsets.fromLTRB(sbbDefaultSpacing * 0.5, sbbDefaultSpacing * 0.5, sbbDefaultSpacing * 0.5, 0),
child: Text(
DateFormat('HH:mm:ss').format(DateTime.now().toLocal()),
style: DASTextStyles.xLargeBold,
),
);
},
);
Expand Down

0 comments on commit 17511ff

Please sign in to comment.