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

Increased test coverage for create_event_page.dart #2737

Open
wants to merge 4 commits into
base: develop-postgres
Choose a base branch
from

Conversation

MohitMaulekhi
Copy link
Contributor

@MohitMaulekhi MohitMaulekhi commented Feb 11, 2025

What kind of change does this PR introduce?

Unit tests to improve test coverage for create_event_page.

Issue Number:

Fixes #1242

Did you add tests for your changes?

Yes

  • [] Tests are written for all uncovered code paths.
  • [] Test coverage for create_event_page now reaches 100%.

Snapshots/Videos:

image

Summary

  1. Code refactoring was performed to reduce dependencies between UI and logic, making the code more testable.
  2. Comments that artificially inflated test coverage by ignoring lines of code have been removed.
  3. New unit tests have been added to cover all remaining code paths, achieving 100% test coverage for the create_event_page file.

Does this PR introduce a breaking change?

No

Have you read the contributing guide?

Yes

Summary by CodeRabbit

  • New Features
    • Enhanced the event creation process with improved date and time validations, ensuring events are scheduled correctly.
    • Integrated real-time error notifications to alert users when invalid date or time selections are made.
    • Introduced a default placeholder image for events lacking venue imagery, enhancing the overall user experience.

Copy link
Contributor

coderabbitai bot commented Feb 11, 2025

Walkthrough

This pull request refactors the event creation view by updating state management in the CreateEventPage. The state class has been renamed to be publicly accessible and new updater methods for start/end date and time validations have been introduced. Additionally, the tests have been expanded with new widget cases and improved assertions for date/time interactions and placeholder image display.

Changes

