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

feat: adding e2e test for article commenting #1158

Conversation

JohnAllenTech
Copy link
Contributor

@JohnAllenTech JohnAllenTech commented Oct 20, 2024

✨ Codu Pull Request 💻

Improves E2E testing for the project by adding tests around a user commenting on an article

Pull Request details

  • Checks authenticated user can post a comment
  • Checks that an unauthenticated user cannot post a comment

Any Breaking changes

  • None

Associated Screenshots

image
Tests passing

image
Example comment generated by E2E test. The uuid needs to be added as if multiple a user runs the test suite multiple times we want to always ensure we are finding the comment created for that specific test run

@JohnAllenTech JohnAllenTech requested a review from a team as a code owner October 20, 2024 00:28
Copy link

vercel bot commented Oct 20, 2024

@JohnAllenTech is attempting to deploy a commit to the Codú Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Oct 20, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes made in this pull request enhance the end-to-end testing suite for the articles page. New test cases are introduced for both unauthenticated and authenticated users regarding comment functionality. The configuration file for Playwright testing is also updated to improve project name clarity, renaming "chromium" to "Desktop Chrome" and "firefox" to "Desktop Firefox," while maintaining existing settings.

Changes

File Change Summary
e2e/articles.spec.ts Added test cases for unauthenticated users unable to post comments and for authenticated users able to post comments.
playwright.config.ts Updated project names from "chromium" to "Desktop Chrome" and "firefox" to "Desktop Firefox."

Possibly related PRs

  • feat: adding e2e test for article commenting #1158: This PR directly relates to the main PR as it introduces new test cases for commenting on articles, specifically validating the behavior for both unauthenticated and authenticated users, which aligns with the changes made in the main PR.

Poem

In a world of articles bright,
Comments now take flight!
Unauthenticated, you can't play,
Authenticated, share your say!
With tests that check each right,
Our code shines, oh what a sight! 🐇✨


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

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

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.

@JohnAllenTech JohnAllenTech changed the title Feat/adding e2e test for article commenting feat:adding e2e test for article commenting Oct 20, 2024
@JohnAllenTech JohnAllenTech changed the title feat:adding e2e test for article commenting feat: adding e2e test for article commenting Oct 20, 2024
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: 3

🧹 Outside diff range and nitpick comments (2)
playwright.config.ts (1)

49-49: Consistent naming improvement for Firefox project

The renaming from "firefox" to "Desktop Firefox" is a good change, consistent with the Chrome project naming. This improves clarity and maintains a uniform naming convention.

For complete consistency, consider updating the names of the "Mobile Chrome" and "Mobile Safari" projects to follow the same pattern, e.g., "Mobile Chrome" to "Mobile Android Chrome" and "Mobile Safari" to "Mobile iOS Safari". This would provide even more explicit information about the test environments.

e2e/articles.spec.ts (1)

209-211: Remove unused 'browserName' parameter

The browserName parameter is not used within the test and can be safely removed to clean up the code.

Apply this diff to remove the unused parameter:

