-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #235 from ProximaEPFL/test-time-dists
Test human readable time and distances values in UI
- Loading branch information
Showing
7 changed files
with
274 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import "package:proxima/services/human_time_service.dart"; | ||
|
||
import "../providers/provider_human_time_service.dart"; | ||
|
||
final humanTimeServiceOverride = [ | ||
humanTimeServiceProvider.overrideWith( | ||
(ref) => ref.watch(constantHumanTimeServiceProvider), | ||
), | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import "package:hooks_riverpod/hooks_riverpod.dart"; | ||
import "package:proxima/services/human_time_service.dart"; | ||
|
||
final constantTestingTime = DateTime.utc(2000); | ||
|
||
CurrentDateTimeCallback constantTimeCallback() { | ||
return () => constantTestingTime; | ||
} | ||
|
||
final constantDateTimeCallbackProvider = | ||
Provider<CurrentDateTimeCallback>((ref) { | ||
return constantTimeCallback(); | ||
}); | ||
|
||
final constantHumanTimeServiceProvider = Provider<HumanTimeService>((ref) { | ||
final currentDateTimeCallback = ref.watch(constantDateTimeCallbackProvider); | ||
|
||
return HumanTimeService( | ||
currentDateTimeCallback: currentDateTimeCallback, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import "package:flutter_test/flutter_test.dart"; | ||
import "package:proxima/services/human_time_service.dart"; | ||
|
||
import "../mocks/providers/provider_human_time_service.dart"; | ||
|
||
void main() { | ||
group("Human Time Service Unit tests", () { | ||
late HumanTimeService humanTimeService; | ||
|
||
setUp(() { | ||
// Setup the `HumanTimeService` for constant time | ||
humanTimeService = HumanTimeService( | ||
currentDateTimeCallback: constantTimeCallback(), | ||
); | ||
}); | ||
|
||
test("Check correct simple absolute time", () { | ||
// Setup actual values for simple date | ||
final time1 = DateTime.utc(2002); | ||
|
||
const expectedSimpleHumanText = "Tuesday, January 1, 2002 00:00"; | ||
|
||
// Use the service to get human time | ||
final actualSimpleHumanText = humanTimeService.textTimeAbsolute( | ||
time1, | ||
); | ||
|
||
// Check that the absolute time value is correct | ||
expect( | ||
actualSimpleHumanText, | ||
expectedSimpleHumanText, | ||
); | ||
}); | ||
|
||
test("Check correct complex absolute time", () { | ||
// Setup actual values for complex specific date | ||
final time2 = DateTime.utc( | ||
2023, | ||
11, | ||
21, | ||
1, | ||
); | ||
|
||
const expectedComplexHumanText = "Tuesday, November 21, 2023 01:00"; | ||
|
||
// Use the service to get human time | ||
final actualComplexHumanText = humanTimeService.textTimeAbsolute( | ||
time2, | ||
); | ||
|
||
// Check that the specific absolute time value is correct | ||
expect( | ||
actualComplexHumanText, | ||
expectedComplexHumanText, | ||
); | ||
}); | ||
|
||
test("Check special case 'now' relative time", () { | ||
// Setup actual relative values for 'now' case | ||
final closeToNowTime = constantTestingTime.subtract( | ||
const Duration(seconds: 1), | ||
); | ||
|
||
const expectedNowRelativeTime = "now"; | ||
|
||
// Use the service to get relative human time | ||
final actualNowTimeHumanText = humanTimeService.textTimeSince( | ||
closeToNowTime, | ||
); | ||
|
||
// Check that the time value is correctly 'now' | ||
expect( | ||
actualNowTimeHumanText, | ||
expectedNowRelativeTime, | ||
); | ||
}); | ||
|
||
test("Check 10 minutes relative time", () { | ||
// Setup specific time values for 10 min before constant time | ||
final relative10Minutes = constantTestingTime.subtract( | ||
const Duration(minutes: 10), | ||
); | ||
|
||
const expectedRelative10Minutes = "10m ago"; | ||
|
||
// Use the service to get relative human time | ||
final actualMinuteTimeHumanText = humanTimeService.textTimeSince( | ||
relative10Minutes, | ||
); | ||
|
||
// Check that the time value is correct for 10 minutes | ||
expect( | ||
actualMinuteTimeHumanText, | ||
expectedRelative10Minutes, | ||
); | ||
}); | ||
|
||
test("Check 4 days relative time", () { | ||
// Setup specific time values for 4 days before constant time | ||
final relative4Days = constantTestingTime.subtract( | ||
const Duration(days: 4), | ||
); | ||
|
||
const expectedRelative4Days = "4d ago"; | ||
|
||
// Use the service to get relative human time | ||
final actualDaysTimeHumanText = humanTimeService.textTimeSince( | ||
relative4Days, | ||
); | ||
|
||
// Check that the time value is correct for 4 days | ||
expect( | ||
actualDaysTimeHumanText, | ||
expectedRelative4Days, | ||
); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import "package:firebase_core/firebase_core.dart"; | ||
import "package:flutter/material.dart"; | ||
import "package:flutter_test/flutter_test.dart"; | ||
import "package:proxima/views/pages/post/post_page_widget/complete_post_widget.dart"; | ||
|
||
import "../../../mocks/data/post_overview.dart"; | ||
import "../../../mocks/providers/provider_post_page.dart"; | ||
import "../../../mocks/services/setup_firebase_mocks.dart"; | ||
|
||
void main() { | ||
setUp(() async { | ||
setupFirebaseAuthMocks(); | ||
await Firebase.initializeApp(); | ||
}); | ||
|
||
group("Post Distances and Timing values", () { | ||
testWidgets("Check correct distance on basic post", (tester) async { | ||
await tester.pumpWidget(emptyPostPageProvider); | ||
await tester.pumpAndSettle(); | ||
|
||
final post = testPosts.first; | ||
final expectedDistanceText = "${post.distance}m away"; | ||
|
||
// Find post distance value with expected human readable distance | ||
final distanceDisplay = find.text(expectedDistanceText); | ||
|
||
// Check that the distance is displayed with correct value | ||
expect(distanceDisplay, findsOneWidget); | ||
}); | ||
|
||
testWidgets("Check correct distance on custom post", (tester) async { | ||
await tester.pumpWidget(customPostOverviewPage(timeDistancePost)); | ||
await tester.pumpAndSettle(); | ||
|
||
final expectedDistanceText = "${timeDistancePost.distance}m away"; | ||
|
||
// Find the container for the distance | ||
final appBar = find.byType(AppBar); | ||
// Check that the container is correctly displayed | ||
expect(appBar, findsOneWidget); | ||
|
||
// Find the child widget of the appBar (containing the distance) | ||
final actualDistanceDisplayed = find.descendant( | ||
of: appBar, | ||
matching: find.text(expectedDistanceText), | ||
); | ||
|
||
// Check that the distance is correctly displayed and with the right value | ||
expect(actualDistanceDisplayed, findsOneWidget); | ||
}); | ||
|
||
testWidgets("Check correct timing on basic post, special 'now' case", | ||
(tester) async { | ||
await tester.pumpWidget(customPostOverviewPage(testPosts.first)); | ||
await tester.pumpAndSettle(); | ||
|
||
const expectedTimeValue = "now"; | ||
|
||
// Find the parent of the timing text | ||
final postUserBar = find.byKey(CompletePostWidget.postUserBarKey); | ||
expect(postUserBar, findsOneWidget); | ||
|
||
// Find if the parent contains a child with the expected timing text | ||
final actualTimeDisplayed = find.descendant( | ||
of: postUserBar, | ||
matching: find.text(expectedTimeValue), | ||
); | ||
|
||
// Check the special case 'now' is correctly handled in UI | ||
expect(actualTimeDisplayed, findsOneWidget); | ||
}); | ||
|
||
testWidgets("Check correct timing on custom post", (tester) async { | ||
await tester.pumpWidget(customPostOverviewPage(timeDistancePost)); | ||
await tester.pumpAndSettle(); | ||
|
||
const expectedTimeValue = "~1y ago"; | ||
|
||
// Find the parent of the timing text | ||
final postUserBar = find.byKey(CompletePostWidget.postUserBarKey); | ||
expect(postUserBar, findsOneWidget); | ||
|
||
// Find if the parent contains a child with the expected timing text | ||
final actualTimeDisplayed = find.descendant( | ||
of: postUserBar, | ||
matching: find.text(expectedTimeValue), | ||
); | ||
|
||
// Check the timing value is correct | ||
expect(actualTimeDisplayed, findsOneWidget); | ||
}); | ||
}); | ||
} |