File(s) Change Summary
lib/views/.../create_event_page.dart Renamed the private state class to CreateEventPageState and refactored event creation logic by adding dateUpdater1, timeUpdater1, dateUpdater2, and timeUpdater2 methods.
test/views/.../create_event_page_logic_test.dart, test/views/.../create_event_page_test.dart Added and restructured widget tests to validate date/time selection, proper error handling, and placeholder image display; updated mocking behavior.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant CP as CreateEventPage
    participant DU as DateUpdater
    participant TU as TimeUpdater
    participant EM as EventModel

    U->>CP: Tap on start date tile
    CP->>DU: Invoke dateUpdater1 (validate future date)
    DU->>EM: Update start date in model

    U->>CP: Tap on start time tile
    CP->>TU: Invoke timeUpdater1 (ensure start < end)
    TU->>EM: Update start time in model

    U->>CP: Tap on end date tile
    CP->>DU: Invoke dateUpdater2 (validate date sequence)
    DU->>EM: Update end date in model

    U->>CP: Tap on end time tile
    CP->>TU: Invoke timeUpdater2 (ensure end > start)
    TU->>EM: Update end time in model
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure 100% test coverage for create_event_page.dart (#1242)

Possibly related issues

Possibly related PRs

Suggested reviewers

  • palisadoes
  • noman2002
  • Dante291

Poem

I'm a happy bunny with code so neat,
Hopping through dates and times in a rhythmic beat.
Tracker methods now guide the flow,
With tests that make our confidence grow.
Carrots and code, a delightful treat!
🐰🎉


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 392b929 and 3d3f735.

📒 Files selected for processing (3)
  • lib/views/after_auth_screens/events/create_event_page.dart (3 hunks)
  • test/views/after_auth_screens/events/create_event_page_logic_test.dart (1 hunks)
  • test/views/after_auth_screens/events/create_event_page_test.dart (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Checking codebase
🔇 Additional comments (15)
test/views/after_auth_screens/events/create_event_page_logic_test.dart (6)

1-18: LGTM! Well-structured test file with comprehensive imports.

The test file includes all necessary imports for testing Flutter widgets, localization, and mocking.


27-53: LGTM! Well-documented test helper function.

The createEventScreenForDateTimeTileTesting function is properly documented with clear parameter descriptions and return type.


70-110: LGTM! Comprehensive test for past date validation.

The test case properly validates that:

  1. Past dates are rejected with appropriate error message
  2. The event model is not updated with past dates

112-172: LGTM! Thorough test for future date validation.

The test case comprehensively verifies that:

  1. Future dates are accepted
  2. The event model is properly updated
  3. Recurrence settings are reset appropriately

174-217: LGTM! Proper validation of start time before end time.

The test case ensures that start time is validated against end time and the model is updated only when valid.


219-264: LGTM! Error handling for invalid start time.

The test case verifies that:

  1. Invalid start times (after end time) are rejected
  2. Appropriate error message is shown
  3. The model retains its original state
lib/views/after_auth_screens/events/create_event_page.dart (5)

27-27: LGTM! Made state class public for testing.

The state class has been made public to facilitate testing, which aligns with the PR's objective of increasing test coverage.

Also applies to: 31-31


35-61: LGTM! Well-implemented date validation for event start date.

The dateUpdater1 method properly validates and updates the event start date, including resetting recurrence settings when the date changes.


63-87: LGTM! Proper time validation for event start time.

The timeUpdater1 method validates start time against end time and provides appropriate error feedback.


89-117: LGTM! Comprehensive validation for event end date.

The dateUpdater2 method ensures that:

  1. End date is after start date
  2. Recurrence settings are reset appropriately
  3. Proper error messages are shown for invalid dates

119-143: LGTM! Proper time validation for event end time.

The timeUpdater2 method validates end time against start time and provides appropriate error feedback.

test/views/after_auth_screens/events/create_event_page_test.dart (4)

82-91: LGTM! Proper test environment setup and cleanup.

Added setup and teardown functions to ensure proper test environment initialization and cleanup.


258-328: LGTM! Comprehensive test for placeholder image.

The test thoroughly verifies that:

  1. Placeholder image is shown when venue has no image
  2. Image dimensions are correct
  3. Image is removed when venue is removed

709-745: LGTM! Enhanced test for first date tile interaction.

The test verifies that:

  1. Date picker dialog appears
  2. Calendar picker is shown
  3. Selected date is properly displayed

784-821: LGTM! Comprehensive tests for time tile interactions.

The tests verify both first and second time tile interactions, ensuring proper dialog display and time format.

Also applies to: 822-859


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>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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 testing code 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

Other

🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.

Copy link

codecov bot commented Feb 11, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.54%. Comparing base (7a21769) to head (3d3f735).
Report is 1 commits behind head on develop-postgres.

Additional details and impacted files
@@                 Coverage Diff                  @@
##           develop-postgres    #2737      +/-   ##
====================================================
+ Coverage             96.37%   96.54%   +0.16%     
====================================================
  Files                   189      189              
  Lines                 10020    10049      +29     
====================================================
+ Hits                   9657     9702      +45     
+ Misses                  363      347      -16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MohitMaulekhi
Copy link
Contributor Author

This PR addresses the same issue as mentioned in Issue #2620. Both issues are identical and this PR aims to resolve them.

Copy link
Contributor

@palisadoes palisadoes left a comment

Choose a reason for hiding this comment

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

Why have you removed so much logic from lib/views/after_auth_screens/events/create_event_page.dart?
image
image

);
if (validationError != null) {
// coverage:ignore-start
navigationService.showTalawaErrorSnackBar(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this logic removed?

model.recurrenceLabel = 'Does not repeat';
model.recurrenceEndDate = null;
model.isRecurring = false;
model.frequency = Frequency.weekly;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this logic removed?

if (validationError != null) {
// coverage:ignore-start
showSnackBar(
'Start time must be before end time',
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this logic removed?

Copy link
Contributor Author

@MohitMaulekhi MohitMaulekhi Feb 12, 2025

Choose a reason for hiding this comment

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

image

No logic was removed. Testing with logic embedded in UI was very difficult. So I created different functions for logics increasing code testability, readability, and overall code structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants