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

Test for location input on /settings page. #1204

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

petercr
Copy link
Contributor

@petercr petercr commented Nov 1, 2024

✨ Codu Pull Request 💻

Fixes #1168
Part 5

Pull Request details

Added UI tests for the #location input on the settings page:

  • tests to see if input is working
  • check for input attributes
  • change state and safe
  • check for change persisting after save

Any Breaking changes

None

Associated Screenshots

None

What gif best describes this PR or how it makes you feel

This is me trying to finish all my PRs last minute! 😂

This is me trying to finsih all my PRs last minute style.

@petercr petercr requested a review from a team as a code owner November 1, 2024 03:44
Copy link

vercel bot commented Nov 1, 2024

@petercr 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 Nov 1, 2024

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

📥 Commits

Reviewing files that changed from the base of the PR and between 4699c2b and 1fad2e0.

📒 Files selected for processing (1)
  • e2e/settings.spec.ts (2 hunks)
 ____________________________________________________________________________________________________________________________________________
< Organize teams around functionality. Don't separate designers from coders, testers from data modelers. Build teams the way you build code. >
 --------------------------------------------------------------------------------------------------------------------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).

Walkthrough

The changes in this pull request enhance the end-to-end test suite for the authenticated settings page in the application. Modifications include the addition of new tests for the username and location input fields, which verify their visibility, validation, and persistence of values. The tests ensure that the functionalities align with the expected behaviors outlined in the linked issue.

Changes

Files Change Summary
e2e/settings.spec.ts Updated import statements and added tests for username and location input fields, focusing on visibility, validation, and persistence.

Assessment against linked issues

