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

added Unittests for lib/widgets/event_card.dart #2668

Closed

Conversation

sayyad-asifbasha
Copy link

@sayyad-asifbasha sayyad-asifbasha commented Dec 17, 2024

What kind of change does this PR introduce?

Unittests for lib/widgets/event_card.dart

Issue Number:

Fixes #2618

Did you add tests for your changes?

Yes

Snapshots/Videos:
Screenshot 2024-12-16 175415

Have you read the contributing guide?

Yes

Summary by CodeRabbit

  • Tests
    • Added test cases to verify the visibility of the "Created" row in the EventCard widget based on the user's role as the event creator.
  • Chores
    • Introduced a new Continuous Integration (CI) workflow to automate testing and coverage reporting for code changes.

Copy link
Contributor

coderabbitai bot commented Dec 17, 2024

Walkthrough

The pull request introduces two new test cases in the event_card_test.dart file, which assess the visibility of the "Created" row in the EventCard widget. The tests determine whether the "Created" row is displayed when the current user is the event creator and confirm its absence when the user is not. Additionally, a new Continuous Integration (CI) workflow is established in the .github/workflows/ci.yml file to automate testing and ensure code quality before merging.

Changes

File Change Summary
test/widget_tests/widgets/event_card_test.dart Added two test cases:
1. Verifies "Created" row visibility when user is event creator
2. Checks absence of "Created" row when user is not the creator
.github/workflows/ci.yml Introduced a new CI workflow that includes:
1. Code checkout
2. Node.js setup
3. Dependency installation
4. Test execution with coverage
5. Coverage report upload

Assessment against linked issues

Objective Addressed Explanation
100% Coverage [#2618] Uncertainty regarding the overall coverage percentage after changes.
Unittests for event_card.dart [#2618] Two new test cases added for widget functionality.
No functionality removal [#2618] No functionality was removed.

Poem

🐰 A rabbit's test of widget might,
Two cases hopping into light,
Created row, now clear and bright,
Checking who can claim event's height,
Widget testing with pure delight! 🧪


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
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.

Actionable comments posted: 1

🧹 Nitpick comments (2)
test/widget_tests/widgets/event_card_test.dart (2)

199-208: LGTM! Consider adding a descriptive doc comment.

The test case effectively verifies the creator indicators when the current user is the event creator. The setup and assertions are clear and appropriate.

Consider adding a doc comment to improve test documentation:

+    /// Verifies that when the current user is the event creator:
+    /// - The verified icon is displayed
+    /// - The "Created" text is shown
     testWidgets('Check for Created Row visibility', (tester) async {

210-220: Consider consistency improvements and documentation.

A few suggestions to enhance this test case:

  1. Use pump() instead of pumpAndSettle() for consistency with other tests, unless there's a specific need for animations to complete
  2. Consider a more concise name like 'Check Created Row hidden for non-creators'
  3. Add documentation for clarity

Consider applying these changes:

+    /// Verifies that when the current user is not the event creator:
+    /// - The verified icon is hidden
+    /// - The "Created" text is hidden
-    testWidgets('Check for absence of Created Row for non-creators',
+    testWidgets('Check Created Row hidden for non-creators',
         (tester) async {
       mockNetworkImages(() async {
         final event = getEvent();
         userConfig.currentUser.id = "nonCreatorId";
         await tester.pumpWidget(createCustomEventCard(event));
-        await tester.pumpAndSettle();
+        await tester.pump();
         expect(find.byIcon(Icons.verified), findsNothing);
         expect(find.text('Created'), findsNothing);
       });
     });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 506457a and 12625fe.

📒 Files selected for processing (1)
  • test/widget_tests/widgets/event_card_test.dart (1 hunks)

Comment on lines +199 to +220
testWidgets('Check for Created Row visibility', (tester) async {
mockNetworkImages(() async {
final event = getEvent();
userConfig.currentUser.id = event.creator!.id;
await tester.pumpWidget(createCustomEventCard(event));
await tester.pump();
expect(find.byIcon(Icons.verified), findsOneWidget);
expect(find.text('Created'), findsOneWidget);
});
});

testWidgets('Check for absence of Created Row for non-creators',
(tester) async {
mockNetworkImages(() async {
final event = getEvent();
userConfig.currentUser.id = "nonCreatorId";
await tester.pumpWidget(createCustomEventCard(event));
await tester.pumpAndSettle();
expect(find.byIcon(Icons.verified), findsNothing);
expect(find.text('Created'), findsNothing);
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Additional test cases needed for null safety

Looking at the EventCard implementation and existing tests, I can confirm that edge cases for null values need coverage. The widget uses null-aware operators and null checks:

  • event.isRegistered ?? false
  • event.creator!.id is force-unwrapped, which could crash if creator is null
  • event.attendees?.length ?? 0 has null safety but isn't tested

Add these test cases:

  1. When event.creator is null
  2. When event.isRegistered is null (currently defaults to false)
  3. When event.attendees is null (currently defaults to 0)
🔗 Analysis chain

Verify test coverage for edge cases.

The new tests effectively cover the basic creator visibility scenarios. Consider adding tests for these edge cases:

  1. When creator field is null
  2. When current user ID is null
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if these edge cases are already covered elsewhere
rg -A 5 "creator.*null|currentUser.*null" "test/widget_tests"

Length of output: 61


Script:

#!/bin/bash
# Let's check the event_card_test.dart file to understand the test setup and existing test cases
cat test/widget_tests/widgets/event_card_test.dart

Length of output: 6706


Script:

#!/bin/bash
# Let's check the EventCard widget implementation to understand how it handles null cases
cat talawa/widgets/event_card.dart

Length of output: 99


Script:

#!/bin/bash
# Let's find the correct path to the event_card widget
fd -t f "event_card.dart" 

Length of output: 53


Script:

#!/bin/bash
# Now let's check the EventCard widget implementation
cat lib/widgets/event_card.dart

Length of output: 12605

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.

Actionable comments posted: 4

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 12625fe and f85fdc2.

📒 Files selected for processing (1)
  • .github/workflows/ci.yml (1 hunks)

Comment on lines +1 to +37
name: CI Workflow

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest

steps:
# Step 1: Checkout your repository
- name: Checkout code
uses: actions/checkout@v4

# Step 2: Set up Node.js
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20' # Adjust Node.js version if needed

# Step 3: Install project dependencies
- name: Install dependencies
run: npm install

# Step 4: Run tests and generate coverage report
- name: Run tests with Jest
run: npx jest --coverage

# Step 5: Upload coverage report to Codecov
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: sayyad-asifbasha/mess-backend-firebase
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Provide complete Flutter CI workflow template

Here's a complete Flutter CI workflow template that would be more appropriate for this project:

name: Flutter CI

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Set up Flutter
        uses: subosito/flutter-action@v2
        with:
          flutter-version: '3.x'
          channel: 'stable'

      - name: Install dependencies
        run: flutter pub get

      - name: Analyze code
        run: flutter analyze

      - name: Run tests
        run: flutter test --coverage

      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@v5
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          slug: PalisadoesFoundation/talawa

This workflow includes:

  • Proper Flutter SDK setup
  • Flutter dependency installation
  • Static code analysis
  • Flutter test runner with coverage
  • Correct repository configuration for Codecov

Comment on lines +19 to +26
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20' # Adjust Node.js version if needed

# Step 3: Install project dependencies
- name: Install dependencies
run: npm install
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical: Incorrect technology stack configuration

This workflow is configured for Node.js/Jest testing, but the project is a Flutter/Dart application. The Node.js setup and npm dependencies are not appropriate for testing Flutter widgets.

Replace the Node.js setup with Flutter SDK setup:

-      # Step 2: Set up Node.js
-      - name: Set up Node.js
-        uses: actions/setup-node@v4
-        with:
-          node-version: '20'  # Adjust Node.js version if needed
-
-      # Step 3: Install project dependencies
-      - name: Install dependencies
-        run: npm install
+      # Step 2: Set up Flutter
+      - name: Set up Flutter
+        uses: subosito/flutter-action@v2
+        with:
+          flutter-version: '3.x'
+          channel: 'stable'
+
+      # Step 3: Get Flutter dependencies
+      - name: Get dependencies
+        run: flutter pub get
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20' # Adjust Node.js version if needed
# Step 3: Install project dependencies
- name: Install dependencies
run: npm install
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: '3.x'
channel: 'stable'
# Step 3: Get Flutter dependencies
- name: Get dependencies
run: flutter pub get

Comment on lines +29 to +30
- name: Run tests with Jest
run: npx jest --coverage
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical: Incorrect test runner configuration

The workflow is using Jest for testing, which is a JavaScript test runner. Flutter tests should be run using flutter test.

Replace the Jest test command with Flutter test:

-      # Step 4: Run tests and generate coverage report
-      - name: Run tests with Jest
-        run: npx jest --coverage
+      # Step 4: Run Flutter tests with coverage
+      - name: Run tests
+        run: flutter test --coverage
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Run tests with Jest
run: npx jest --coverage
# Step 4: Run Flutter tests with coverage
- name: Run tests
run: flutter test --coverage

Comment on lines +36 to +37
token: ${{ secrets.CODECOV_TOKEN }}
slug: sayyad-asifbasha/mess-backend-firebase
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical: Incorrect repository configuration

The Codecov slug is pointing to sayyad-asifbasha/mess-backend-firebase instead of PalisadoesFoundation/talawa.

Fix the repository configuration:

         uses: codecov/codecov-action@v5
         with:
           token: ${{ secrets.CODECOV_TOKEN }}
-          slug: sayyad-asifbasha/mess-backend-firebase
+          slug: PalisadoesFoundation/talawa
📝 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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
token: ${{ secrets.CODECOV_TOKEN }}
slug: sayyad-asifbasha/mess-backend-firebase
token: ${{ secrets.CODECOV_TOKEN }}
slug: PalisadoesFoundation/talawa

@palisadoes
Copy link
Contributor

We have a policy of unassigning contributors who close PRs without getting validation from our reviewer team. This is because:

  1. We start looking for people to review PRs when you submit them.
  2. We often contact them and link to the PR. If the PR is closed the whole effort is wasted.
  3. The historical thread of reviewer comments is broken when the work is spread across multiple PRs. The quality of our code is affected negatively.

Please be considerate of our volunteers' limited time and our desire to improve our code base.

This policy is stated as a pinned post in all our Talawa repositories. Our YouTube videos explain why this practice is not acceptable to our Community.

Unfortunately, if this continues we will have to close the offending PR and unassign you from the issue.

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