-  test("Should post a comment on an article", async ({
-    page,
-    browserName,
-  }, workerInfo) => {
+  test("Should post a comment on an article", async ({ page }, workerInfo) => {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 91c4627 and ad97c58.

📒 Files selected for processing (2)
  • e2e/articles.spec.ts (3 hunks)
  • playwright.config.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (3)
playwright.config.ts (2)

40-40: Improved project naming for clarity

The change from "chromium" to "Desktop Chrome" enhances readability and provides a more explicit description of the test environment. This aligns well with best practices in configuration naming.


Line range hint 1-85: Overall improvement in configuration clarity

The changes made to this configuration file enhance the readability and maintainability of the Playwright test setup. By providing more explicit names for the test projects, it becomes easier for developers to understand the purpose and environment of each test configuration at a glance.

These modifications align well with the PR objectives of improving E2E testing, as they contribute to a more organized and clear testing structure. The functional aspects of the configuration remain unchanged, ensuring that existing tests will continue to run as before.

e2e/articles.spec.ts (1)

2-2: Importing 'randomUUID' from 'crypto' is appropriate

The import statement is necessary for generating unique identifiers in your tests.

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

🧹 Outside diff range and nitpick comments (1)
e2e/articles.spec.ts (1)

62-78: LGTM: New test case for unauthenticated users

The new test case effectively verifies that unauthenticated users cannot post comments on articles. It checks for the appropriate UI elements and messages.

For consistency with other tests, consider using toBeVisible() instead of toBeHidden() on line 71:

-    await expect(page.getByPlaceholder("What do you think?")).toBeHidden();
+    await expect(page.getByPlaceholder("What do you think?")).not.toBeVisible();
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ad97c58 and 3fda823.

📒 Files selected for processing (1)
  • e2e/articles.spec.ts (3 hunks)
🧰 Additional context used
🔇 Additional comments (2)
e2e/articles.spec.ts (2)

2-2: LGTM: Import of randomUUID

The addition of the randomUUID import from the crypto module is appropriate for generating unique identifiers in the new test case.


Line range hint 1-221: LGTM: Overall structure and consistency

The new test cases are well-integrated into the existing test suite, maintaining the file's structure and readability. They follow the established patterns and conventions, which is commendable.

Comment on lines +208 to +221
test("Should post a comment on an article", async ({ page }, workerInfo) => {
const commentContent = `This is a great read. Thanks for posting! Sent from ${workerInfo.project.name} + ${randomUUID()}`;
await page.goto("http://localhost:3000");
// Waits for articles to be loaded
await expect(page.getByText("Read Full Article").first()).toBeVisible();
await page.getByText("Read Full Article").first().click();
await page.waitForURL(/^http:\/\/localhost:3000\/articles\/.*$/);

await expect(page.getByPlaceholder("What do you think?")).toBeVisible();
await page.getByPlaceholder("What do you think?").fill(commentContent);
await page.getByRole("button", { name: "Submit" }).click();

await expect(page.getByText(commentContent)).toBeVisible();
});
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

LGTM: New test case for authenticated users

The new test case effectively verifies that authenticated users can post comments on articles. The use of randomUUID() for generating unique comments is a good practice.

There's a missing await before the click() method on line 213. This issue was flagged in a previous review. Please apply the following fix:

-    await page.getByText("Read Full Article").first().click();
+    await page.getByText("Read Full Article").first().click();
📝 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
test("Should post a comment on an article", async ({ page }, workerInfo) => {
const commentContent = `This is a great read. Thanks for posting! Sent from ${workerInfo.project.name} + ${randomUUID()}`;
await page.goto("http://localhost:3000");
// Waits for articles to be loaded
await expect(page.getByText("Read Full Article").first()).toBeVisible();
await page.getByText("Read Full Article").first().click();
await page.waitForURL(/^http:\/\/localhost:3000\/articles\/.*$/);
await expect(page.getByPlaceholder("What do you think?")).toBeVisible();
await page.getByPlaceholder("What do you think?").fill(commentContent);
await page.getByRole("button", { name: "Submit" }).click();
await expect(page.getByText(commentContent)).toBeVisible();
});
test("Should post a comment on an article", async ({ page }, workerInfo) => {
const commentContent = `This is a great read. Thanks for posting! Sent from ${workerInfo.project.name} + ${randomUUID()}`;
await page.goto("http://localhost:3000");
// Waits for articles to be loaded
await expect(page.getByText("Read Full Article").first()).toBeVisible();
await page.getByText("Read Full Article").first().click();
await page.waitForURL(/^http:\/\/localhost:3000\/articles\/.*$/);
await expect(page.getByPlaceholder("What do you think?")).toBeVisible();
await page.getByPlaceholder("What do you think?").fill(commentContent);
await page.getByRole("button", { name: "Submit" }).click();
await expect(page.getByText(commentContent)).toBeVisible();
});

Copy link
Contributor

@NiallJoeMaher NiallJoeMaher left a comment

Choose a reason for hiding this comment

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

🌮🌮🌮🌮

Copy link

vercel bot commented Oct 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
codu ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 20, 2024 2:22pm

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

Successfully merging this pull request may close these issues.

2 participants