Objective Addressed Explanation
Add tests for username field (Issue #1168)
Add tests for location field (Issue #1168)
Ensure tests follow authenticated/unauthenticated pattern (Issue #1168)
Validate input fields against Zod schema (Issue #1168) Unclear if all tests align with the current Zod validation schema.
Propose additional relevant tests (Issue #1168) No additional tests were proposed beyond the specified ones.

Possibly related PRs

  • Template/e2e/testing #1167: The introduction of a new test suite for the settings page aligns with the main PR's focus on enhancing the test suite for the authenticated settings page.

Suggested labels

hacktoberfest-accepted, hacktoberfest

Suggested reviewers

  • NiallJoeMaher

Poem

In the land of settings, where tests do play,
A rabbit hops in, to brighten the day.
With username checks and locations so bright,
Our tests now shine with validation's light!
So let’s save our changes, let’s give them a cheer,
For a well-tested page brings us all near! 🐇✨

Tip

You can disable the changed files summary in the walkthrough.

Disable the reviews.changed_files_summary setting in your project's settings in CodeRabbit to disable the changed files summary in the walkthrough.


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.

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

🧹 Outside diff range and nitpick comments (2)
e2e/settings.spec.ts (2)

43-43: Improve test description

The current test name "location input is visible" doesn't fully describe all the test cases within. Consider a more comprehensive description.

-test('location input is visible', async ({page}) => {
+test('location input field validation and persistence', async ({page}) => {

42-58: Add accessibility tests

As mentioned in the PR objectives, accessibility testing is required. Consider adding tests to verify:

  • Keyboard navigation
  • ARIA labels and roles
  • Focus management

Example test to add:

test('location input meets accessibility requirements', async ({page}) => {
  await page.goto('http://localhost:3000/settings');
  const locationInput = page.locator('#location');
  
  // Test keyboard navigation
  await page.keyboard.press('Tab');
  await expect(locationInput).toBeFocused();
  
  // Test ARIA labels
  await expect(locationInput).toHaveAttribute('aria-label', 'Location');
});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2df1fd9 and 8724657.

📒 Files selected for processing (1)
  • e2e/settings.spec.ts (2 hunks)
🔇 Additional comments (2)
e2e/settings.spec.ts (2)

1-1: LGTM!

The import statement correctly includes both test and expect from Playwright.


51-52: Review autocomplete attribute value

The autocomplete value 'country-name' might not be appropriate for a location field that accepts cities or general locations. Consider using 'address-level1' or 'address-level2' depending on the expected input.

e2e/settings.spec.ts Outdated Show resolved Hide resolved
Comment on lines 28 to 32
await inputField.fill('45&p^x#@!96%*()');
await page.locator('button[type="submit"]').click();
const errorMessage = page.locator('p:text-is("Username can only contain alphanumerics and dashes.")')
await expect(errorMessage).toBeVisible();
await expect(errorMessage).toHaveText('Username can only contain alphanumerics and dashes.');
Copy link
Contributor

@coderabbitai coderabbitai bot Nov 1, 2024

Choose a reason for hiding this comment

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

⚠️ Potential issue

Simplify error message assertion

The error message assertion is duplicated. Also, consider testing additional validation rules like minimum/maximum length constraints.

-const errorMessage = page.locator('p:text-is("Username can only contain alphanumerics and dashes.")')
-await expect(errorMessage).toBeVisible();
-await expect(errorMessage).toHaveText('Username can only contain alphanumerics and dashes.');
+const errorMessage = page.getByText('Username can only contain alphanumerics and dashes.');
+await expect(errorMessage).toBeVisible();

+// Add tests for length constraints
+await inputField.fill('a');  // Too short
+await page.locator('button[type="submit"]').click();
+await expect(page.getByText('Username must be at least 3 characters')).toBeVisible();

Copy link
Contributor

Choose a reason for hiding this comment

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

@petercr this seems like good points, could you add this changes? :) thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@CarolinaCobo I think I already did this on PR #1203
That PR handled the username input and testing.
But let me know if you want me to add anything there 👌

This one #1204 is focusing on the #location input.
I have tested for max length and its error, but there is no minimum length for location currently.

e2e/settings.spec.ts Outdated Show resolved Hide resolved
e2e/settings.spec.ts Outdated Show resolved Hide resolved
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 (1)
e2e/settings.spec.ts (1)

63-69: Add comprehensive validation tests for location input.

The current validation only tests the maximum length. Consider adding more validation cases for better coverage.

Add these additional test cases:

   // Add validation tests for location
+  // Test empty state
+  await page.locator('input[id="location"]').fill("");
+  await page.locator('button[type="submit"]').click();
+  await expect(page.getByText("Location is required")).toBeVisible();
+
+  // Test trimming
+  await page.locator('input[id="location"]').fill("  New York  ");
+  await page.locator('button[type="submit"]').click();
+  await expect(page.locator('input[id="location"]')).toHaveValue("New York");
+
+  // Test special characters
+  await page.locator('input[id="location"]').fill("New York!@#$%");
+  await page.locator('button[type="submit"]').click();
+  await expect(page.getByText("Location contains invalid characters")).toBeVisible();
+
   // Test maximum length
   await page.locator('input[id="location"]').fill("a".repeat(101));
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8724657 and 4699c2b.

📒 Files selected for processing (1)
  • e2e/settings.spec.ts (2 hunks)

await page.goto("http://localhost:3000/settings");

// Test to see if input is visible
await page.locator('input[id="location"]').isVisible();
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

Fix incorrect usage of isVisible() method.

The isVisible() method returns a Promise that needs to be properly handled with an assertion.

Replace with:

-await page.locator('input[id="location"]').isVisible();
+await expect(page.locator('input[id="location"]')).toBeVisible();
📝 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
await page.locator('input[id="location"]').isVisible();
await expect(page.locator('input[id="location"]')).toBeVisible();

Comment on lines 70 to 76
// Test to see if change in location persists after submit and page reload
await page.fill('input[id="location"]', "A fun place to visit.");
await page.locator('button[type="submit"]').click();
await expect(page.locator('input[id="location"]')).toHaveValue(
"A fun place to visit.",
);
});
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

Add missing page reload in persistence test.

The test comment mentions verifying persistence after page reload, but the actual reload step is missing.

Add the reload step:

   await page.fill('input[id="location"]', "A fun place to visit.");
   await page.locator('button[type="submit"]').click();
   await expect(page.locator('input[id="location"]')).toHaveValue(
     "A fun place to visit.",
   );
+  // Verify persistence after reload
+  await page.reload();
+  await expect(page.locator('input[id="location"]')).toHaveValue(
+    "A fun place to visit.",
+  );
📝 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 to see if change in location persists after submit and page reload
await page.fill('input[id="location"]', "A fun place to visit.");
await page.locator('button[type="submit"]').click();
await expect(page.locator('input[id="location"]')).toHaveValue(
"A fun place to visit.",
);
});
// Test to see if change in location persists after submit and page reload
await page.fill('input[id="location"]', "A fun place to visit.");
await page.locator('button[type="submit"]').click();
await expect(page.locator('input[id="location"]')).toHaveValue(
"A fun place to visit.",
);
// Verify persistence after reload
await page.reload();
await expect(page.locator('input[id="location"]')).toHaveValue(
"A fun place to visit.",
);
});

e2e/settings.spec.ts Show resolved Hide resolved
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.

E2E test - /settings page - Multiple issues available
2 participants