Skip to content

Commit

Permalink
TW-1503 Add some more test case for Sunday
Browse files Browse the repository at this point in the history
  • Loading branch information
hieutbui authored and hoangdat committed Mar 1, 2024
1 parent 1c1fe4e commit 6ac4dde
Showing 1 changed file with 166 additions and 0 deletions.
166 changes: 166 additions & 0 deletions test/utils/date_time_extension_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,172 @@ void main() {
expect(textWidget.data, equals(expectedDisplayText));
});

testWidgets(
'GIVEN the current time is Sunday\n'
'AND the date time to display is Friday of current week\n'
'THEN should display Friday\n', (WidgetTester tester) async {
const expectedDisplayText = 'Friday';
final currentTime = DateTime(2024, 3, 3);
final timeToTest = DateTime(2024, 3, 1, 12, 5);

final textWidgetBuilder = Builder(
builder: (BuildContext context) {
final displayText = timeToTest.localizedTimeShort(
context,
currentTime: currentTime,
);

return Text(
displayText,
key: textWidgetKey,
);
},
);

await tester.binding.setLocale('en', 'US');
await tester.pumpWidget(
MaterialApp(
localizationsDelegates: const [L10n.delegate],
home: textWidgetBuilder,
),
);

final textWidgetFinder = find.byKey(textWidgetKey);

expect(textWidgetFinder, findsOneWidget);

final Text textWidget = tester.widget(textWidgetFinder) as Text;

expect(textWidget.data, isNotNull);

expect(textWidget.data, equals(expectedDisplayText));
});

testWidgets(
'GIVEN the current time is Sunday\n'
'AND the date time to display is Saturday of current week\n'
'THEN should display Saturday\n', (WidgetTester tester) async {
const expectedDisplayText = 'Saturday';
final currentTime = DateTime(2024, 3, 3);
final timeToTest = DateTime(2024, 3, 2, 12, 5);

final textWidgetBuilder = Builder(
builder: (BuildContext context) {
final displayText = timeToTest.localizedTimeShort(
context,
currentTime: currentTime,
);

return Text(
displayText,
key: textWidgetKey,
);
},
);

await tester.binding.setLocale('en', 'US');
await tester.pumpWidget(
MaterialApp(
localizationsDelegates: const [L10n.delegate],
home: textWidgetBuilder,
),
);

final textWidgetFinder = find.byKey(textWidgetKey);

expect(textWidgetFinder, findsOneWidget);

final Text textWidget = tester.widget(textWidgetFinder) as Text;

expect(textWidget.data, isNotNull);

expect(textWidget.data, equals(expectedDisplayText));
});

testWidgets(
'GIVEN current time is Sunday\n'
'AND the date time to display is Monday of the next week\n'
'THEN should display the date in the format MMM d\n',
(WidgetTester tester) async {
const expectedDisplayText = 'Mar 4';
final currentTime = DateTime(2024, 3, 3);
final timeToTest = DateTime(2024, 3, 4, 12, 5);

final textWidgetBuilder = Builder(
builder: (BuildContext context) {
final displayText = timeToTest.localizedTimeShort(
context,
currentTime: currentTime,
);

return Text(
displayText,
key: textWidgetKey,
);
},
);

await tester.binding.setLocale('en', 'US');
await tester.pumpWidget(
MaterialApp(
localizationsDelegates: const [L10n.delegate],
home: textWidgetBuilder,
),
);

final textWidgetFinder = find.byKey(textWidgetKey);

expect(textWidgetFinder, findsOneWidget);

final Text textWidget = tester.widget(textWidgetFinder) as Text;

expect(textWidget.data, isNotNull);

expect(textWidget.data, equals(expectedDisplayText));
});

testWidgets(
'GIVEN current time is Sunday\n'
'AND the date time to display is Tuesday of the next week\n'
'THEN should display the date in the format MMM d\n',
(WidgetTester tester) async {
const expectedDisplayText = 'Mar 5';
final currentTime = DateTime(2024, 3, 3);
final timeToTest = DateTime(2024, 3, 5, 12, 5);

final textWidgetBuilder = Builder(
builder: (BuildContext context) {
final displayText = timeToTest.localizedTimeShort(
context,
currentTime: currentTime,
);

return Text(
displayText,
key: textWidgetKey,
);
},
);

await tester.binding.setLocale('en', 'US');
await tester.pumpWidget(
MaterialApp(
localizationsDelegates: const [L10n.delegate],
home: textWidgetBuilder,
),
);

final textWidgetFinder = find.byKey(textWidgetKey);

expect(textWidgetFinder, findsOneWidget);

final Text textWidget = tester.widget(textWidgetFinder) as Text;

expect(textWidget.data, isNotNull);

expect(textWidget.data, equals(expectedDisplayText));
});

testWidgets(
'GIVEN the date time to display is not in the same week\n'
'AND in the same year\n'
Expand Down

0 comments on commit 6ac4dde

Please sign in to comment.