Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace DateTime.now() with clock.now(). #1314

Merged
merged 2 commits into from
Feb 27, 2024

Conversation

Jonas-Sander
Copy link
Collaborator

@Jonas-Sander Jonas-Sander commented Feb 26, 2024

Using clock is better because one can return customizable results from clock.now() by using withClock in tests.

Summary by CodeRabbit

  • New Features

    • Introduced the use of a custom clock (clock package) across the application for consistent time handling, enhancing testability and time-related operations.
  • Refactor

    • Updated various components (dashboard, comments, homework, feedback, file sharing, and more) to utilize the clock package for time calculations instead of directly using DateTime.now().
    • Streamlined time-related operations in tests and logic classes by adopting the clock package, ensuring more reliable and consistent time management throughout the application.

Using `clock` is better because one can return customizable results from `clock.now()` by using `withClock` in tests.
@github-actions github-actions bot added feature: homework feature: homework-submissions Submissions can be toggled for homeworks so that pupils can upload their solutions for the teacher. feature: file-sharing Files can be shared inside Sharezone e.g. by uploading them in a file-sharing folder of a course. feature: timetable / calendar Includes anything regarding lessons (timetable) and events (calendar). feature: information sheet Information sheets are posted to courses as a way to announce information. ui / ux feature: universal file features File features (downloading, preview, etc.) that are used by multiple Sharezone features. feature: holidays feature: groups Groups umbrella term for courses and classes. testing feature: report Users can report content inside Sharezone (e.g. if an info sheet contains hate speech). sharezone cli user: parent feature: comments Comment on contents (homeworks, info sheets) to e.g. ask for clarifications on a task. dependencies Changing, updating, adding or removing one or more dependencies. feature: feedback Users can send us feedback to improve the app. w: dashboard-page Page that shows a summary of all important things (homeworks, events, etc.). labels Feb 26, 2024
Copy link
Contributor

coderabbitai bot commented Feb 26, 2024

Important

Auto Review Skipped

Review was skipped due to path filters

Files ignored due to path filters (2)
  • lib/abgabe/abgabe_client_lib/pubspec.lock is excluded by: !**/*.lock
  • lib/filesharing/filesharing_logic/pubspec.lock is excluded by: !**/*.lock

Walkthrough

The overarching change across various files involves the adoption of the clock package to replace direct calls to DateTime.now() with clock.now(). This adjustment aims to enhance testability and consistency in handling time-related operations throughout the application, allowing for easier manipulation of time in tests and potentially accommodating different time zones or custom time flows.

Changes

File Path Change Summary
Various files across app/lib/, lib/, and tools/sz_repo_cli/lib/src/common/ Introduced the clock package and replaced DateTime.now() with clock.now() for time-related operations.
app/test/..., lib/abgabe/abgabe_client_lib/test/, lib/firebase_hausaufgabenheft_logik/test/, lib/hausaufgabenheft_logik/test/ Added clock package import and replaced DateTime.now() with clock.now() to improve test consistency and reliability.

🐰

In the land of code, where the clock ticks slow,
A rabbit hopped in, with a change in tow.
"No more DateTime.now(), we'll use clock.now() instead,"
For tests that won't break, and time that's well-tread.
So cheer, dear friends, for the future is bright,
With time on our side, everything's just right.
🕰️🐇

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

github-actions bot commented Feb 26, 2024

Visit the preview URL for this PR (updated for commit 3f1d7a5):

https://sharezone-website-dev--pr1314-replace-datetime-now-78j265se.web.app

(expires Thu, 29 Feb 2024 15:05:05 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 372b0431a96247f908d9a97d5d865de1c8b3b04e

Copy link

github-actions bot commented Feb 26, 2024

Visit the preview URL for this PR (updated for commit 3f1d7a5):

https://sharezone-test--pr1314-replace-datetime-now-jpl8ihr2.web.app

(expires Thu, 29 Feb 2024 15:05:36 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 4cb3ae61e1e018abfd9841fd3239f5b49ccc034b

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 4

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e5a5eb0 and 232e84c.
Files ignored due to path filters (22)
  • lib/abgabe/abgabe_client_lib/pubspec.lock is excluded by: !**/*.lock
  • lib/abgabe/abgabe_client_lib/pubspec.yaml is excluded by: !**/*.yaml
  • lib/authentification/authentification_qrcode/pubspec.lock is excluded by: !**/*.lock
  • lib/authentification/authentification_qrcode/pubspec.yaml is excluded by: !**/*.yaml
  • lib/cloud_firestore_helper/pubspec.lock is excluded by: !**/*.lock
  • lib/cloud_firestore_helper/pubspec.yaml is excluded by: !**/*.yaml
  • lib/date/pubspec.lock is excluded by: !**/*.lock
  • lib/date/pubspec.yaml is excluded by: !**/*.yaml
  • lib/filesharing/filesharing_logic/pubspec.lock is excluded by: !**/*.lock
  • lib/filesharing/filesharing_logic/pubspec.yaml is excluded by: !**/*.yaml
  • lib/firebase_hausaufgabenheft_logik/pubspec.lock is excluded by: !**/*.lock
  • lib/firebase_hausaufgabenheft_logik/pubspec.yaml is excluded by: !**/*.yaml
  • lib/group_domain_models/pubspec.lock is excluded by: !**/*.lock
  • lib/group_domain_models/pubspec.yaml is excluded by: !**/*.yaml
  • lib/hausaufgabenheft_logik/pubspec.lock is excluded by: !**/*.lock
  • lib/hausaufgabenheft_logik/pubspec.yaml is excluded by: !**/*.yaml
  • lib/holidays/pubspec.lock is excluded by: !**/*.lock
  • lib/holidays/pubspec.yaml is excluded by: !**/*.yaml
  • lib/sharezone_widgets/pubspec.lock is excluded by: !**/*.lock
  • lib/sharezone_widgets/pubspec.yaml is excluded by: !**/*.yaml
  • tools/sz_repo_cli/pubspec.lock is excluded by: !**/*.lock
  • tools/sz_repo_cli/pubspec.yaml is excluded by: !**/*.yaml
Files selected for processing (46)
  • app/lib/blackboard/blackboard_item.dart (2 hunks)
  • app/lib/changelog/change_database_model.dart (2 hunks)
  • app/lib/comments/comment.dart (2 hunks)
  • app/lib/comments/comment_data_models.dart (2 hunks)
  • app/lib/dashboard/bloc/dashboard_bloc.dart (4 hunks)
  • app/lib/dashboard/dashboard_page.dart (1 hunks)
  • app/lib/dashboard/models/homework_view.dart (3 hunks)
  • app/lib/dashboard/sections/holiday_countdown_section.dart (2 hunks)
  • app/lib/dashboard/update_reminder/update_reminder_bloc.dart (2 hunks)
  • app/lib/feedback/src/cache/feedback_cache.dart (2 hunks)
  • app/lib/filesharing/logic/firebase_file_uploader/implementation/firebase_file_uploader_impl.dart (2 hunks)
  • app/lib/holidays/holiday_bloc.dart (2 hunks)
  • app/lib/homework/parent/homework_page.dart (3 hunks)
  • app/lib/homework/parent/src/homework_page_bloc.dart (2 hunks)
  • app/lib/homework/shared/homework_archived.dart (2 hunks)
  • app/lib/homework/shared/homework_card.dart (2 hunks)
  • app/lib/main/sharezone_bloc_providers.dart (5 hunks)
  • app/lib/report/report_factory.dart (2 hunks)
  • app/lib/settings/src/subpages/timetable/timetable_settings_page.dart (3 hunks)
  • app/lib/submissions/homework_list_submissions_page.dart (2 hunks)
  • app/lib/timetable/src/edit_date.dart (2 hunks)
  • app/lib/util/api/homework_api.dart (2 hunks)
  • app/test/feedback/feedback_cache_test.dart (3 hunks)
  • app/test/holidays/holiday_bloc_unit_test.dart (2 hunks)
  • app/test/holidays/holiday_cache_test.dart (3 hunks)
  • app/test/holidays/integration_test.dart (1 hunks)
  • app/test/timetable/timetable_bloc_test.dart (2 hunks)
  • app/test_goldens/dashboard/dashboard_page_test.dart (2 hunks)
  • lib/abgabe/abgabe_client_lib/lib/src/erstellung/bloc/homework_user_create_submissions_bloc_factory.dart (2 hunks)
  • lib/abgabe/abgabe_client_lib/lib/src/erstellung/cloud_storage_abgabedatei_uploader.dart (2 hunks)
  • lib/abgabe/abgabe_client_lib/test/bloc_test.dart (4 hunks)
  • lib/authentification/authentification_qrcode/lib/src/logic/qr_code_user_authenticator.dart (2 hunks)
  • lib/cloud_firestore_helper/lib/src/cloud_firestore_helper.dart (2 hunks)
  • lib/date/lib/src/date.dart (2 hunks)
  • lib/filesharing/filesharing_logic/lib/src/models/cloud_file.dart (2 hunks)
  • lib/firebase_hausaufgabenheft_logik/lib/src/homework_dto.dart (2 hunks)
  • lib/firebase_hausaufgabenheft_logik/test/lazy_loading_controller_test.dart (2 hunks)
  • lib/group_domain_models/lib/src/models/member.dart (2 hunks)
  • lib/hausaufgabenheft_logik/lib/src/models/date.dart (2 hunks)
  • lib/hausaufgabenheft_logik/lib/src/setup/create_homework_page_bloc.dart (2 hunks)
  • lib/hausaufgabenheft_logik/test/date/date_test.dart (2 hunks)
  • lib/hausaufgabenheft_logik/test/homework_page_bloc_test.dart (3 hunks)
  • lib/holidays/lib/src/holiday_cache.dart (2 hunks)
  • lib/sharezone_widgets/lib/src/widgets.dart (2 hunks)
  • tools/sz_repo_cli/lib/src/common/src/concurrent_command.dart (2 hunks)
  • tools/sz_repo_cli/lib/src/common/src/concurrent_package_task_runner.dart (2 hunks)
Additional comments: 100
app/lib/report/report_factory.dart (2)
  • 10-10: The addition of the clock package import is correctly implemented.
  • 30-30: The usage of clock.now() to set the createdOn field in the Report object aligns with the PR's objective to enhance testability by allowing customizable time results during testing.
app/lib/feedback/src/cache/feedback_cache.dart (3)
  • 11-11: The addition of the clock package import is correctly implemented.
  • 41-41: The usage of clock.now() for calculating time differences in the hasFeedbackSubmissionCoolDown method is appropriate and enhances the testability of the FeedbackCache class.
  • 47-47: The usage of clock.now() to set the last submit time in the setLastSubmit method aligns with the PR's objective to improve testability.
lib/hausaufgabenheft_logik/lib/src/models/date.dart (2)
  • 9-9: The addition of the clock package import is correctly implemented.
  • 23-23: The usage of clock.now() in the now factory constructor to create a new Date instance based on the current time is appropriate and enhances the testability of the Date class.
app/test/feedback/feedback_cache_test.dart (2)
  • 9-9: The addition of the clock package import is correctly implemented.
  • 33-33: The usage of clock.now() in test cases for setting up feedback submission cooldown conditions is appropriate and enhances the testability of the feedback caching logic.

Also applies to: 48-48

lib/cloud_firestore_helper/lib/src/cloud_firestore_helper.dart (2)
  • 9-9: The addition of the clock package import is correctly implemented.
  • 47-47: The usage of clock.now() in the dateTimeFromTimestamp function when the timestamp is null is appropriate and enhances the testability of the cloud_firestore_helper library.
lib/group_domain_models/lib/src/models/member.dart (2)
  • 9-9: The addition of the clock package import is correctly implemented.
  • 45-45: The usage of clock.now() for the joinedOn field in the create factory constructor is appropriate and enhances the testability of the MemberData class.
app/lib/changelog/change_database_model.dart (2)
  • 9-9: The addition of the clock package import is correctly implemented.
  • 36-36: The usage of clock.now() for the releaseDate field in the create factory constructor is appropriate and enhances the testability of the ChangeDatabaseModel class.
app/lib/filesharing/logic/firebase_file_uploader/implementation/firebase_file_uploader_impl.dart (2)
  • 9-9: The addition of the clock package import is correctly implemented.
  • 49-49: The usage of clock.now() for the changedOn property in the ChangeActivity constructor is appropriate and enhances the testability of the FirebaseFileUploaderImplementation class.
app/lib/timetable/src/edit_date.dart (2)
  • 9-9: The addition of the clock package import is correctly implemented.
  • 80-80: The usage of clock.now() for the initialDate assignment in the selectDate function is appropriate and enhances the testability of the EditDateField class.
lib/authentification/authentification_qrcode/lib/src/logic/qr_code_user_authenticator.dart (2)
  • 10-10: The addition of the clock package import is correctly implemented.
  • 53-53: The usage of clock.now() for the created field in the generateQrId method is appropriate and enhances the testability of the QrCodeUserAuthenticator class.
app/lib/comments/comment.dart (2)
  • 9-9: The addition of the clock package import is correctly implemented.
  • 71-71: The usage of clock.now() in the writtenOnDateTime getter of the CommentAge class is appropriate and enhances the testability of the Comment class.
lib/holidays/lib/src/holiday_cache.dart (2)
  • 10-10: The addition of the clock package import is correctly implemented.
  • 26-26: The usage of clock.now() for the getCurrentTime initialization logic is appropriate and enhances the testability of the HolidayCache class.
app/test_goldens/dashboard/dashboard_page_test.dart (2)
  • 13-13: The import statement for the clock package is correctly added, ensuring that clock.now() can be used within this test file.
  • 46-46: Replacing DateTime.now() with clock.now() is correctly implemented, enhancing the testability of this section by allowing time manipulation during tests.
lib/abgabe/abgabe_client_lib/lib/src/erstellung/bloc/homework_user_create_submissions_bloc_factory.dart (2)
  • 19-19: The import statement for the clock package is correctly added, enabling the use of clock.now() in the HomeworkUserCreateSubmissionsBlocFactory class.
  • 63-63: Correctly replacing DateTime.now() with clock.now() in the factory method enhances the testability by allowing the manipulation of the current time in tests.
app/test/holidays/holiday_cache_test.dart (3)
  • 10-10: The import statement for the clock package is correctly added, ensuring that clock.now() can be used within this test file.
  • 41-45: Correctly using clock.now() for generating future and past holidays in tests. This change enhances test reliability by allowing control over the current time.
  • 70-71: Correctly using clock.now() to manipulate the current time in tests, improving the test's reliability and control over time-sensitive logic.
lib/hausaufgabenheft_logik/lib/src/setup/create_homework_page_bloc.dart (2)
  • 9-9: The import statement for the clock package is correctly added, enabling the use of clock.now() in the createHomeworkPageBloc function.
  • 58-58: Replacing DateTime.now() with clock.now() is correctly implemented, enhancing the testability of this section by allowing time manipulation during tests.
lib/hausaufgabenheft_logik/test/date/date_test.dart (2)
  • 9-9: The import statement for the clock package is correctly added, ensuring that clock.now() can be used within this test file.
  • 54-54: Correctly replacing DateTime.now() with clock.now() in the Date.now() test function enhances the testability by allowing the manipulation of the current time in tests.
app/lib/dashboard/update_reminder/update_reminder_bloc.dart (2)
  • 10-10: The import statement for the clock package is correctly added, enabling the use of clock.now() in the UpdateReminderBloc class.
  • 45-45: Correctly replacing DateTime.now() with clock.now() in the getCurrentDateTime method enhances the testability by allowing the manipulation of the current time in tests.
app/lib/dashboard/models/homework_view.dart (3)
  • 9-9: The import statement for the clock package is correctly added, ensuring that clock.now() can be used within this model class.
  • 43-43: Correctly using clock.now() for initializing todayDateTimeWithoutTime variable. This change ensures consistency in date calculations based on the clock library.
  • 66-67: Correctly using clock.now() for initializing dayAfterTomorrow variable. This change ensures consistency in date calculations based on the clock library.
app/lib/comments/comment_data_models.dart (2)
  • 9-9: The import statement for the clock package is correctly added, enabling the use of clock.now() in the CommentDataModel class.
  • 77-77: Correctly replacing DateTime.now() with clock.now() to calculate comment age. This change enhances the testability by allowing the manipulation of the current time in tests.
lib/date/lib/src/date.dart (2)
  • 9-9: The import statement for the clock package is correctly added, ensuring that clock.now() can be used within the Date class.
  • 36-36: Correctly replacing DateTime.now() with clock.now() in the Date.today() factory method. This change ensures that the current date is retrieved consistently across the application, enhancing testability.
tools/sz_repo_cli/lib/src/common/src/concurrent_command.dart (2)
  • 12-12: The addition of the clock package import is correctly implemented to facilitate the use of clock.now() for time retrieval, enhancing testability by allowing time manipulation in tests.
  • 95-95: The replacement of DateTime.now() with clock.now() in the ConcurrentPackageTaskRunner initialization is correctly implemented. This change aligns with the PR's objective to enhance testability by allowing customizable time results during testing.
app/lib/blackboard/blackboard_item.dart (2)
  • 9-9: The addition of the clock package import is correctly implemented, enabling the use of clock.now() for time retrieval within the BlackboardItem class.
  • 68-68: Replacing DateTime.now() with clock.now() in the BlackboardItem.create factory constructor is correctly done. This change ensures that the createdOn field can be manipulated in tests, improving the testability of the code.
app/lib/holidays/holiday_bloc.dart (2)
  • 12-12: The addition of the clock package import is correctly implemented, enabling the use of clock.now() for time retrieval within the HolidayBloc class.
  • 38-38: Modifying the getCurrentTime initialization to use clock.now() instead of a direct call to DateTime.now() is correctly done. This change aligns with the PR's objective to enhance testability by allowing customizable time results during testing.
app/lib/homework/parent/src/homework_page_bloc.dart (2)
  • 13-13: The addition of the clock package import is correctly implemented, enabling the use of clock.now() for time retrieval within the HomeworkPageBloc class.
  • 120-121: Changing the way todayDateTime is initialized to use clock.now() instead of DateTime.now() is correctly done. This modification ensures that the date comparison logic can be tested with controlled time values, improving the testability of the code.
app/lib/homework/shared/homework_archived.dart (2)
  • 12-12: The addition of the clock package import is correctly implemented, enabling the use of clock.now() for time retrieval within the HomeworkArchivedPage class.
  • 67-68: Modifying the usage of DateTime to utilize clock.now() for the current date in the HomeworkArchivedPage class is correctly done. This change aligns with the PR's objective to enhance testability by allowing customizable time results during testing.
lib/firebase_hausaufgabenheft_logik/test/lazy_loading_controller_test.dart (2)
  • 11-11: The addition of the clock package import is correctly implemented, enabling the use of clock.now() for time retrieval within the test file.
  • 36-36: Replacing DateTime.now() with clock.now() in the listOfHomeworksWithLength function for the HomeworkReadModel initialization is correctly done. This change ensures that the tests can manipulate the todoDate field, improving the testability of the code.
lib/filesharing/filesharing_logic/lib/src/models/cloud_file.dart (1)
  • 87-87: The change from DateTime.now() to clock.now() for the createdOn field initialization is aligned with the PR's objective to enhance testability. Ensure that the clock package is correctly utilized in tests to mock time effectively.
app/test/holidays/holiday_bloc_unit_test.dart (1)
  • 179-179: The replacement of DateTime.now() with clock.now() in the generateHolidayList method is a good practice for improving testability. Verify that this change behaves as expected in tests, especially in mocking time.
lib/abgabe/abgabe_client_lib/lib/src/erstellung/cloud_storage_abgabedatei_uploader.dart (2)
  • 23-23: The initialization of _lastUploaded with clock.now() is a good practice for improving testability. Ensure that this change integrates well with the rest of the functionality.
  • 60-64: The use of clock.now() for time calculations related to upload throttling is consistent with the PR's objective. Verify that this logic works as intended and does not introduce any unintended delays or issues.
app/lib/dashboard/dashboard_page.dart (1)
  • 13-13: The addition of the clock package import is consistent with the PR's objective to enhance testability. Ensure that future changes in this file make appropriate use of the clock package for time-related operations.
app/lib/submissions/homework_list_submissions_page.dart (3)
  • 140-140: The replacement of DateTime.now() with clock.now() for lastActionDateTime is aligned with the PR's objective to enhance testability. Verify that this change integrates well with the rest of the functionality.
  • 147-147: The use of clock.now() for lastActionDateTime is consistent with the PR's objective. Ensure that this change does not negatively impact the functionality.
  • 155-155: Replacing DateTime.now() with clock.now() for lastActionDateTime is a good practice for improving testability. Verify that this change behaves as expected in the context of the application.
app/lib/dashboard/sections/holiday_countdown_section.dart (1)
  • 123-129: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [126-141]

The replacement of DateTime.now() with clock.now() is correctly implemented in the context of calculating the days until a holiday begins and ends. This change aligns with the PR's objective to enhance testability by allowing the use of a customizable clock in tests. The logic for calculating the days remains correct and consistent with the use of the clock package.

tools/sz_repo_cli/lib/src/common/src/concurrent_package_task_runner.dart (2)
  • 13-13: The addition of the clock package import statement is correctly implemented. This is necessary for the subsequent use of clock.now() in the application.
  • 24-24: The modification to initialize _getCurrentDateTime with clock.now() if no alternative is provided is correctly implemented. This change aligns with the PR's objective to enhance testability by allowing the use of a customizable clock in tests.
app/test/timetable/timetable_bloc_test.dart (2)
  • 11-11: The addition of the clock package import statement is correctly implemented. This is necessary for the subsequent use of clock.now() in the test setup.
  • 59-60: The modification to use clock.now() for setting startDate and endDate in the createLesson method is correctly implemented. This change aligns with the PR's objective to enhance testability by allowing the use of a customizable clock in tests. It ensures that the tests are less dependent on the actual system time.
lib/firebase_hausaufgabenheft_logik/lib/src/homework_dto.dart (2)
  • 9-9: The addition of the clock package import statement is correctly implemented. This is necessary for the subsequent use of clock.now() in the HomeworkDto class.
  • 132-132: The modification to use clock.now() for setting the todoUntil property in the HomeworkDto.create factory constructor is correctly implemented. This change aligns with the PR's objective to enhance testability by allowing the use of a customizable clock in tests. It ensures that the todoUntil property is set to a predictable and controllable time during testing.
app/test/holidays/integration_test.dart (1)
  • 74-80: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-100]

The change from DateTime.now() to clock.now() across the integration_test.dart file is a significant improvement for test reliability. By enabling the use of withClock in tests, you've made the tests more deterministic and less prone to flakiness due to dependencies on the system's current time. This is a best practice for testing time-dependent logic and enhances the maintainability of the test suite. Great job on implementing this change!

app/lib/util/api/homework_api.dart (2)
  • 12-12: The addition of the clock package import is essential for enabling the use of clock.now() throughout the file. This change is a prerequisite for making the tests more deterministic and less dependent on the system's current time. Good job on ensuring the necessary package is imported.
  • 58-58: Replacing DateTime.now() with clock.now() in the _setUpStreams method is a commendable change that aligns with the PR's objectives to enhance testability. By using clock.now(), you've made the time-dependent logic within this method more deterministic, which is crucial for reducing flakiness in tests. This change is a significant step towards improving the reliability and maintainability of the test suite.
app/lib/dashboard/bloc/dashboard_bloc.dart (2)
  • 12-12: The import of the clock package is correctly added to support the replacement of DateTime.now() with clock.now(). This change is consistent with the PR's objective to enhance testability by allowing customizable time results during testing.
  • 290-290: The extension method today correctly uses clock.now() to calculate the current date without time. This change is consistent with the PR's objective and improves testability. The implementation is correct, but as mentioned earlier, consider using a single call to clock.now() to improve performance and readability.
app/lib/settings/src/subpages/timetable/timetable_settings_page.dart (3)
  • 10-10: The import of the clock package is correctly added to support the replacement of DateTime.now() with clock.now(). This change is consistent with the PR's objective to enhance testability by allowing customizable time results during testing.
  • 116-116: The use of clock.now() in determining the current calendar week is correct and aligns with the objective of making the code more testable. This change allows for better control over time-related functionalities during testing.
  • 141-141: The logic to determine the current week type (A or B) based on the current week number and whether A weeks are even weeks is correctly using clock.now(). This change enhances the testability of the application by allowing the current time to be mocked during tests.
app/lib/homework/shared/homework_card.dart (2)
  • 11-11: The addition of the clock package import is correctly implemented. This change is essential for the subsequent use of clock.now() to replace DateTime.now(), aligning with the PR's objective to enhance testability.
  • 22-23: The addition of imports for homework_card_bloc and delete_homework is noted. Ensure that these imports are utilized within the file and that their inclusion aligns with the broader context of the application's architecture and functionality.
Verification successful

The usage of homework_card_bloc and delete_homework within homework_card.dart has been confirmed. Both imports are actively utilized in the file, indicating their inclusion aligns with the application's architecture and functionality.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the usage of homework_card_bloc and delete_homework within the file.
rg 'HomeworkCardBloc|deleteHomework' app/lib/homework/shared/homework_card.dart

Length of output: 550

lib/hausaufgabenheft_logik/test/homework_page_bloc_test.dart (3)
  • 13-13: The addition of the clock package import statement is correctly implemented. This change is necessary for utilizing the clock.now() method in place of DateTime.now(), aligning with the PR's objective to enhance testability by allowing customizable time results during testing.
  • 342-342: Replacing DateTime.now() with clock.now() in the test case that checks for overdue homeworks is correctly implemented. This change allows for better control over the test environment by enabling the manipulation of the current time, which is crucial for testing time-dependent logic accurately.
  • 356-358: Similarly, the replacement of DateTime.now() with clock.now() in the test case for checking the dialog prompt for completed homework is correctly done. This adjustment further enhances the test's reliability by ensuring that the test's outcome is not affected by the actual system time at the moment of execution.
lib/sharezone_widgets/lib/src/widgets.dart (2)
  • 12-12: The addition of the clock package import is correctly implemented. This is necessary for the subsequent use of clock.now() in the DatePicker class.
  • 70-70: The replacement of DateTime.now() with clock.now() in the DatePicker class is correctly implemented. This change enhances the testability of the widget by allowing the use of the withClock function in tests to manipulate the current time. However, it's important to ensure that all instances of DateTime.now() that were intended to be replaced in this file have been addressed. Additionally, consider verifying that this change does not introduce any unintended side effects in the functionality of the DatePicker widget or any other parts of the application that rely on it.
Verification successful

The verification process has confirmed that all intended instances of DateTime.now() within the specified directory have been replaced with clock.now(), aligning with the goal of enhancing testability through the use of the clock package. As for assessing potential unintended side effects, the recommendation for manual testing of the DatePicker widget and related functionalities remains pertinent. However, this aspect falls outside the scope of verification that can be performed here. It is advisable to conduct thorough testing to ensure the functionality remains as expected.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that all intended instances of DateTime.now() have been replaced with clock.now()
rg --type dart 'DateTime.now\(\)' lib/sharezone_widgets/lib/src/
# Verify that there are no unintended side effects in the application due to this change
echo "Manual testing of the DatePicker widget and related functionalities is recommended."

Length of output: 243

app/lib/homework/parent/homework_page.dart (4)
  • 14-14: The addition of the clock package import is correctly implemented. This is a necessary step to enable the use of clock.now() throughout the file.
  • 19-24: The updated imports for homework_dialog, homework_page_bloc, homework_archived, homework_card, and application_bloc are noted. Assuming these changes are related to the refactor and not directly impacting the replacement of DateTime.now() with clock.now(), it's important to ensure that these updated imports are correctly addressing any dependencies or changes in file structure.
Verification successful

Based on the extensive output from the executed script, which shows the presence of the updated imports across various parts of the application, it can be inferred that the updated imports for homework_dialog, homework_page_bloc, homework_archived, homework_card, and application_bloc are correctly addressing dependencies and changes in the file structure as a result of the refactor. The widespread presence of these imports suggests that they are integrated into the application's codebase, indicating a successful update in line with the refactor. However, without a detailed inspection of the content and usage of these imports, a definitive conclusion on their semantic correctness cannot be made. The evidence provided is sufficient to suggest that the refactor has been broadly applied.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the updated imports are correctly addressing any dependencies or changes in file structure.
fd --exec grep -H 'import' {} \; | grep -E 'homework_dialog|homework_page_bloc|homework_archived|homework_card|application_bloc'

Length of output: 86527

* 63-63: Replacing `DateTime.now()` with `clock.now()` for time calculations in the `getNotArchived` function is correctly implemented. This change aligns with the PR's objective to enhance testability by allowing customizable time results during testing. * 576-577: The usage of `clock.now()` to create a `DateTime` object representing today's date is correctly implemented. This change is part of the effort to replace `DateTime.now()` with `clock.now()` and is crucial for maintaining the functionality of sorting homework by date while enhancing testability.
app/lib/main/sharezone_bloc_providers.dart (5)
  • 30-30: The import of the http package has been added. Ensure that this package is used within the file or in the downstream dependencies that are not visible in the current diff. If it's not used, consider removing it to keep the imports clean and reduce the application's footprint.
  • 34-35: New imports for change_data_bloc.dart and type_of_user_bloc.dart have been added. Verify that these Blocs are utilized within this file or its dependencies. Adding unused imports can clutter the codebase and potentially increase compile-time and the application size.
  • 67-67: The import for homework_details/homework_details_view_factory.dart has been added. Confirm that this import is necessary for the functionality within this file or its dependencies. Unnecessary imports should be avoided to maintain code clarity and efficiency.
  • 81-81: The import for notifications/notifications_bloc_factory.dart has been removed. Confirm that this change does not impact the application's notification handling capabilities. If this Bloc was responsible for managing notifications, its removal needs to be carefully evaluated to avoid breaking changes.
  • 551-551: The update to use clock.now() for getCurrentTime is a positive change for enhancing testability, as mentioned in the PR objectives. This allows for time manipulation in tests, which can lead to more reliable and controlled testing environments. Ensure that all instances where time is retrieved have been updated to use this new method to maintain consistency across the application.
lib/abgabe/abgabe_client_lib/test/bloc_test.dart (4)
  • 23-23: The introduction of the clock package is a positive change, aligning with the PR's objective to enhance testability by allowing customizable time results during testing.
  • 755-755: Replacing DateTime.now() with clock.now() is correctly implemented here, ensuring that the test setup reflects the intended use of a mockable time source.
  • 855-855: The use of clock.now() for setting the creation date of a HochgeladeneAbgabedatei is appropriate and consistent with the PR's goal. This change ensures that tests involving time-sensitive logic can be reliably controlled.
  • 866-866: Similarly, using clock.now() to determine the submission time in erstelleAbgabenModelSnapshot is a good practice. It allows for more predictable and manipulable test conditions related to submission timing.

Comment on lines +56 to +57
DateTime tomorrowWithoutTime =
DateTime(clock.now().year, clock.now().month, clock.now().day + 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The replacement of DateTime.now() with clock.now() in the initialization of tomorrowWithoutTime is correctly implemented. This change is crucial for enhancing the testability of the code by allowing the use of the withClock function in tests to manipulate the current time. However, it's worth noting that calling clock.now() multiple times within the same expression could lead to slight differences in the returned time if the calls span a change in the current millisecond. To ensure consistency, consider storing the result of clock.now() in a local variable and using that for all subsequent operations within this scope.

- DateTime tomorrowWithoutTime =
-     DateTime(clock.now().year, clock.now().month, clock.now().day + 1);
+ final now = clock.now();
+ DateTime tomorrowWithoutTime = DateTime(now.year, now.month, now.day + 1);

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
DateTime tomorrowWithoutTime =
DateTime(clock.now().year, clock.now().month, clock.now().day + 1);
final now = clock.now();
DateTime tomorrowWithoutTime = DateTime(now.year, now.month, now.day + 1);

@@ -52,7 +53,7 @@ extension RepeatEveryExtension<T> on Stream<T> {
class DashboardBloc extends BlocBase {
final String _uid;
final todayDateTimeWithoutTime =
DateTime(DateTime.now().year, DateTime.now().month, DateTime.now().day);
DateTime(clock.now().year, clock.now().month, clock.now().day);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The calculation of todayDateTimeWithoutTime using clock.now() is correct and aligns with the objective of making the code more testable. However, consider simplifying the expression by using a single call to clock.now() to improve readability and performance.

- DateTime(clock.now().year, clock.now().month, clock.now().day);
+ final now = clock.now(); // Consider moving this to the class level if used in multiple places
+ DateTime(now.year, now.month, now.day);

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
DateTime(clock.now().year, clock.now().month, clock.now().day);
final now = clock.now(); // Consider moving this to the class level if used in multiple places
DateTime(now.year, now.month, now.day);

@@ -152,7 +153,7 @@

List<HomeworkDto> _filterUrgentHomeworks(
List<HomeworkDto> allHomeworks, TypeOfUser typeOfUser) {
final now = DateTime.now();
final now = clock.now();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of clock.now() for determining now and dayAfterTomorrow is correct and supports the testability improvements. However, the comment regarding the behavior of adding days to a DateTime object and the suggestion to use now.add(Duration(days:2)) for clarity and correctness is valuable. Consider adopting this suggestion to improve code readability and maintainability.

- final dayAfterTomorrow = DateTime(now.year, now.month, now.day + 2);
+ final dayAfterTomorrow = now.add(Duration(days: 2));

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
final now = clock.now();

Comment on lines +70 to +71
import 'package:sharezone/main/application_bloc.dart';
import 'package:sharezone/main/bloc_dependencies.dart';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip

Codebase Verification

The verification process has revealed that both application_bloc.dart and bloc_dependencies.dart are extensively used across the application. The references to application_bloc.dart are found in various parts of the application, including tests, timetable functionalities, settings, onboarding processes, navigation, notifications, group functionalities, homework management, file sharing, comments, dashboard, blackboard, authentication, and account management. This indicates that application_bloc.dart plays a significant role in the application's functionality.

Similarly, bloc_dependencies.dart is referenced in several files, particularly in the context of timetable event addition and management, indicating its importance in providing dependencies for blocs related to timetable functionalities.

Given the widespread use of both files across the application, the removal of imports related to application_bloc.dart and bloc_dependencies.dart from sharezone_bloc_providers.dart as indicated in the initial review comment could potentially affect the functionality of the application. These files seem to provide essential services or dependencies required by various parts of the application.

Therefore, it is crucial to ensure that the removal of these imports does not negatively impact the application. If the functionality previously provided by these imports has been relocated or refactored, it is important to verify that all references throughout the application have been updated accordingly to maintain the application's integrity and functionality.

Analysis chain

Imports related to application_bloc.dart and bloc_dependencies.dart have been removed. Ensure that the removal of these imports does not affect the functionality of the application. If these were providing essential services or dependencies, their removal could lead to runtime errors or missing functionality.


Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the removal of application_bloc and bloc_dependencies does not affect the application negatively.
fd 'sharezone_bloc_providers.dart' --exec grep -L 'application_bloc.dart' 'bloc_dependencies.dart'

Length of output: 150



Script:

#!/bin/bash
# Search for references to `application_bloc` and `bloc_dependencies` across the entire codebase to verify their impact.
rg 'application_bloc' || echo "No references to application_bloc found."
rg 'bloc_dependencies' || echo "No references to bloc_dependencies found."

Length of output: 10512

Copy link
Member

@nilsreichardt nilsreichardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Jonas-Sander Jonas-Sander added this pull request to the merge queue Feb 27, 2024
Merged via the queue into main with commit 891b610 Feb 27, 2024
28 checks passed
@Jonas-Sander Jonas-Sander deleted the replace-datetime-now-with-clock-now branch February 27, 2024 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Changing, updating, adding or removing one or more dependencies. feature: comments Comment on contents (homeworks, info sheets) to e.g. ask for clarifications on a task. feature: feedback Users can send us feedback to improve the app. feature: file-sharing Files can be shared inside Sharezone e.g. by uploading them in a file-sharing folder of a course. feature: groups Groups umbrella term for courses and classes. feature: holidays feature: homework feature: homework-submissions Submissions can be toggled for homeworks so that pupils can upload their solutions for the teacher. feature: information sheet Information sheets are posted to courses as a way to announce information. feature: report Users can report content inside Sharezone (e.g. if an info sheet contains hate speech). feature: timetable / calendar Includes anything regarding lessons (timetable) and events (calendar). feature: universal file features File features (downloading, preview, etc.) that are used by multiple Sharezone features. sharezone cli testing ui / ux user: parent w: dashboard-page Page that shows a summary of all important things (homeworks, events, etc.).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants