UI Tests for username change on /settings page. - #1203

Closed
petercr wants to merge 9 commits into
codu-code:developfrom
petercr:develop
Closed

UI Tests for username change on /settings page.#1203
petercr wants to merge 9 commits into
codu-code:developfrom
petercr:develop

Conversation

@petercr

Copy link
Copy Markdown
Contributor

✨ Codu Pull Request 💻

Fixes#1168
** Only Part 3.**

Pull Request details

Added UI tests for /settings to:

  • tests for input field & types
  • tries to submit a bad user name
  • checks for error visibility
  • resets the form
  • changes user name, saves, and checks for update

Any Breaking changes

None

Associated Screenshots

None, but the tests pass 😅 I promise!

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

Like this, only instead of Monday, Wed, Friday it's like start, middle, end 😆
A dog that starts out grumpy, then get glad, then gets happy.

@petercr
petercr requested a review from a team as a code ownerOctober 31, 2024 23:33
@vercel

vercelBot commented Oct 31, 2024

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitaiBot commented Oct 31, 2024

Copy link
Copy Markdown
Contributor

Walkthrough

The changes in this pull request enhance the end-to-end test suite for the authenticated settings page by adding a new test case focused on the username input field. The modifications include updating the import statements and implementing a series of assertions that validate the visibility, attributes, and functionality of the username input, including error handling for invalid inputs and confirmation of valid submissions.

Changes

FileChange Summary
e2e/settings.spec.tsUpdated import statements; added a new test case for username input validation, including checks for visibility, attributes, error messages, and form reset functionality.
app/(app)/settings/_client.tsxEnhanced toast notifications for success and error handling during settings save operations by adding custom class names.
e2e/setup.tsUpdated bio property in userData with a grammatical error; changed websiteUrl from a relative to an absolute URL.

Assessment against linked issues

ObjectiveAddressedExplanation
Add E2E tests for the username field (1168)
Ensure tests are standalone and focused (1168)
Validate input fields against Zod schema (1168)No explicit validation against Zod schema shown.
Cover edge cases for username input (1168)

Possibly related PRs

  • Fix/e2e tests #1061: This PR focuses on fixing and stabilizing end-to-end tests, which may relate to the enhancements made in the main PR for the settings page tests, as both involve improving test coverage and reliability.
  • fix: update e2e tests for newer changes in site #1085: This PR updates E2E tests, including modifications to the homepage tests, which may share similar testing strategies or structures with the new tests added for the settings page.
  • Feat/improving existing e2e tests #1125: This PR improves existing E2E tests, which could be relevant as it aims to enhance the overall testing framework, similar to the enhancements made in the main PR for the settings page.
  • feat: adding e2e test for article commenting #1158: This PR adds tests for commenting functionality, which may share testing principles with the username input validation in the settings tests, focusing on user input and feedback.
  • Isolating E2E test suite from seed script #1192: The isolation of the E2E test suite from the seed script may impact how tests are structured, potentially relating to the main PR's enhancements in testing.

Suggested labels

hacktoberfest-accepted, hacktoberfest

Suggested reviewers

  • NiallJoeMaher

🐰 In the land of code, where rabbits hop,
A test was added, and we won't stop!
For usernames bright, we check and we see,
Valid or not, they must be error-free!
With each little change, our coverage grows,
Hopping through tests, as the confidence flows! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fcd1dbb and c6949d0.

📒 Files selected for processing (1)
  • e2e/setup.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • e2e/setup.ts

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.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

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

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

Line range hint 4-7: Implement missing unauthenticated tests

The PR objectives mention testing unauthenticated user redirection to /get-started, but this test is missing.

Would you like me to provide an implementation for the unauthenticated test case that verifies redirection?

Comment threade2e/settings.spec.ts Outdated
Comment on lines +14 to +16
// Test for changing username
test('Username input field', async ({ page }) => {
await page.goto('http://localhost:3000/settings', { timeout: 30000 });

@coderabbitaicoderabbitaiBotOct 31, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve test configuration and navigation

Consider these improvements:

  1. The 30-second timeout seems excessive for local development
  2. The hardcoded URL should be replaced with a configurable base URL
- await page.goto('http://localhost:3000/settings', { timeout: 30000 });+ await page.goto('/settings');

Add this to your playwright.config.ts:

use: {baseURL: process.env.BASE_URL||'http://localhost:3000',}

Copy link
Copy Markdown
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!

Comment threade2e/settings.spec.ts Outdated
Comment threade2e/settings.spec.ts Outdated
Comment threade2e/settings.spec.ts
import { test, expect } from "@playwright/test";
import { loggedInAsUserOne } from "./utils";

test.describe("Unauthenticated setttings Page", () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we change this to authenticated settings page. Because the user is authenticated for these tests

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'm not sure exactly what you're saying here?

Did you want a separate file for auth vs. un-auth tests, because doesn't a user have to be logged in to edit their profile?

I guess I could use more detail on this 👌🏻

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Your new test is ran inside a test suite called 'Unauthenticated setttings Page'

But this is an authenticated test because users need to login to change their username.

If you just change the name of the test it will be fixed

Comment threade2e/settings.spec.ts Outdated
// Test that the input field can be filled with a valid value and saves it
await inputField.fill('codu-rules');
await page.locator('button[type="submit"]').click();
await expect(inputField).toHaveValue('codu-rules');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Will this wait for the username change to take effect?

If you fill in the new username and then click submit.

Will this test see the new username you have entered as the value of the input and complete straight away?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I mean the tests pass for it. But it could be just catching the still filled in form from before the reset.

Would you like me to change it to a page refresh instead?

Or would you like some kind of timeOut in-between the state change and checking for the change to persist?

I would be happy to add either one 👍🏻

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah I am not sure is there a loading indicator for these types of change? It would be nice to see

  1. Click submit
  2. Loading indicator appears
  3. Loading indicator hidden
  4. Check new username has taken effect

@JohnAllenTechJohnAllenTech left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just made some general comments. I am not a maintainer here so everything is just a suggestion

@NiallJoeMaher

Copy link
Copy Markdown
Contributor

@JohnAllenTech let me know when this is good to go since you are the overlord of tests.

@petercr

Copy link
Copy Markdown
ContributorAuthor

@JohnAllenTech I made some changes and added the extra tests you had suggested.
Tests now cover:

  • waiting for toast to show
  • waiting for toast to disappear
  • full page refresh
  • checking new value persists in input field

I did have to change a field in /e2e/setup/setup.ts to add https:// to it.
Otherwise you get an error on the form in E2E testing.

I also added new class names to both the toast messages for UI testing.

Thanks

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

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

Line range hint 4-8: Fix typo and remove empty test suite.

  1. Fix the typo in "setttings" (three 't's).
  2. The empty test suite for unauthenticated users should either be implemented or removed to maintain clean code.
-test.describe("Unauthenticated setttings Page", () => {- //- // Replace with tests for unauthenticated users-});+// TODO: Implement tests for unauthenticated users being redirected to /get-started+test.describe("Unauthenticated settings Page", () => {+ test("redirects to get-started page", async ({ page }) => {+ await page.goto("/settings");+ await expect(page).toHaveURL("/get-started");+ });+});

27-32: Improve error message validation.

The error message validation could be more robust by:

  1. Using data-testid for reliable selection
  2. Centralizing error messages
  3. Verifying error styling
+ // Define error messages+ const ERROR_MESSAGES = {+ INVALID_CHARS: 'Username can only contain alphanumerics and dashes.'+ } as const;+- const errorMessage = page.locator('p:text-is("Username can only contain alphanumerics and dashes.")')+ const errorMessage = page.locator('[data-testid="username-error"]');
await expect(errorMessage).toBeVisible();
- await expect(errorMessage).toHaveText('Username can only contain alphanumerics and dashes.');+ await expect(errorMessage).toHaveText(ERROR_MESSAGES.INVALID_CHARS);+ await expect(errorMessage).toHaveCSS('color', 'rgb(220, 38, 38)'); // Verify error styling
e2e/setup.ts (1)

123-123: Document the reason for URL format change.

While the change to use an absolute URL is sensible, it would be helpful to document why this change was necessary, especially since it seems tangential to the main PR objective of testing username changes.

Add a comment explaining the URL format requirement:

+ // Using absolute URL to comply with website URL validation requirements
websiteUrl: "https://codu.co",
app/(app)/settings/_client.tsx (2)

Line range hint 261-276: Consider adding a loading indicator during username validation.

While the username field implementation is solid, it could benefit from a visual indicator during validation to improve user experience. This would be particularly useful when checking for username availability.

Consider adding a loading state:

 <Field>
<Input
id="username"
type="text"
autoComplete="username"
invalid={!!errors?.username}
+ className={isValidating ? "opacity-50" : ""}
{...register("username")}
/>
+ {isValidating && (+ <div className="mt-2 flex items-center text-sm text-gray-500">+ <Loader2 className="mr-2 h-4 w-4 animate-spin" />+ Checking username availability...+ </div>+ )}
{errors?.username && (
<ErrorMessage>{errors.username.message}</ErrorMessage>
)}
</Field>

Line range hint 1-458: Consider breaking down the Settings component for better maintainability.

The component is well-structured but handles multiple responsibilities. Consider splitting it into smaller, focused components for better maintainability and testing.

Suggested structure:

  1. Create separate components for each section:

    • ProfilePhotoSection
    • PersonalInfoSection (name, username, bio)
    • ContactSection (location, website)
    • EmailSection
    • NotificationsSection
  2. Move the file upload logic to a custom hook:

    // hooks/useProfilePhotoUpload.tsconstuseProfilePhotoUpload=()=>{const[profilePhoto,setProfilePhoto]=useState<ProfilePhoto>({...});// ... file upload logicreturn{ profilePhoto, handleImageChange };};

This refactoring would:

  • Improve code organization
  • Make testing easier
  • Reduce cognitive load when maintaining the component
  • Allow for better error boundary placement
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e6883a5 and f9140cf.

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

43-45: Verify username persistence more thoroughly.

The current persistence check could be enhanced by:

  1. Verifying the username in the UI header/profile
  2. Checking the API response
  3. Testing persistence across multiple page navigations
✅ Verification successful

Current username persistence testing is sufficient

The current e2e test adequately verifies username persistence because:

  1. The username is properly integrated throughout the application (Nav, BioBar, Settings)
  2. The page reload test verifies server-side persistence
  3. Additional UI checks would be redundant as the username update automatically propagates through the layout and components

The implementation shows the username is:

  • Stored in the database and fetched server-side (layout.tsx)
  • Consistently displayed across navigation and profile components
  • Properly validated and persisted in settings
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash# Description: Verify username persistence across the application# Note: This script helps identify places where the username should be updated# Find files that might display or use the usernameecho"Files potentially using username:"
rg -l "username" --type=tsx --type=ts
# Find API endpoints handling usernameecho"\nAPI endpoints for username:"
rg -l "username.*api" --type=ts

Length of output: 245


Script:

#!/bin/bash# Let's try a different approach to find username-related code# Search for username-related patterns in all filesecho"Files containing username-related patterns:"
rg -l -i "username|user.*name"# Look for settings or profile-related componentsecho -e "\nSettings and profile-related files:"
fd -e ts -e tsx -e js -e jsx "settings|profile" --type f
# Search for API calls or endpointsecho -e "\nAPI-related patterns:"
rg -l "api.*username|username.*api"# Look specifically in the e2e test file to understand the context betterecho -e "\nContext from the e2e test file:"
rg -C 5 "username""e2e/settings.spec.ts"

Length of output: 3690


Script:

#!/bin/bash# Let's examine the settings page implementation and username persistence logic# Check settings page implementationecho"Settings page implementation:"
rg -C 10 "username""app/(app)/settings/_client.tsx"# Check username usage in layout and navigationecho -e "\nUsername usage in layout:"
rg -C 5 "username""app/(app)/layout.tsx"# Check profile/bio components that might display usernameecho -e "\nUsername display in BioBar:"
rg -C 5 "username""components/BioBar/BioBar.tsx"# Check navigation components for username displayecho -e "\nUsername in navigation:"
rg -C 5 "username""components/Nav/Nav.tsx"

Length of output: 4555

e2e/setup.ts (1)

123-123: Verify URL format change impact on tests.

The change from relative URL "codu.co" to absolute URL "https://codu.co" looks good, but let's ensure this aligns with the validation requirements.

Let's verify the URL validation requirements:

✅ Verification successful

URL format change aligns with schema requirements

The change from "codu.co" to "https://codu.co" is correct as the websiteUrl field in schema/profile.ts uses Zod's .url() validator, which requires a fully qualified URL with protocol. This validation would reject the previous "codu.co" format.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash# Description: Check URL validation schema and related tests# Look for URL validation schema
rg -A 5 'websiteUrl.*zod'# Look for website URL related tests
rg -A 5 'websiteUrl.*test'

Length of output: 56


Script:

#!/bin/bash# Let's try a broader search for URL validation patterns and website-related schemas# Search for any URL validation patterns
rg -i "url.*validation|validate.*url" -A 5
# Search for website URL usage in tests
rg "website.*url|url.*website" -A 5
# Search for zod schema definitions that might include URL
rg "z\.string\(\).*url|url.*z\.string" -A 5
# Look for any URL-related constants or configurations
rg "URL_PATTERN|URL_REGEX" -A 5

Length of output: 2168

app/(app)/settings/_client.tsx (1)

89-94: LGTM: Toast styling changes are clean and consistent.

The addition of className props to toast notifications provides better styling control while maintaining the existing functionality.

Comment threade2e/settings.spec.ts Outdated
Comment threade2e/settings.spec.ts Outdated
@JohnAllenTech

Copy link
Copy Markdown
Contributor

@JohnAllenTech I made some changes and added the extra tests you had suggested.

Tests now cover:

  • waiting for toast to show

  • waiting for toast to disappear

  • full page refresh

  • checking new value persists in input field

I did have to change a field in /e2e/setup/setup.ts to add https:// to it.

Otherwise you get an error on the form in E2E testing.

I also added new class names to both the toast messages for UI testing.

Thanks

Hey @petercr apologies I was AFK for a few days. I'll take a look at this in a while and reply properly

@NiallJoeMaher

Copy link
Copy Markdown
Contributor

Tests failing here.

@petercr

Copy link
Copy Markdown
ContributorAuthor

Well crap 😕 that's no good.
I will look into this over the weekend (next 2 days) and see if I can figure it out. 👌🏻

I wonder if this has to do with the newsletter sub function?
Either way I'm on it 👍🏻

@petercr

Copy link
Copy Markdown
ContributorAuthor

When I run the test locally, they all pass 🤷🏼‍♂️ see pic below.
I'm not sure but this may have to do with /server/lib/newsletter.ts.

I added extra code on line 39 to keep from getting the email API errors for the newsletter.
You can see some controller errors from posts.sidebarData and the tRPC error for profile.edit.

Here's what I added locally for this:

if(process.env.ENV==="local"||"development"){returntrue;}

But it might be simpler to go with:

if(process.env.ENV!=="production"){returntrue;}

Here is the image of the tests passing.

msrdc_ttyjHMMI1j

Sign up for freeto 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

3 participants

@petercr@NiallJoeMaher@JohnAllenTech
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

UI Tests for username change on /settings page. - #1203

Closed
petercr wants to merge 9 commits into
codu-code:developfrom
petercr:develop
Closed

UI Tests for username change on /settings page.#1203
petercr wants to merge 9 commits into
codu-code:developfrom
petercr:develop

Conversation

@petercr

Copy link
Copy Markdown
Contributor

✨ Codu Pull Request 💻

Fixes#1168
** Only Part 3.**

Pull Request details

Added UI tests for /settings to:

  • tests for input field & types
  • tries to submit a bad user name
  • checks for error visibility
  • resets the form
  • changes user name, saves, and checks for update

Any Breaking changes

None

Associated Screenshots

None, but the tests pass 😅 I promise!

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

Like this, only instead of Monday, Wed, Friday it's like start, middle, end 😆
A dog that starts out grumpy, then get glad, then gets happy.

@petercr
petercr requested a review from a team as a code ownerOctober 31, 2024 23:33
@vercel

vercelBot commented Oct 31, 2024

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitaiBot commented Oct 31, 2024

Copy link
Copy Markdown
Contributor

Walkthrough

The changes in this pull request enhance the end-to-end test suite for the authenticated settings page by adding a new test case focused on the username input field. The modifications include updating the import statements and implementing a series of assertions that validate the visibility, attributes, and functionality of the username input, including error handling for invalid inputs and confirmation of valid submissions.

Changes

FileChange Summary
e2e/settings.spec.tsUpdated import statements; added a new test case for username input validation, including checks for visibility, attributes, error messages, and form reset functionality.
app/(app)/settings/_client.tsxEnhanced toast notifications for success and error handling during settings save operations by adding custom class names.
e2e/setup.tsUpdated bio property in userData with a grammatical error; changed websiteUrl from a relative to an absolute URL.

Assessment against linked issues

ObjectiveAddressedExplanation
Add E2E tests for the username field (1168)
Ensure tests are standalone and focused (1168)
Validate input fields against Zod schema (1168)No explicit validation against Zod schema shown.
Cover edge cases for username input (1168)

Possibly related PRs

  • Fix/e2e tests #1061: This PR focuses on fixing and stabilizing end-to-end tests, which may relate to the enhancements made in the main PR for the settings page tests, as both involve improving test coverage and reliability.
  • fix: update e2e tests for newer changes in site #1085: This PR updates E2E tests, including modifications to the homepage tests, which may share similar testing strategies or structures with the new tests added for the settings page.
  • Feat/improving existing e2e tests #1125: This PR improves existing E2E tests, which could be relevant as it aims to enhance the overall testing framework, similar to the enhancements made in the main PR for the settings page.
  • feat: adding e2e test for article commenting #1158: This PR adds tests for commenting functionality, which may share testing principles with the username input validation in the settings tests, focusing on user input and feedback.
  • Isolating E2E test suite from seed script #1192: The isolation of the E2E test suite from the seed script may impact how tests are structured, potentially relating to the main PR's enhancements in testing.

Suggested labels

hacktoberfest-accepted, hacktoberfest

Suggested reviewers

  • NiallJoeMaher

🐰 In the land of code, where rabbits hop,
A test was added, and we won't stop!
For usernames bright, we check and we see,
Valid or not, they must be error-free!
With each little change, our coverage grows,
Hopping through tests, as the confidence flows! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fcd1dbb and c6949d0.

📒 Files selected for processing (1)
  • e2e/setup.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • e2e/setup.ts

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.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

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

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

Line range hint 4-7: Implement missing unauthenticated tests

The PR objectives mention testing unauthenticated user redirection to /get-started, but this test is missing.

Would you like me to provide an implementation for the unauthenticated test case that verifies redirection?

Comment threade2e/settings.spec.ts Outdated
Comment on lines +14 to +16
// Test for changing username
test('Username input field', async ({ page }) => {
await page.goto('http://localhost:3000/settings', { timeout: 30000 });

@coderabbitaicoderabbitaiBotOct 31, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve test configuration and navigation

Consider these improvements:

  1. The 30-second timeout seems excessive for local development
  2. The hardcoded URL should be replaced with a configurable base URL
- await page.goto('http://localhost:3000/settings', { timeout: 30000 });+ await page.goto('/settings');

Add this to your playwright.config.ts:

use: {baseURL: process.env.BASE_URL||'http://localhost:3000',}

Copy link
Copy Markdown
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!

Comment threade2e/settings.spec.ts Outdated
Comment threade2e/settings.spec.ts Outdated
Comment threade2e/settings.spec.ts
import { test, expect } from "@playwright/test";
import { loggedInAsUserOne } from "./utils";

test.describe("Unauthenticated setttings Page", () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we change this to authenticated settings page. Because the user is authenticated for these tests

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'm not sure exactly what you're saying here?

Did you want a separate file for auth vs. un-auth tests, because doesn't a user have to be logged in to edit their profile?

I guess I could use more detail on this 👌🏻

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Your new test is ran inside a test suite called 'Unauthenticated setttings Page'

But this is an authenticated test because users need to login to change their username.

If you just change the name of the test it will be fixed

Comment threade2e/settings.spec.ts Outdated
// Test that the input field can be filled with a valid value and saves it
await inputField.fill('codu-rules');
await page.locator('button[type="submit"]').click();
await expect(inputField).toHaveValue('codu-rules');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Will this wait for the username change to take effect?

If you fill in the new username and then click submit.

Will this test see the new username you have entered as the value of the input and complete straight away?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I mean the tests pass for it. But it could be just catching the still filled in form from before the reset.

Would you like me to change it to a page refresh instead?

Or would you like some kind of timeOut in-between the state change and checking for the change to persist?

I would be happy to add either one 👍🏻

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah I am not sure is there a loading indicator for these types of change? It would be nice to see

  1. Click submit
  2. Loading indicator appears
  3. Loading indicator hidden
  4. Check new username has taken effect

@JohnAllenTechJohnAllenTech left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just made some general comments. I am not a maintainer here so everything is just a suggestion

@NiallJoeMaher

Copy link
Copy Markdown
Contributor

@JohnAllenTech let me know when this is good to go since you are the overlord of tests.

@petercr

Copy link
Copy Markdown
ContributorAuthor

@JohnAllenTech I made some changes and added the extra tests you had suggested.
Tests now cover:

  • waiting for toast to show
  • waiting for toast to disappear
  • full page refresh
  • checking new value persists in input field

I did have to change a field in /e2e/setup/setup.ts to add https:// to it.
Otherwise you get an error on the form in E2E testing.

I also added new class names to both the toast messages for UI testing.

Thanks

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

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

Line range hint 4-8: Fix typo and remove empty test suite.

  1. Fix the typo in "setttings" (three 't's).
  2. The empty test suite for unauthenticated users should either be implemented or removed to maintain clean code.
-test.describe("Unauthenticated setttings Page", () => {- //- // Replace with tests for unauthenticated users-});+// TODO: Implement tests for unauthenticated users being redirected to /get-started+test.describe("Unauthenticated settings Page", () => {+ test("redirects to get-started page", async ({ page }) => {+ await page.goto("/settings");+ await expect(page).toHaveURL("/get-started");+ });+});

27-32: Improve error message validation.

The error message validation could be more robust by:

  1. Using data-testid for reliable selection
  2. Centralizing error messages
  3. Verifying error styling
+ // Define error messages+ const ERROR_MESSAGES = {+ INVALID_CHARS: 'Username can only contain alphanumerics and dashes.'+ } as const;+- const errorMessage = page.locator('p:text-is("Username can only contain alphanumerics and dashes.")')+ const errorMessage = page.locator('[data-testid="username-error"]');
await expect(errorMessage).toBeVisible();
- await expect(errorMessage).toHaveText('Username can only contain alphanumerics and dashes.');+ await expect(errorMessage).toHaveText(ERROR_MESSAGES.INVALID_CHARS);+ await expect(errorMessage).toHaveCSS('color', 'rgb(220, 38, 38)'); // Verify error styling
e2e/setup.ts (1)

123-123: Document the reason for URL format change.

While the change to use an absolute URL is sensible, it would be helpful to document why this change was necessary, especially since it seems tangential to the main PR objective of testing username changes.

Add a comment explaining the URL format requirement:

+ // Using absolute URL to comply with website URL validation requirements
websiteUrl: "https://codu.co",
app/(app)/settings/_client.tsx (2)

Line range hint 261-276: Consider adding a loading indicator during username validation.

While the username field implementation is solid, it could benefit from a visual indicator during validation to improve user experience. This would be particularly useful when checking for username availability.

Consider adding a loading state:

 <Field>
<Input
id="username"
type="text"
autoComplete="username"
invalid={!!errors?.username}
+ className={isValidating ? "opacity-50" : ""}
{...register("username")}
/>
+ {isValidating && (+ <div className="mt-2 flex items-center text-sm text-gray-500">+ <Loader2 className="mr-2 h-4 w-4 animate-spin" />+ Checking username availability...+ </div>+ )}
{errors?.username && (
<ErrorMessage>{errors.username.message}</ErrorMessage>
)}
</Field>

Line range hint 1-458: Consider breaking down the Settings component for better maintainability.

The component is well-structured but handles multiple responsibilities. Consider splitting it into smaller, focused components for better maintainability and testing.

Suggested structure:

  1. Create separate components for each section:

    • ProfilePhotoSection
    • PersonalInfoSection (name, username, bio)
    • ContactSection (location, website)
    • EmailSection
    • NotificationsSection
  2. Move the file upload logic to a custom hook:

    // hooks/useProfilePhotoUpload.tsconstuseProfilePhotoUpload=()=>{const[profilePhoto,setProfilePhoto]=useState<ProfilePhoto>({...});// ... file upload logicreturn{ profilePhoto, handleImageChange };};

This refactoring would:

  • Improve code organization
  • Make testing easier
  • Reduce cognitive load when maintaining the component
  • Allow for better error boundary placement
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e6883a5 and f9140cf.

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

43-45: Verify username persistence more thoroughly.

The current persistence check could be enhanced by:

  1. Verifying the username in the UI header/profile
  2. Checking the API response
  3. Testing persistence across multiple page navigations
✅ Verification successful

Current username persistence testing is sufficient

The current e2e test adequately verifies username persistence because:

  1. The username is properly integrated throughout the application (Nav, BioBar, Settings)
  2. The page reload test verifies server-side persistence
  3. Additional UI checks would be redundant as the username update automatically propagates through the layout and components

The implementation shows the username is:

  • Stored in the database and fetched server-side (layout.tsx)
  • Consistently displayed across navigation and profile components
  • Properly validated and persisted in settings
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash# Description: Verify username persistence across the application# Note: This script helps identify places where the username should be updated# Find files that might display or use the usernameecho"Files potentially using username:"
rg -l "username" --type=tsx --type=ts
# Find API endpoints handling usernameecho"\nAPI endpoints for username:"
rg -l "username.*api" --type=ts

Length of output: 245


Script:

#!/bin/bash# Let's try a different approach to find username-related code# Search for username-related patterns in all filesecho"Files containing username-related patterns:"
rg -l -i "username|user.*name"# Look for settings or profile-related componentsecho -e "\nSettings and profile-related files:"
fd -e ts -e tsx -e js -e jsx "settings|profile" --type f
# Search for API calls or endpointsecho -e "\nAPI-related patterns:"
rg -l "api.*username|username.*api"# Look specifically in the e2e test file to understand the context betterecho -e "\nContext from the e2e test file:"
rg -C 5 "username""e2e/settings.spec.ts"

Length of output: 3690


Script:

#!/bin/bash# Let's examine the settings page implementation and username persistence logic# Check settings page implementationecho"Settings page implementation:"
rg -C 10 "username""app/(app)/settings/_client.tsx"# Check username usage in layout and navigationecho -e "\nUsername usage in layout:"
rg -C 5 "username""app/(app)/layout.tsx"# Check profile/bio components that might display usernameecho -e "\nUsername display in BioBar:"
rg -C 5 "username""components/BioBar/BioBar.tsx"# Check navigation components for username displayecho -e "\nUsername in navigation:"
rg -C 5 "username""components/Nav/Nav.tsx"

Length of output: 4555

e2e/setup.ts (1)

123-123: Verify URL format change impact on tests.

The change from relative URL "codu.co" to absolute URL "https://codu.co" looks good, but let's ensure this aligns with the validation requirements.

Let's verify the URL validation requirements:

✅ Verification successful

URL format change aligns with schema requirements

The change from "codu.co" to "https://codu.co" is correct as the websiteUrl field in schema/profile.ts uses Zod's .url() validator, which requires a fully qualified URL with protocol. This validation would reject the previous "codu.co" format.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash# Description: Check URL validation schema and related tests# Look for URL validation schema
rg -A 5 'websiteUrl.*zod'# Look for website URL related tests
rg -A 5 'websiteUrl.*test'

Length of output: 56


Script:

#!/bin/bash# Let's try a broader search for URL validation patterns and website-related schemas# Search for any URL validation patterns
rg -i "url.*validation|validate.*url" -A 5
# Search for website URL usage in tests
rg "website.*url|url.*website" -A 5
# Search for zod schema definitions that might include URL
rg "z\.string\(\).*url|url.*z\.string" -A 5
# Look for any URL-related constants or configurations
rg "URL_PATTERN|URL_REGEX" -A 5

Length of output: 2168

app/(app)/settings/_client.tsx (1)

89-94: LGTM: Toast styling changes are clean and consistent.

The addition of className props to toast notifications provides better styling control while maintaining the existing functionality.

Comment threade2e/settings.spec.ts Outdated
Comment threade2e/settings.spec.ts Outdated
@JohnAllenTech

Copy link
Copy Markdown
Contributor

@JohnAllenTech I made some changes and added the extra tests you had suggested.

Tests now cover:

  • waiting for toast to show

  • waiting for toast to disappear

  • full page refresh

  • checking new value persists in input field

I did have to change a field in /e2e/setup/setup.ts to add https:// to it.

Otherwise you get an error on the form in E2E testing.

I also added new class names to both the toast messages for UI testing.

Thanks

Hey @petercr apologies I was AFK for a few days. I'll take a look at this in a while and reply properly

@NiallJoeMaher

Copy link
Copy Markdown
Contributor

Tests failing here.

@petercr

Copy link
Copy Markdown
ContributorAuthor

Well crap 😕 that's no good.
I will look into this over the weekend (next 2 days) and see if I can figure it out. 👌🏻

I wonder if this has to do with the newsletter sub function?
Either way I'm on it 👍🏻

@petercr

Copy link
Copy Markdown
ContributorAuthor

When I run the test locally, they all pass 🤷🏼‍♂️ see pic below.
I'm not sure but this may have to do with /server/lib/newsletter.ts.

I added extra code on line 39 to keep from getting the email API errors for the newsletter.
You can see some controller errors from posts.sidebarData and the tRPC error for profile.edit.

Here's what I added locally for this:

if(process.env.ENV==="local"||"development"){returntrue;}

But it might be simpler to go with:

if(process.env.ENV!=="production"){returntrue;}

Here is the image of the tests passing.

msrdc_ttyjHMMI1j

Sign up for freeto 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

3 participants

@petercr@NiallJoeMaher@JohnAllenTech
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

UI Tests for username change on /settings page. - #1203

Closed
petercr wants to merge 9 commits into
codu-code:developfrom
petercr:develop
Closed

UI Tests for username change on /settings page.#1203
petercr wants to merge 9 commits into
codu-code:developfrom
petercr:develop

Conversation

@petercr

Copy link
Copy Markdown
Contributor

✨ Codu Pull Request 💻

Fixes#1168
** Only Part 3.**

Pull Request details

Added UI tests for /settings to:

  • tests for input field & types
  • tries to submit a bad user name
  • checks for error visibility
  • resets the form
  • changes user name, saves, and checks for update

Any Breaking changes

None

Associated Screenshots

None, but the tests pass 😅 I promise!

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

Like this, only instead of Monday, Wed, Friday it's like start, middle, end 😆
A dog that starts out grumpy, then get glad, then gets happy.

@petercr
petercr requested a review from a team as a code ownerOctober 31, 2024 23:33
@vercel

vercelBot commented Oct 31, 2024

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitaiBot commented Oct 31, 2024

Copy link
Copy Markdown
Contributor

Walkthrough

The changes in this pull request enhance the end-to-end test suite for the authenticated settings page by adding a new test case focused on the username input field. The modifications include updating the import statements and implementing a series of assertions that validate the visibility, attributes, and functionality of the username input, including error handling for invalid inputs and confirmation of valid submissions.

Changes

FileChange Summary
e2e/settings.spec.tsUpdated import statements; added a new test case for username input validation, including checks for visibility, attributes, error messages, and form reset functionality.
app/(app)/settings/_client.tsxEnhanced toast notifications for success and error handling during settings save operations by adding custom class names.
e2e/setup.tsUpdated bio property in userData with a grammatical error; changed websiteUrl from a relative to an absolute URL.

Assessment against linked issues

ObjectiveAddressedExplanation
Add E2E tests for the username field (1168)
Ensure tests are standalone and focused (1168)
Validate input fields against Zod schema (1168)No explicit validation against Zod schema shown.
Cover edge cases for username input (1168)

Possibly related PRs

  • Fix/e2e tests #1061: This PR focuses on fixing and stabilizing end-to-end tests, which may relate to the enhancements made in the main PR for the settings page tests, as both involve improving test coverage and reliability.
  • fix: update e2e tests for newer changes in site #1085: This PR updates E2E tests, including modifications to the homepage tests, which may share similar testing strategies or structures with the new tests added for the settings page.
  • Feat/improving existing e2e tests #1125: This PR improves existing E2E tests, which could be relevant as it aims to enhance the overall testing framework, similar to the enhancements made in the main PR for the settings page.
  • feat: adding e2e test for article commenting #1158: This PR adds tests for commenting functionality, which may share testing principles with the username input validation in the settings tests, focusing on user input and feedback.
  • Isolating E2E test suite from seed script #1192: The isolation of the E2E test suite from the seed script may impact how tests are structured, potentially relating to the main PR's enhancements in testing.

Suggested labels

hacktoberfest-accepted, hacktoberfest

Suggested reviewers

  • NiallJoeMaher

🐰 In the land of code, where rabbits hop,
A test was added, and we won't stop!
For usernames bright, we check and we see,
Valid or not, they must be error-free!
With each little change, our coverage grows,
Hopping through tests, as the confidence flows! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fcd1dbb and c6949d0.

📒 Files selected for processing (1)
  • e2e/setup.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • e2e/setup.ts

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.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

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

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

Line range hint 4-7: Implement missing unauthenticated tests

The PR objectives mention testing unauthenticated user redirection to /get-started, but this test is missing.

Would you like me to provide an implementation for the unauthenticated test case that verifies redirection?

Comment threade2e/settings.spec.ts Outdated
Comment on lines +14 to +16
// Test for changing username
test('Username input field', async ({ page }) => {
await page.goto('http://localhost:3000/settings', { timeout: 30000 });

@coderabbitaicoderabbitaiBotOct 31, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve test configuration and navigation

Consider these improvements:

  1. The 30-second timeout seems excessive for local development
  2. The hardcoded URL should be replaced with a configurable base URL
- await page.goto('http://localhost:3000/settings', { timeout: 30000 });+ await page.goto('/settings');

Add this to your playwright.config.ts:

use: {baseURL: process.env.BASE_URL||'http://localhost:3000',}

Copy link
Copy Markdown
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!

Comment threade2e/settings.spec.ts Outdated
Comment threade2e/settings.spec.ts Outdated
Comment threade2e/settings.spec.ts
import { test, expect } from "@playwright/test";
import { loggedInAsUserOne } from "./utils";

test.describe("Unauthenticated setttings Page", () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we change this to authenticated settings page. Because the user is authenticated for these tests

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'm not sure exactly what you're saying here?

Did you want a separate file for auth vs. un-auth tests, because doesn't a user have to be logged in to edit their profile?

I guess I could use more detail on this 👌🏻

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Your new test is ran inside a test suite called 'Unauthenticated setttings Page'

But this is an authenticated test because users need to login to change their username.

If you just change the name of the test it will be fixed

Comment threade2e/settings.spec.ts Outdated
// Test that the input field can be filled with a valid value and saves it
await inputField.fill('codu-rules');
await page.locator('button[type="submit"]').click();
await expect(inputField).toHaveValue('codu-rules');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Will this wait for the username change to take effect?

If you fill in the new username and then click submit.

Will this test see the new username you have entered as the value of the input and complete straight away?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I mean the tests pass for it. But it could be just catching the still filled in form from before the reset.

Would you like me to change it to a page refresh instead?

Or would you like some kind of timeOut in-between the state change and checking for the change to persist?

I would be happy to add either one 👍🏻

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah I am not sure is there a loading indicator for these types of change? It would be nice to see

  1. Click submit
  2. Loading indicator appears
  3. Loading indicator hidden
  4. Check new username has taken effect

@JohnAllenTechJohnAllenTech left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just made some general comments. I am not a maintainer here so everything is just a suggestion

@NiallJoeMaher

Copy link
Copy Markdown
Contributor

@JohnAllenTech let me know when this is good to go since you are the overlord of tests.

@petercr

Copy link
Copy Markdown
ContributorAuthor

@JohnAllenTech I made some changes and added the extra tests you had suggested.
Tests now cover:

  • waiting for toast to show
  • waiting for toast to disappear
  • full page refresh
  • checking new value persists in input field

I did have to change a field in /e2e/setup/setup.ts to add https:// to it.
Otherwise you get an error on the form in E2E testing.

I also added new class names to both the toast messages for UI testing.

Thanks

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

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

Line range hint 4-8: Fix typo and remove empty test suite.

  1. Fix the typo in "setttings" (three 't's).
  2. The empty test suite for unauthenticated users should either be implemented or removed to maintain clean code.
-test.describe("Unauthenticated setttings Page", () => {- //- // Replace with tests for unauthenticated users-});+// TODO: Implement tests for unauthenticated users being redirected to /get-started+test.describe("Unauthenticated settings Page", () => {+ test("redirects to get-started page", async ({ page }) => {+ await page.goto("/settings");+ await expect(page).toHaveURL("/get-started");+ });+});

27-32: Improve error message validation.

The error message validation could be more robust by:

  1. Using data-testid for reliable selection
  2. Centralizing error messages
  3. Verifying error styling
+ // Define error messages+ const ERROR_MESSAGES = {+ INVALID_CHARS: 'Username can only contain alphanumerics and dashes.'+ } as const;+- const errorMessage = page.locator('p:text-is("Username can only contain alphanumerics and dashes.")')+ const errorMessage = page.locator('[data-testid="username-error"]');
await expect(errorMessage).toBeVisible();
- await expect(errorMessage).toHaveText('Username can only contain alphanumerics and dashes.');+ await expect(errorMessage).toHaveText(ERROR_MESSAGES.INVALID_CHARS);+ await expect(errorMessage).toHaveCSS('color', 'rgb(220, 38, 38)'); // Verify error styling
e2e/setup.ts (1)

123-123: Document the reason for URL format change.

While the change to use an absolute URL is sensible, it would be helpful to document why this change was necessary, especially since it seems tangential to the main PR objective of testing username changes.

Add a comment explaining the URL format requirement:

+ // Using absolute URL to comply with website URL validation requirements
websiteUrl: "https://codu.co",
app/(app)/settings/_client.tsx (2)

Line range hint 261-276: Consider adding a loading indicator during username validation.

While the username field implementation is solid, it could benefit from a visual indicator during validation to improve user experience. This would be particularly useful when checking for username availability.

Consider adding a loading state:

 <Field>
<Input
id="username"
type="text"
autoComplete="username"
invalid={!!errors?.username}
+ className={isValidating ? "opacity-50" : ""}
{...register("username")}
/>
+ {isValidating && (+ <div className="mt-2 flex items-center text-sm text-gray-500">+ <Loader2 className="mr-2 h-4 w-4 animate-spin" />+ Checking username availability...+ </div>+ )}
{errors?.username && (
<ErrorMessage>{errors.username.message}</ErrorMessage>
)}
</Field>

Line range hint 1-458: Consider breaking down the Settings component for better maintainability.

The component is well-structured but handles multiple responsibilities. Consider splitting it into smaller, focused components for better maintainability and testing.

Suggested structure:

  1. Create separate components for each section:

    • ProfilePhotoSection
    • PersonalInfoSection (name, username, bio)
    • ContactSection (location, website)
    • EmailSection
    • NotificationsSection
  2. Move the file upload logic to a custom hook:

    // hooks/useProfilePhotoUpload.tsconstuseProfilePhotoUpload=()=>{const[profilePhoto,setProfilePhoto]=useState<ProfilePhoto>({...});// ... file upload logicreturn{ profilePhoto, handleImageChange };};

This refactoring would:

  • Improve code organization
  • Make testing easier
  • Reduce cognitive load when maintaining the component
  • Allow for better error boundary placement
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e6883a5 and f9140cf.

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

43-45: Verify username persistence more thoroughly.

The current persistence check could be enhanced by:

  1. Verifying the username in the UI header/profile
  2. Checking the API response
  3. Testing persistence across multiple page navigations
✅ Verification successful

Current username persistence testing is sufficient

The current e2e test adequately verifies username persistence because:

  1. The username is properly integrated throughout the application (Nav, BioBar, Settings)
  2. The page reload test verifies server-side persistence
  3. Additional UI checks would be redundant as the username update automatically propagates through the layout and components

The implementation shows the username is:

  • Stored in the database and fetched server-side (layout.tsx)
  • Consistently displayed across navigation and profile components
  • Properly validated and persisted in settings
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash# Description: Verify username persistence across the application# Note: This script helps identify places where the username should be updated# Find files that might display or use the usernameecho"Files potentially using username:"
rg -l "username" --type=tsx --type=ts
# Find API endpoints handling usernameecho"\nAPI endpoints for username:"
rg -l "username.*api" --type=ts

Length of output: 245


Script:

#!/bin/bash# Let's try a different approach to find username-related code# Search for username-related patterns in all filesecho"Files containing username-related patterns:"
rg -l -i "username|user.*name"# Look for settings or profile-related componentsecho -e "\nSettings and profile-related files:"
fd -e ts -e tsx -e js -e jsx "settings|profile" --type f
# Search for API calls or endpointsecho -e "\nAPI-related patterns:"
rg -l "api.*username|username.*api"# Look specifically in the e2e test file to understand the context betterecho -e "\nContext from the e2e test file:"
rg -C 5 "username""e2e/settings.spec.ts"

Length of output: 3690


Script:

#!/bin/bash# Let's examine the settings page implementation and username persistence logic# Check settings page implementationecho"Settings page implementation:"
rg -C 10 "username""app/(app)/settings/_client.tsx"# Check username usage in layout and navigationecho -e "\nUsername usage in layout:"
rg -C 5 "username""app/(app)/layout.tsx"# Check profile/bio components that might display usernameecho -e "\nUsername display in BioBar:"
rg -C 5 "username""components/BioBar/BioBar.tsx"# Check navigation components for username displayecho -e "\nUsername in navigation:"
rg -C 5 "username""components/Nav/Nav.tsx"

Length of output: 4555

e2e/setup.ts (1)

123-123: Verify URL format change impact on tests.

The change from relative URL "codu.co" to absolute URL "https://codu.co" looks good, but let's ensure this aligns with the validation requirements.

Let's verify the URL validation requirements:

✅ Verification successful

URL format change aligns with schema requirements

The change from "codu.co" to "https://codu.co" is correct as the websiteUrl field in schema/profile.ts uses Zod's .url() validator, which requires a fully qualified URL with protocol. This validation would reject the previous "codu.co" format.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash# Description: Check URL validation schema and related tests# Look for URL validation schema
rg -A 5 'websiteUrl.*zod'# Look for website URL related tests
rg -A 5 'websiteUrl.*test'

Length of output: 56


Script:

#!/bin/bash# Let's try a broader search for URL validation patterns and website-related schemas# Search for any URL validation patterns
rg -i "url.*validation|validate.*url" -A 5
# Search for website URL usage in tests
rg "website.*url|url.*website" -A 5
# Search for zod schema definitions that might include URL
rg "z\.string\(\).*url|url.*z\.string" -A 5
# Look for any URL-related constants or configurations
rg "URL_PATTERN|URL_REGEX" -A 5

Length of output: 2168

app/(app)/settings/_client.tsx (1)

89-94: LGTM: Toast styling changes are clean and consistent.

The addition of className props to toast notifications provides better styling control while maintaining the existing functionality.

Comment threade2e/settings.spec.ts Outdated
Comment threade2e/settings.spec.ts Outdated
@JohnAllenTech

Copy link
Copy Markdown
Contributor

@JohnAllenTech I made some changes and added the extra tests you had suggested.

Tests now cover:

  • waiting for toast to show

  • waiting for toast to disappear

  • full page refresh

  • checking new value persists in input field

I did have to change a field in /e2e/setup/setup.ts to add https:// to it.

Otherwise you get an error on the form in E2E testing.

I also added new class names to both the toast messages for UI testing.

Thanks

Hey @petercr apologies I was AFK for a few days. I'll take a look at this in a while and reply properly

@NiallJoeMaher

Copy link
Copy Markdown
Contributor

Tests failing here.

@petercr

Copy link
Copy Markdown
ContributorAuthor

Well crap 😕 that's no good.
I will look into this over the weekend (next 2 days) and see if I can figure it out. 👌🏻

I wonder if this has to do with the newsletter sub function?
Either way I'm on it 👍🏻

@petercr

Copy link
Copy Markdown
ContributorAuthor

When I run the test locally, they all pass 🤷🏼‍♂️ see pic below.
I'm not sure but this may have to do with /server/lib/newsletter.ts.

I added extra code on line 39 to keep from getting the email API errors for the newsletter.
You can see some controller errors from posts.sidebarData and the tRPC error for profile.edit.

Here's what I added locally for this:

if(process.env.ENV==="local"||"development"){returntrue;}

But it might be simpler to go with:

if(process.env.ENV!=="production"){returntrue;}

Here is the image of the tests passing.

msrdc_ttyjHMMI1j

Sign up for freeto 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

3 participants

@petercr@NiallJoeMaher@JohnAllenTech
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

UI Tests for username change on /settings page. - #1203

Closed
petercr wants to merge 9 commits into
codu-code:developfrom
petercr:develop
Closed

UI Tests for username change on /settings page.#1203
petercr wants to merge 9 commits into
codu-code:developfrom
petercr:develop

Conversation

@petercr

Copy link
Copy Markdown
Contributor

✨ Codu Pull Request 💻

Fixes#1168
** Only Part 3.**

Pull Request details

Added UI tests for /settings to:

  • tests for input field & types
  • tries to submit a bad user name
  • checks for error visibility
  • resets the form
  • changes user name, saves, and checks for update

Any Breaking changes

None

Associated Screenshots

None, but the tests pass 😅 I promise!

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

Like this, only instead of Monday, Wed, Friday it's like start, middle, end 😆
A dog that starts out grumpy, then get glad, then gets happy.

@petercr
petercr requested a review from a team as a code ownerOctober 31, 2024 23:33
@vercel

vercelBot commented Oct 31, 2024

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitaiBot commented Oct 31, 2024

Copy link
Copy Markdown
Contributor

Walkthrough

The changes in this pull request enhance the end-to-end test suite for the authenticated settings page by adding a new test case focused on the username input field. The modifications include updating the import statements and implementing a series of assertions that validate the visibility, attributes, and functionality of the username input, including error handling for invalid inputs and confirmation of valid submissions.

Changes

FileChange Summary
e2e/settings.spec.tsUpdated import statements; added a new test case for username input validation, including checks for visibility, attributes, error messages, and form reset functionality.
app/(app)/settings/_client.tsxEnhanced toast notifications for success and error handling during settings save operations by adding custom class names.
e2e/setup.tsUpdated bio property in userData with a grammatical error; changed websiteUrl from a relative to an absolute URL.

Assessment against linked issues

ObjectiveAddressedExplanation
Add E2E tests for the username field (1168)
Ensure tests are standalone and focused (1168)
Validate input fields against Zod schema (1168)No explicit validation against Zod schema shown.
Cover edge cases for username input (1168)

Possibly related PRs

  • Fix/e2e tests #1061: This PR focuses on fixing and stabilizing end-to-end tests, which may relate to the enhancements made in the main PR for the settings page tests, as both involve improving test coverage and reliability.
  • fix: update e2e tests for newer changes in site #1085: This PR updates E2E tests, including modifications to the homepage tests, which may share similar testing strategies or structures with the new tests added for the settings page.
  • Feat/improving existing e2e tests #1125: This PR improves existing E2E tests, which could be relevant as it aims to enhance the overall testing framework, similar to the enhancements made in the main PR for the settings page.
  • feat: adding e2e test for article commenting #1158: This PR adds tests for commenting functionality, which may share testing principles with the username input validation in the settings tests, focusing on user input and feedback.
  • Isolating E2E test suite from seed script #1192: The isolation of the E2E test suite from the seed script may impact how tests are structured, potentially relating to the main PR's enhancements in testing.

Suggested labels

hacktoberfest-accepted, hacktoberfest

Suggested reviewers

  • NiallJoeMaher

🐰 In the land of code, where rabbits hop,
A test was added, and we won't stop!
For usernames bright, we check and we see,
Valid or not, they must be error-free!
With each little change, our coverage grows,
Hopping through tests, as the confidence flows! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fcd1dbb and c6949d0.

📒 Files selected for processing (1)
  • e2e/setup.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • e2e/setup.ts

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.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

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

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

Line range hint 4-7: Implement missing unauthenticated tests

The PR objectives mention testing unauthenticated user redirection to /get-started, but this test is missing.

Would you like me to provide an implementation for the unauthenticated test case that verifies redirection?

Comment threade2e/settings.spec.ts Outdated
Comment on lines +14 to +16
// Test for changing username
test('Username input field', async ({ page }) => {
await page.goto('http://localhost:3000/settings', { timeout: 30000 });

@coderabbitaicoderabbitaiBotOct 31, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve test configuration and navigation

Consider these improvements:

  1. The 30-second timeout seems excessive for local development
  2. The hardcoded URL should be replaced with a configurable base URL
- await page.goto('http://localhost:3000/settings', { timeout: 30000 });+ await page.goto('/settings');

Add this to your playwright.config.ts:

use: {baseURL: process.env.BASE_URL||'http://localhost:3000',}

Copy link
Copy Markdown
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!

Comment threade2e/settings.spec.ts Outdated
Comment threade2e/settings.spec.ts Outdated
Comment threade2e/settings.spec.ts
import { test, expect } from "@playwright/test";
import { loggedInAsUserOne } from "./utils";

test.describe("Unauthenticated setttings Page", () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we change this to authenticated settings page. Because the user is authenticated for these tests

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'm not sure exactly what you're saying here?

Did you want a separate file for auth vs. un-auth tests, because doesn't a user have to be logged in to edit their profile?

I guess I could use more detail on this 👌🏻

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Your new test is ran inside a test suite called 'Unauthenticated setttings Page'

But this is an authenticated test because users need to login to change their username.

If you just change the name of the test it will be fixed

Comment threade2e/settings.spec.ts Outdated
// Test that the input field can be filled with a valid value and saves it
await inputField.fill('codu-rules');
await page.locator('button[type="submit"]').click();
await expect(inputField).toHaveValue('codu-rules');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Will this wait for the username change to take effect?

If you fill in the new username and then click submit.

Will this test see the new username you have entered as the value of the input and complete straight away?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I mean the tests pass for it. But it could be just catching the still filled in form from before the reset.

Would you like me to change it to a page refresh instead?

Or would you like some kind of timeOut in-between the state change and checking for the change to persist?

I would be happy to add either one 👍🏻

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah I am not sure is there a loading indicator for these types of change? It would be nice to see

  1. Click submit
  2. Loading indicator appears
  3. Loading indicator hidden
  4. Check new username has taken effect

@JohnAllenTechJohnAllenTech left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just made some general comments. I am not a maintainer here so everything is just a suggestion

@NiallJoeMaher

Copy link
Copy Markdown
Contributor

@JohnAllenTech let me know when this is good to go since you are the overlord of tests.

@petercr

Copy link
Copy Markdown
ContributorAuthor

@JohnAllenTech I made some changes and added the extra tests you had suggested.
Tests now cover:

  • waiting for toast to show
  • waiting for toast to disappear
  • full page refresh
  • checking new value persists in input field

I did have to change a field in /e2e/setup/setup.ts to add https:// to it.
Otherwise you get an error on the form in E2E testing.

I also added new class names to both the toast messages for UI testing.

Thanks

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

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

Line range hint 4-8: Fix typo and remove empty test suite.

  1. Fix the typo in "setttings" (three 't's).
  2. The empty test suite for unauthenticated users should either be implemented or removed to maintain clean code.
-test.describe("Unauthenticated setttings Page", () => {- //- // Replace with tests for unauthenticated users-});+// TODO: Implement tests for unauthenticated users being redirected to /get-started+test.describe("Unauthenticated settings Page", () => {+ test("redirects to get-started page", async ({ page }) => {+ await page.goto("/settings");+ await expect(page).toHaveURL("/get-started");+ });+});

27-32: Improve error message validation.

The error message validation could be more robust by:

  1. Using data-testid for reliable selection
  2. Centralizing error messages
  3. Verifying error styling
+ // Define error messages+ const ERROR_MESSAGES = {+ INVALID_CHARS: 'Username can only contain alphanumerics and dashes.'+ } as const;+- const errorMessage = page.locator('p:text-is("Username can only contain alphanumerics and dashes.")')+ const errorMessage = page.locator('[data-testid="username-error"]');
await expect(errorMessage).toBeVisible();
- await expect(errorMessage).toHaveText('Username can only contain alphanumerics and dashes.');+ await expect(errorMessage).toHaveText(ERROR_MESSAGES.INVALID_CHARS);+ await expect(errorMessage).toHaveCSS('color', 'rgb(220, 38, 38)'); // Verify error styling
e2e/setup.ts (1)

123-123: Document the reason for URL format change.

While the change to use an absolute URL is sensible, it would be helpful to document why this change was necessary, especially since it seems tangential to the main PR objective of testing username changes.

Add a comment explaining the URL format requirement:

+ // Using absolute URL to comply with website URL validation requirements
websiteUrl: "https://codu.co",
app/(app)/settings/_client.tsx (2)

Line range hint 261-276: Consider adding a loading indicator during username validation.

While the username field implementation is solid, it could benefit from a visual indicator during validation to improve user experience. This would be particularly useful when checking for username availability.

Consider adding a loading state:

 <Field>
<Input
id="username"
type="text"
autoComplete="username"
invalid={!!errors?.username}
+ className={isValidating ? "opacity-50" : ""}
{...register("username")}
/>
+ {isValidating && (+ <div className="mt-2 flex items-center text-sm text-gray-500">+ <Loader2 className="mr-2 h-4 w-4 animate-spin" />+ Checking username availability...+ </div>+ )}
{errors?.username && (
<ErrorMessage>{errors.username.message}</ErrorMessage>
)}
</Field>

Line range hint 1-458: Consider breaking down the Settings component for better maintainability.

The component is well-structured but handles multiple responsibilities. Consider splitting it into smaller, focused components for better maintainability and testing.

Suggested structure:

  1. Create separate components for each section:

    • ProfilePhotoSection
    • PersonalInfoSection (name, username, bio)
    • ContactSection (location, website)
    • EmailSection
    • NotificationsSection
  2. Move the file upload logic to a custom hook:

    // hooks/useProfilePhotoUpload.tsconstuseProfilePhotoUpload=()=>{const[profilePhoto,setProfilePhoto]=useState<ProfilePhoto>({...});// ... file upload logicreturn{ profilePhoto, handleImageChange };};

This refactoring would:

  • Improve code organization
  • Make testing easier
  • Reduce cognitive load when maintaining the component
  • Allow for better error boundary placement
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e6883a5 and f9140cf.

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

43-45: Verify username persistence more thoroughly.

The current persistence check could be enhanced by:

  1. Verifying the username in the UI header/profile
  2. Checking the API response
  3. Testing persistence across multiple page navigations
✅ Verification successful

Current username persistence testing is sufficient

The current e2e test adequately verifies username persistence because:

  1. The username is properly integrated throughout the application (Nav, BioBar, Settings)
  2. The page reload test verifies server-side persistence
  3. Additional UI checks would be redundant as the username update automatically propagates through the layout and components

The implementation shows the username is:

  • Stored in the database and fetched server-side (layout.tsx)
  • Consistently displayed across navigation and profile components
  • Properly validated and persisted in settings
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash# Description: Verify username persistence across the application# Note: This script helps identify places where the username should be updated# Find files that might display or use the usernameecho"Files potentially using username:"
rg -l "username" --type=tsx --type=ts
# Find API endpoints handling usernameecho"\nAPI endpoints for username:"
rg -l "username.*api" --type=ts

Length of output: 245


Script:

#!/bin/bash# Let's try a different approach to find username-related code# Search for username-related patterns in all filesecho"Files containing username-related patterns:"
rg -l -i "username|user.*name"# Look for settings or profile-related componentsecho -e "\nSettings and profile-related files:"
fd -e ts -e tsx -e js -e jsx "settings|profile" --type f
# Search for API calls or endpointsecho -e "\nAPI-related patterns:"
rg -l "api.*username|username.*api"# Look specifically in the e2e test file to understand the context betterecho -e "\nContext from the e2e test file:"
rg -C 5 "username""e2e/settings.spec.ts"

Length of output: 3690


Script:

#!/bin/bash# Let's examine the settings page implementation and username persistence logic# Check settings page implementationecho"Settings page implementation:"
rg -C 10 "username""app/(app)/settings/_client.tsx"# Check username usage in layout and navigationecho -e "\nUsername usage in layout:"
rg -C 5 "username""app/(app)/layout.tsx"# Check profile/bio components that might display usernameecho -e "\nUsername display in BioBar:"
rg -C 5 "username""components/BioBar/BioBar.tsx"# Check navigation components for username displayecho -e "\nUsername in navigation:"
rg -C 5 "username""components/Nav/Nav.tsx"

Length of output: 4555

e2e/setup.ts (1)

123-123: Verify URL format change impact on tests.

The change from relative URL "codu.co" to absolute URL "https://codu.co" looks good, but let's ensure this aligns with the validation requirements.

Let's verify the URL validation requirements:

✅ Verification successful

URL format change aligns with schema requirements

The change from "codu.co" to "https://codu.co" is correct as the websiteUrl field in schema/profile.ts uses Zod's .url() validator, which requires a fully qualified URL with protocol. This validation would reject the previous "codu.co" format.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash# Description: Check URL validation schema and related tests# Look for URL validation schema
rg -A 5 'websiteUrl.*zod'# Look for website URL related tests
rg -A 5 'websiteUrl.*test'

Length of output: 56


Script:

#!/bin/bash# Let's try a broader search for URL validation patterns and website-related schemas# Search for any URL validation patterns
rg -i "url.*validation|validate.*url" -A 5
# Search for website URL usage in tests
rg "website.*url|url.*website" -A 5
# Search for zod schema definitions that might include URL
rg "z\.string\(\).*url|url.*z\.string" -A 5
# Look for any URL-related constants or configurations
rg "URL_PATTERN|URL_REGEX" -A 5

Length of output: 2168

app/(app)/settings/_client.tsx (1)

89-94: LGTM: Toast styling changes are clean and consistent.

The addition of className props to toast notifications provides better styling control while maintaining the existing functionality.

Comment threade2e/settings.spec.ts Outdated
Comment threade2e/settings.spec.ts Outdated
@JohnAllenTech

Copy link
Copy Markdown
Contributor

@JohnAllenTech I made some changes and added the extra tests you had suggested.

Tests now cover:

  • waiting for toast to show

  • waiting for toast to disappear

  • full page refresh

  • checking new value persists in input field

I did have to change a field in /e2e/setup/setup.ts to add https:// to it.

Otherwise you get an error on the form in E2E testing.

I also added new class names to both the toast messages for UI testing.

Thanks

Hey @petercr apologies I was AFK for a few days. I'll take a look at this in a while and reply properly

@NiallJoeMaher

Copy link
Copy Markdown
Contributor

Tests failing here.

@petercr

Copy link
Copy Markdown
ContributorAuthor

Well crap 😕 that's no good.
I will look into this over the weekend (next 2 days) and see if I can figure it out. 👌🏻

I wonder if this has to do with the newsletter sub function?
Either way I'm on it 👍🏻

@petercr

Copy link
Copy Markdown
ContributorAuthor

When I run the test locally, they all pass 🤷🏼‍♂️ see pic below.
I'm not sure but this may have to do with /server/lib/newsletter.ts.

I added extra code on line 39 to keep from getting the email API errors for the newsletter.
You can see some controller errors from posts.sidebarData and the tRPC error for profile.edit.

Here's what I added locally for this:

if(process.env.ENV==="local"||"development"){returntrue;}

But it might be simpler to go with:

if(process.env.ENV!=="production"){returntrue;}

Here is the image of the tests passing.

msrdc_ttyjHMMI1j

Sign up for freeto 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

3 participants

@petercr@NiallJoeMaher@JohnAllenTech
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

UI Tests for username change on /settings page. - #1203

Closed
petercr wants to merge 9 commits into
codu-code:developfrom
petercr:develop
Closed

UI Tests for username change on /settings page.#1203
petercr wants to merge 9 commits into
codu-code:developfrom
petercr:develop

Conversation

@petercr

Copy link
Copy Markdown
Contributor

✨ Codu Pull Request 💻

Fixes#1168
** Only Part 3.**

Pull Request details

Added UI tests for /settings to:

  • tests for input field & types
  • tries to submit a bad user name
  • checks for error visibility
  • resets the form
  • changes user name, saves, and checks for update

Any Breaking changes

None

Associated Screenshots

None, but the tests pass 😅 I promise!

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

Like this, only instead of Monday, Wed, Friday it's like start, middle, end 😆
A dog that starts out grumpy, then get glad, then gets happy.

@petercr
petercr requested a review from a team as a code ownerOctober 31, 2024 23:33
@vercel

vercelBot commented Oct 31, 2024

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitaiBot commented Oct 31, 2024

Copy link
Copy Markdown
Contributor

Walkthrough

The changes in this pull request enhance the end-to-end test suite for the authenticated settings page by adding a new test case focused on the username input field. The modifications include updating the import statements and implementing a series of assertions that validate the visibility, attributes, and functionality of the username input, including error handling for invalid inputs and confirmation of valid submissions.

Changes

FileChange Summary
e2e/settings.spec.tsUpdated import statements; added a new test case for username input validation, including checks for visibility, attributes, error messages, and form reset functionality.
app/(app)/settings/_client.tsxEnhanced toast notifications for success and error handling during settings save operations by adding custom class names.
e2e/setup.tsUpdated bio property in userData with a grammatical error; changed websiteUrl from a relative to an absolute URL.

Assessment against linked issues

ObjectiveAddressedExplanation
Add E2E tests for the username field (1168)
Ensure tests are standalone and focused (1168)
Validate input fields against Zod schema (1168)No explicit validation against Zod schema shown.
Cover edge cases for username input (1168)

Possibly related PRs

  • Fix/e2e tests #1061: This PR focuses on fixing and stabilizing end-to-end tests, which may relate to the enhancements made in the main PR for the settings page tests, as both involve improving test coverage and reliability.
  • fix: update e2e tests for newer changes in site #1085: This PR updates E2E tests, including modifications to the homepage tests, which may share similar testing strategies or structures with the new tests added for the settings page.
  • Feat/improving existing e2e tests #1125: This PR improves existing E2E tests, which could be relevant as it aims to enhance the overall testing framework, similar to the enhancements made in the main PR for the settings page.
  • feat: adding e2e test for article commenting #1158: This PR adds tests for commenting functionality, which may share testing principles with the username input validation in the settings tests, focusing on user input and feedback.
  • Isolating E2E test suite from seed script #1192: The isolation of the E2E test suite from the seed script may impact how tests are structured, potentially relating to the main PR's enhancements in testing.

Suggested labels

hacktoberfest-accepted, hacktoberfest

Suggested reviewers

  • NiallJoeMaher

🐰 In the land of code, where rabbits hop,
A test was added, and we won't stop!
For usernames bright, we check and we see,
Valid or not, they must be error-free!
With each little change, our coverage grows,
Hopping through tests, as the confidence flows! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fcd1dbb and c6949d0.

📒 Files selected for processing (1)
  • e2e/setup.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • e2e/setup.ts

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.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

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

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

Line range hint 4-7: Implement missing unauthenticated tests

The PR objectives mention testing unauthenticated user redirection to /get-started, but this test is missing.

Would you like me to provide an implementation for the unauthenticated test case that verifies redirection?

Comment threade2e/settings.spec.ts Outdated
Comment on lines +14 to +16
// Test for changing username
test('Username input field', async ({ page }) => {
await page.goto('http://localhost:3000/settings', { timeout: 30000 });

@coderabbitaicoderabbitaiBotOct 31, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve test configuration and navigation

Consider these improvements:

  1. The 30-second timeout seems excessive for local development
  2. The hardcoded URL should be replaced with a configurable base URL
- await page.goto('http://localhost:3000/settings', { timeout: 30000 });+ await page.goto('/settings');

Add this to your playwright.config.ts:

use: {baseURL: process.env.BASE_URL||'http://localhost:3000',}

Copy link
Copy Markdown
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!

Comment threade2e/settings.spec.ts Outdated
Comment threade2e/settings.spec.ts Outdated
Comment threade2e/settings.spec.ts
import { test, expect } from "@playwright/test";
import { loggedInAsUserOne } from "./utils";

test.describe("Unauthenticated setttings Page", () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we change this to authenticated settings page. Because the user is authenticated for these tests

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'm not sure exactly what you're saying here?

Did you want a separate file for auth vs. un-auth tests, because doesn't a user have to be logged in to edit their profile?

I guess I could use more detail on this 👌🏻

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Your new test is ran inside a test suite called 'Unauthenticated setttings Page'

But this is an authenticated test because users need to login to change their username.

If you just change the name of the test it will be fixed

Comment threade2e/settings.spec.ts Outdated
// Test that the input field can be filled with a valid value and saves it
await inputField.fill('codu-rules');
await page.locator('button[type="submit"]').click();
await expect(inputField).toHaveValue('codu-rules');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Will this wait for the username change to take effect?

If you fill in the new username and then click submit.

Will this test see the new username you have entered as the value of the input and complete straight away?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I mean the tests pass for it. But it could be just catching the still filled in form from before the reset.

Would you like me to change it to a page refresh instead?

Or would you like some kind of timeOut in-between the state change and checking for the change to persist?

I would be happy to add either one 👍🏻

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah I am not sure is there a loading indicator for these types of change? It would be nice to see

  1. Click submit
  2. Loading indicator appears
  3. Loading indicator hidden
  4. Check new username has taken effect

@JohnAllenTechJohnAllenTech left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just made some general comments. I am not a maintainer here so everything is just a suggestion

@NiallJoeMaher

Copy link
Copy Markdown
Contributor

@JohnAllenTech let me know when this is good to go since you are the overlord of tests.

@petercr

Copy link
Copy Markdown
ContributorAuthor

@JohnAllenTech I made some changes and added the extra tests you had suggested.
Tests now cover:

  • waiting for toast to show
  • waiting for toast to disappear
  • full page refresh
  • checking new value persists in input field

I did have to change a field in /e2e/setup/setup.ts to add https:// to it.
Otherwise you get an error on the form in E2E testing.

I also added new class names to both the toast messages for UI testing.

Thanks

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

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

Line range hint 4-8: Fix typo and remove empty test suite.

  1. Fix the typo in "setttings" (three 't's).
  2. The empty test suite for unauthenticated users should either be implemented or removed to maintain clean code.
-test.describe("Unauthenticated setttings Page", () => {- //- // Replace with tests for unauthenticated users-});+// TODO: Implement tests for unauthenticated users being redirected to /get-started+test.describe("Unauthenticated settings Page", () => {+ test("redirects to get-started page", async ({ page }) => {+ await page.goto("/settings");+ await expect(page).toHaveURL("/get-started");+ });+});

27-32: Improve error message validation.

The error message validation could be more robust by:

  1. Using data-testid for reliable selection
  2. Centralizing error messages
  3. Verifying error styling
+ // Define error messages+ const ERROR_MESSAGES = {+ INVALID_CHARS: 'Username can only contain alphanumerics and dashes.'+ } as const;+- const errorMessage = page.locator('p:text-is("Username can only contain alphanumerics and dashes.")')+ const errorMessage = page.locator('[data-testid="username-error"]');
await expect(errorMessage).toBeVisible();
- await expect(errorMessage).toHaveText('Username can only contain alphanumerics and dashes.');+ await expect(errorMessage).toHaveText(ERROR_MESSAGES.INVALID_CHARS);+ await expect(errorMessage).toHaveCSS('color', 'rgb(220, 38, 38)'); // Verify error styling
e2e/setup.ts (1)

123-123: Document the reason for URL format change.

While the change to use an absolute URL is sensible, it would be helpful to document why this change was necessary, especially since it seems tangential to the main PR objective of testing username changes.

Add a comment explaining the URL format requirement:

+ // Using absolute URL to comply with website URL validation requirements
websiteUrl: "https://codu.co",
app/(app)/settings/_client.tsx (2)

Line range hint 261-276: Consider adding a loading indicator during username validation.

While the username field implementation is solid, it could benefit from a visual indicator during validation to improve user experience. This would be particularly useful when checking for username availability.

Consider adding a loading state:

 <Field>
<Input
id="username"
type="text"
autoComplete="username"
invalid={!!errors?.username}
+ className={isValidating ? "opacity-50" : ""}
{...register("username")}
/>
+ {isValidating && (+ <div className="mt-2 flex items-center text-sm text-gray-500">+ <Loader2 className="mr-2 h-4 w-4 animate-spin" />+ Checking username availability...+ </div>+ )}
{errors?.username && (
<ErrorMessage>{errors.username.message}</ErrorMessage>
)}
</Field>

Line range hint 1-458: Consider breaking down the Settings component for better maintainability.

The component is well-structured but handles multiple responsibilities. Consider splitting it into smaller, focused components for better maintainability and testing.

Suggested structure:

  1. Create separate components for each section:

    • ProfilePhotoSection
    • PersonalInfoSection (name, username, bio)
    • ContactSection (location, website)
    • EmailSection
    • NotificationsSection
  2. Move the file upload logic to a custom hook:

    // hooks/useProfilePhotoUpload.tsconstuseProfilePhotoUpload=()=>{const[profilePhoto,setProfilePhoto]=useState<ProfilePhoto>({...});// ... file upload logicreturn{ profilePhoto, handleImageChange };};

This refactoring would:

  • Improve code organization
  • Make testing easier
  • Reduce cognitive load when maintaining the component
  • Allow for better error boundary placement
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e6883a5 and f9140cf.

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

43-45: Verify username persistence more thoroughly.

The current persistence check could be enhanced by:

  1. Verifying the username in the UI header/profile
  2. Checking the API response
  3. Testing persistence across multiple page navigations
✅ Verification successful

Current username persistence testing is sufficient

The current e2e test adequately verifies username persistence because:

  1. The username is properly integrated throughout the application (Nav, BioBar, Settings)
  2. The page reload test verifies server-side persistence
  3. Additional UI checks would be redundant as the username update automatically propagates through the layout and components

The implementation shows the username is:

  • Stored in the database and fetched server-side (layout.tsx)
  • Consistently displayed across navigation and profile components
  • Properly validated and persisted in settings
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash# Description: Verify username persistence across the application# Note: This script helps identify places where the username should be updated# Find files that might display or use the usernameecho"Files potentially using username:"
rg -l "username" --type=tsx --type=ts
# Find API endpoints handling usernameecho"\nAPI endpoints for username:"
rg -l "username.*api" --type=ts

Length of output: 245


Script:

#!/bin/bash# Let's try a different approach to find username-related code# Search for username-related patterns in all filesecho"Files containing username-related patterns:"
rg -l -i "username|user.*name"# Look for settings or profile-related componentsecho -e "\nSettings and profile-related files:"
fd -e ts -e tsx -e js -e jsx "settings|profile" --type f
# Search for API calls or endpointsecho -e "\nAPI-related patterns:"
rg -l "api.*username|username.*api"# Look specifically in the e2e test file to understand the context betterecho -e "\nContext from the e2e test file:"
rg -C 5 "username""e2e/settings.spec.ts"

Length of output: 3690


Script:

#!/bin/bash# Let's examine the settings page implementation and username persistence logic# Check settings page implementationecho"Settings page implementation:"
rg -C 10 "username""app/(app)/settings/_client.tsx"# Check username usage in layout and navigationecho -e "\nUsername usage in layout:"
rg -C 5 "username""app/(app)/layout.tsx"# Check profile/bio components that might display usernameecho -e "\nUsername display in BioBar:"
rg -C 5 "username""components/BioBar/BioBar.tsx"# Check navigation components for username displayecho -e "\nUsername in navigation:"
rg -C 5 "username""components/Nav/Nav.tsx"

Length of output: 4555

e2e/setup.ts (1)

123-123: Verify URL format change impact on tests.

The change from relative URL "codu.co" to absolute URL "https://codu.co" looks good, but let's ensure this aligns with the validation requirements.

Let's verify the URL validation requirements:

✅ Verification successful

URL format change aligns with schema requirements

The change from "codu.co" to "https://codu.co" is correct as the websiteUrl field in schema/profile.ts uses Zod's .url() validator, which requires a fully qualified URL with protocol. This validation would reject the previous "codu.co" format.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash# Description: Check URL validation schema and related tests# Look for URL validation schema
rg -A 5 'websiteUrl.*zod'# Look for website URL related tests
rg -A 5 'websiteUrl.*test'

Length of output: 56


Script:

#!/bin/bash# Let's try a broader search for URL validation patterns and website-related schemas# Search for any URL validation patterns
rg -i "url.*validation|validate.*url" -A 5
# Search for website URL usage in tests
rg "website.*url|url.*website" -A 5
# Search for zod schema definitions that might include URL
rg "z\.string\(\).*url|url.*z\.string" -A 5
# Look for any URL-related constants or configurations
rg "URL_PATTERN|URL_REGEX" -A 5

Length of output: 2168

app/(app)/settings/_client.tsx (1)

89-94: LGTM: Toast styling changes are clean and consistent.

The addition of className props to toast notifications provides better styling control while maintaining the existing functionality.

Comment threade2e/settings.spec.ts Outdated
Comment threade2e/settings.spec.ts Outdated
@JohnAllenTech

Copy link
Copy Markdown
Contributor

@JohnAllenTech I made some changes and added the extra tests you had suggested.

Tests now cover:

  • waiting for toast to show

  • waiting for toast to disappear

  • full page refresh

  • checking new value persists in input field

I did have to change a field in /e2e/setup/setup.ts to add https:// to it.

Otherwise you get an error on the form in E2E testing.

I also added new class names to both the toast messages for UI testing.

Thanks

Hey @petercr apologies I was AFK for a few days. I'll take a look at this in a while and reply properly

@NiallJoeMaher

Copy link
Copy Markdown
Contributor

Tests failing here.

@petercr

Copy link
Copy Markdown
ContributorAuthor

Well crap 😕 that's no good.
I will look into this over the weekend (next 2 days) and see if I can figure it out. 👌🏻

I wonder if this has to do with the newsletter sub function?
Either way I'm on it 👍🏻

@petercr

Copy link
Copy Markdown
ContributorAuthor

When I run the test locally, they all pass 🤷🏼‍♂️ see pic below.
I'm not sure but this may have to do with /server/lib/newsletter.ts.

I added extra code on line 39 to keep from getting the email API errors for the newsletter.
You can see some controller errors from posts.sidebarData and the tRPC error for profile.edit.

Here's what I added locally for this:

if(process.env.ENV==="local"||"development"){returntrue;}

But it might be simpler to go with:

if(process.env.ENV!=="production"){returntrue;}

Here is the image of the tests passing.

msrdc_ttyjHMMI1j

Sign up for freeto 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

3 participants

@petercr@NiallJoeMaher@JohnAllenTech
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

UI Tests for username change on /settings page. - #1203

Closed
petercr wants to merge 9 commits into
codu-code:developfrom
petercr:develop
Closed

UI Tests for username change on /settings page.#1203
petercr wants to merge 9 commits into
codu-code:developfrom
petercr:develop

Conversation

@petercr

Copy link
Copy Markdown
Contributor

✨ Codu Pull Request 💻

Fixes#1168
** Only Part 3.**

Pull Request details

Added UI tests for /settings to:

  • tests for input field & types
  • tries to submit a bad user name
  • checks for error visibility
  • resets the form
  • changes user name, saves, and checks for update

Any Breaking changes

None

Associated Screenshots

None, but the tests pass 😅 I promise!

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

Like this, only instead of Monday, Wed, Friday it's like start, middle, end 😆
A dog that starts out grumpy, then get glad, then gets happy.

@petercr
petercr requested a review from a team as a code ownerOctober 31, 2024 23:33
@vercel

vercelBot commented Oct 31, 2024

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitaiBot commented Oct 31, 2024

Copy link
Copy Markdown
Contributor

Walkthrough

The changes in this pull request enhance the end-to-end test suite for the authenticated settings page by adding a new test case focused on the username input field. The modifications include updating the import statements and implementing a series of assertions that validate the visibility, attributes, and functionality of the username input, including error handling for invalid inputs and confirmation of valid submissions.

Changes

FileChange Summary
e2e/settings.spec.tsUpdated import statements; added a new test case for username input validation, including checks for visibility, attributes, error messages, and form reset functionality.
app/(app)/settings/_client.tsxEnhanced toast notifications for success and error handling during settings save operations by adding custom class names.
e2e/setup.tsUpdated bio property in userData with a grammatical error; changed websiteUrl from a relative to an absolute URL.

Assessment against linked issues

ObjectiveAddressedExplanation
Add E2E tests for the username field (1168)
Ensure tests are standalone and focused (1168)
Validate input fields against Zod schema (1168)No explicit validation against Zod schema shown.
Cover edge cases for username input (1168)

Possibly related PRs

  • Fix/e2e tests #1061: This PR focuses on fixing and stabilizing end-to-end tests, which may relate to the enhancements made in the main PR for the settings page tests, as both involve improving test coverage and reliability.
  • fix: update e2e tests for newer changes in site #1085: This PR updates E2E tests, including modifications to the homepage tests, which may share similar testing strategies or structures with the new tests added for the settings page.
  • Feat/improving existing e2e tests #1125: This PR improves existing E2E tests, which could be relevant as it aims to enhance the overall testing framework, similar to the enhancements made in the main PR for the settings page.
  • feat: adding e2e test for article commenting #1158: This PR adds tests for commenting functionality, which may share testing principles with the username input validation in the settings tests, focusing on user input and feedback.
  • Isolating E2E test suite from seed script #1192: The isolation of the E2E test suite from the seed script may impact how tests are structured, potentially relating to the main PR's enhancements in testing.

Suggested labels

hacktoberfest-accepted, hacktoberfest

Suggested reviewers

  • NiallJoeMaher

🐰 In the land of code, where rabbits hop,
A test was added, and we won't stop!
For usernames bright, we check and we see,
Valid or not, they must be error-free!
With each little change, our coverage grows,
Hopping through tests, as the confidence flows! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fcd1dbb and c6949d0.

📒 Files selected for processing (1)
  • e2e/setup.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • e2e/setup.ts

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.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

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

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

Line range hint 4-7: Implement missing unauthenticated tests

The PR objectives mention testing unauthenticated user redirection to /get-started, but this test is missing.

Would you like me to provide an implementation for the unauthenticated test case that verifies redirection?

Comment threade2e/settings.spec.ts Outdated
Comment on lines +14 to +16
// Test for changing username
test('Username input field', async ({ page }) => {
await page.goto('http://localhost:3000/settings', { timeout: 30000 });

@coderabbitaicoderabbitaiBotOct 31, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve test configuration and navigation

Consider these improvements:

  1. The 30-second timeout seems excessive for local development
  2. The hardcoded URL should be replaced with a configurable base URL
- await page.goto('http://localhost:3000/settings', { timeout: 30000 });+ await page.goto('/settings');

Add this to your playwright.config.ts:

use: {baseURL: process.env.BASE_URL||'http://localhost:3000',}

Copy link
Copy Markdown
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!

Comment threade2e/settings.spec.ts Outdated
Comment threade2e/settings.spec.ts Outdated
Comment threade2e/settings.spec.ts
import { test, expect } from "@playwright/test";
import { loggedInAsUserOne } from "./utils";

test.describe("Unauthenticated setttings Page", () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we change this to authenticated settings page. Because the user is authenticated for these tests

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'm not sure exactly what you're saying here?

Did you want a separate file for auth vs. un-auth tests, because doesn't a user have to be logged in to edit their profile?

I guess I could use more detail on this 👌🏻

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Your new test is ran inside a test suite called 'Unauthenticated setttings Page'

But this is an authenticated test because users need to login to change their username.

If you just change the name of the test it will be fixed

Comment threade2e/settings.spec.ts Outdated
// Test that the input field can be filled with a valid value and saves it
await inputField.fill('codu-rules');
await page.locator('button[type="submit"]').click();
await expect(inputField).toHaveValue('codu-rules');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Will this wait for the username change to take effect?

If you fill in the new username and then click submit.

Will this test see the new username you have entered as the value of the input and complete straight away?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I mean the tests pass for it. But it could be just catching the still filled in form from before the reset.

Would you like me to change it to a page refresh instead?

Or would you like some kind of timeOut in-between the state change and checking for the change to persist?

I would be happy to add either one 👍🏻

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah I am not sure is there a loading indicator for these types of change? It would be nice to see

  1. Click submit
  2. Loading indicator appears
  3. Loading indicator hidden
  4. Check new username has taken effect

@JohnAllenTechJohnAllenTech left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just made some general comments. I am not a maintainer here so everything is just a suggestion

@NiallJoeMaher

Copy link
Copy Markdown
Contributor

@JohnAllenTech let me know when this is good to go since you are the overlord of tests.

@petercr

Copy link
Copy Markdown
ContributorAuthor

@JohnAllenTech I made some changes and added the extra tests you had suggested.
Tests now cover:

  • waiting for toast to show
  • waiting for toast to disappear
  • full page refresh
  • checking new value persists in input field

I did have to change a field in /e2e/setup/setup.ts to add https:// to it.
Otherwise you get an error on the form in E2E testing.

I also added new class names to both the toast messages for UI testing.

Thanks

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

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

Line range hint 4-8: Fix typo and remove empty test suite.

  1. Fix the typo in "setttings" (three 't's).
  2. The empty test suite for unauthenticated users should either be implemented or removed to maintain clean code.
-test.describe("Unauthenticated setttings Page", () => {- //- // Replace with tests for unauthenticated users-});+// TODO: Implement tests for unauthenticated users being redirected to /get-started+test.describe("Unauthenticated settings Page", () => {+ test("redirects to get-started page", async ({ page }) => {+ await page.goto("/settings");+ await expect(page).toHaveURL("/get-started");+ });+});

27-32: Improve error message validation.

The error message validation could be more robust by:

  1. Using data-testid for reliable selection
  2. Centralizing error messages
  3. Verifying error styling
+ // Define error messages+ const ERROR_MESSAGES = {+ INVALID_CHARS: 'Username can only contain alphanumerics and dashes.'+ } as const;+- const errorMessage = page.locator('p:text-is("Username can only contain alphanumerics and dashes.")')+ const errorMessage = page.locator('[data-testid="username-error"]');
await expect(errorMessage).toBeVisible();
- await expect(errorMessage).toHaveText('Username can only contain alphanumerics and dashes.');+ await expect(errorMessage).toHaveText(ERROR_MESSAGES.INVALID_CHARS);+ await expect(errorMessage).toHaveCSS('color', 'rgb(220, 38, 38)'); // Verify error styling
e2e/setup.ts (1)

123-123: Document the reason for URL format change.

While the change to use an absolute URL is sensible, it would be helpful to document why this change was necessary, especially since it seems tangential to the main PR objective of testing username changes.

Add a comment explaining the URL format requirement:

+ // Using absolute URL to comply with website URL validation requirements
websiteUrl: "https://codu.co",
app/(app)/settings/_client.tsx (2)

Line range hint 261-276: Consider adding a loading indicator during username validation.

While the username field implementation is solid, it could benefit from a visual indicator during validation to improve user experience. This would be particularly useful when checking for username availability.

Consider adding a loading state:

 <Field>
<Input
id="username"
type="text"
autoComplete="username"
invalid={!!errors?.username}
+ className={isValidating ? "opacity-50" : ""}
{...register("username")}
/>
+ {isValidating && (+ <div className="mt-2 flex items-center text-sm text-gray-500">+ <Loader2 className="mr-2 h-4 w-4 animate-spin" />+ Checking username availability...+ </div>+ )}
{errors?.username && (
<ErrorMessage>{errors.username.message}</ErrorMessage>
)}
</Field>

Line range hint 1-458: Consider breaking down the Settings component for better maintainability.

The component is well-structured but handles multiple responsibilities. Consider splitting it into smaller, focused components for better maintainability and testing.

Suggested structure:

  1. Create separate components for each section:

    • ProfilePhotoSection
    • PersonalInfoSection (name, username, bio)
    • ContactSection (location, website)
    • EmailSection
    • NotificationsSection
  2. Move the file upload logic to a custom hook:

    // hooks/useProfilePhotoUpload.tsconstuseProfilePhotoUpload=()=>{const[profilePhoto,setProfilePhoto]=useState<ProfilePhoto>({...});// ... file upload logicreturn{ profilePhoto, handleImageChange };};

This refactoring would:

  • Improve code organization
  • Make testing easier
  • Reduce cognitive load when maintaining the component
  • Allow for better error boundary placement
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e6883a5 and f9140cf.

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

43-45: Verify username persistence more thoroughly.

The current persistence check could be enhanced by:

  1. Verifying the username in the UI header/profile
  2. Checking the API response
  3. Testing persistence across multiple page navigations
✅ Verification successful

Current username persistence testing is sufficient

The current e2e test adequately verifies username persistence because:

  1. The username is properly integrated throughout the application (Nav, BioBar, Settings)
  2. The page reload test verifies server-side persistence
  3. Additional UI checks would be redundant as the username update automatically propagates through the layout and components

The implementation shows the username is:

  • Stored in the database and fetched server-side (layout.tsx)
  • Consistently displayed across navigation and profile components
  • Properly validated and persisted in settings
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash# Description: Verify username persistence across the application# Note: This script helps identify places where the username should be updated# Find files that might display or use the usernameecho"Files potentially using username:"
rg -l "username" --type=tsx --type=ts
# Find API endpoints handling usernameecho"\nAPI endpoints for username:"
rg -l "username.*api" --type=ts

Length of output: 245


Script:

#!/bin/bash# Let's try a different approach to find username-related code# Search for username-related patterns in all filesecho"Files containing username-related patterns:"
rg -l -i "username|user.*name"# Look for settings or profile-related componentsecho -e "\nSettings and profile-related files:"
fd -e ts -e tsx -e js -e jsx "settings|profile" --type f
# Search for API calls or endpointsecho -e "\nAPI-related patterns:"
rg -l "api.*username|username.*api"# Look specifically in the e2e test file to understand the context betterecho -e "\nContext from the e2e test file:"
rg -C 5 "username""e2e/settings.spec.ts"

Length of output: 3690


Script:

#!/bin/bash# Let's examine the settings page implementation and username persistence logic# Check settings page implementationecho"Settings page implementation:"
rg -C 10 "username""app/(app)/settings/_client.tsx"# Check username usage in layout and navigationecho -e "\nUsername usage in layout:"
rg -C 5 "username""app/(app)/layout.tsx"# Check profile/bio components that might display usernameecho -e "\nUsername display in BioBar:"
rg -C 5 "username""components/BioBar/BioBar.tsx"# Check navigation components for username displayecho -e "\nUsername in navigation:"
rg -C 5 "username""components/Nav/Nav.tsx"

Length of output: 4555

e2e/setup.ts (1)

123-123: Verify URL format change impact on tests.

The change from relative URL "codu.co" to absolute URL "https://codu.co" looks good, but let's ensure this aligns with the validation requirements.

Let's verify the URL validation requirements:

✅ Verification successful

URL format change aligns with schema requirements

The change from "codu.co" to "https://codu.co" is correct as the websiteUrl field in schema/profile.ts uses Zod's .url() validator, which requires a fully qualified URL with protocol. This validation would reject the previous "codu.co" format.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash# Description: Check URL validation schema and related tests# Look for URL validation schema
rg -A 5 'websiteUrl.*zod'# Look for website URL related tests
rg -A 5 'websiteUrl.*test'

Length of output: 56


Script:

#!/bin/bash# Let's try a broader search for URL validation patterns and website-related schemas# Search for any URL validation patterns
rg -i "url.*validation|validate.*url" -A 5
# Search for website URL usage in tests
rg "website.*url|url.*website" -A 5
# Search for zod schema definitions that might include URL
rg "z\.string\(\).*url|url.*z\.string" -A 5
# Look for any URL-related constants or configurations
rg "URL_PATTERN|URL_REGEX" -A 5

Length of output: 2168

app/(app)/settings/_client.tsx (1)

89-94: LGTM: Toast styling changes are clean and consistent.

The addition of className props to toast notifications provides better styling control while maintaining the existing functionality.

Comment threade2e/settings.spec.ts Outdated
Comment threade2e/settings.spec.ts Outdated
@JohnAllenTech

Copy link
Copy Markdown
Contributor

@JohnAllenTech I made some changes and added the extra tests you had suggested.

Tests now cover:

  • waiting for toast to show

  • waiting for toast to disappear

  • full page refresh

  • checking new value persists in input field

I did have to change a field in /e2e/setup/setup.ts to add https:// to it.

Otherwise you get an error on the form in E2E testing.

I also added new class names to both the toast messages for UI testing.

Thanks

Hey @petercr apologies I was AFK for a few days. I'll take a look at this in a while and reply properly

@NiallJoeMaher

Copy link
Copy Markdown
Contributor

Tests failing here.

@petercr

Copy link
Copy Markdown
ContributorAuthor

Well crap 😕 that's no good.
I will look into this over the weekend (next 2 days) and see if I can figure it out. 👌🏻

I wonder if this has to do with the newsletter sub function?
Either way I'm on it 👍🏻

@petercr

Copy link
Copy Markdown
ContributorAuthor

When I run the test locally, they all pass 🤷🏼‍♂️ see pic below.
I'm not sure but this may have to do with /server/lib/newsletter.ts.

I added extra code on line 39 to keep from getting the email API errors for the newsletter.
You can see some controller errors from posts.sidebarData and the tRPC error for profile.edit.

Here's what I added locally for this:

if(process.env.ENV==="local"||"development"){returntrue;}

But it might be simpler to go with:

if(process.env.ENV!=="production"){returntrue;}

Here is the image of the tests passing.

msrdc_ttyjHMMI1j

Sign up for freeto 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

3 participants

@petercr@NiallJoeMaher@JohnAllenTech
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

UI Tests for username change on /settings page. - #1203

Closed
petercr wants to merge 9 commits into
codu-code:developfrom
petercr:develop
Closed

UI Tests for username change on /settings page.#1203
petercr wants to merge 9 commits into
codu-code:developfrom
petercr:develop

Conversation

@petercr

Copy link
Copy Markdown
Contributor

✨ Codu Pull Request 💻

Fixes#1168
** Only Part 3.**

Pull Request details

Added UI tests for /settings to:

  • tests for input field & types
  • tries to submit a bad user name
  • checks for error visibility
  • resets the form
  • changes user name, saves, and checks for update

Any Breaking changes

None

Associated Screenshots

None, but the tests pass 😅 I promise!

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

Like this, only instead of Monday, Wed, Friday it's like start, middle, end 😆
A dog that starts out grumpy, then get glad, then gets happy.

@petercr
petercr requested a review from a team as a code ownerOctober 31, 2024 23:33
@vercel

vercelBot commented Oct 31, 2024

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitaiBot commented Oct 31, 2024

Copy link
Copy Markdown
Contributor

Walkthrough

The changes in this pull request enhance the end-to-end test suite for the authenticated settings page by adding a new test case focused on the username input field. The modifications include updating the import statements and implementing a series of assertions that validate the visibility, attributes, and functionality of the username input, including error handling for invalid inputs and confirmation of valid submissions.

Changes

FileChange Summary
e2e/settings.spec.tsUpdated import statements; added a new test case for username input validation, including checks for visibility, attributes, error messages, and form reset functionality.
app/(app)/settings/_client.tsxEnhanced toast notifications for success and error handling during settings save operations by adding custom class names.
e2e/setup.tsUpdated bio property in userData with a grammatical error; changed websiteUrl from a relative to an absolute URL.

Assessment against linked issues

ObjectiveAddressedExplanation
Add E2E tests for the username field (1168)
Ensure tests are standalone and focused (1168)
Validate input fields against Zod schema (1168)No explicit validation against Zod schema shown.
Cover edge cases for username input (1168)

Possibly related PRs

  • Fix/e2e tests #1061: This PR focuses on fixing and stabilizing end-to-end tests, which may relate to the enhancements made in the main PR for the settings page tests, as both involve improving test coverage and reliability.
  • fix: update e2e tests for newer changes in site #1085: This PR updates E2E tests, including modifications to the homepage tests, which may share similar testing strategies or structures with the new tests added for the settings page.
  • Feat/improving existing e2e tests #1125: This PR improves existing E2E tests, which could be relevant as it aims to enhance the overall testing framework, similar to the enhancements made in the main PR for the settings page.
  • feat: adding e2e test for article commenting #1158: This PR adds tests for commenting functionality, which may share testing principles with the username input validation in the settings tests, focusing on user input and feedback.
  • Isolating E2E test suite from seed script #1192: The isolation of the E2E test suite from the seed script may impact how tests are structured, potentially relating to the main PR's enhancements in testing.

Suggested labels

hacktoberfest-accepted, hacktoberfest

Suggested reviewers

  • NiallJoeMaher

🐰 In the land of code, where rabbits hop,
A test was added, and we won't stop!
For usernames bright, we check and we see,
Valid or not, they must be error-free!
With each little change, our coverage grows,
Hopping through tests, as the confidence flows! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fcd1dbb and c6949d0.

📒 Files selected for processing (1)
  • e2e/setup.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • e2e/setup.ts

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.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

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

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

Line range hint 4-7: Implement missing unauthenticated tests

The PR objectives mention testing unauthenticated user redirection to /get-started, but this test is missing.

Would you like me to provide an implementation for the unauthenticated test case that verifies redirection?

Comment threade2e/settings.spec.ts Outdated
Comment on lines +14 to +16
// Test for changing username
test('Username input field', async ({ page }) => {
await page.goto('http://localhost:3000/settings', { timeout: 30000 });

@coderabbitaicoderabbitaiBotOct 31, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve test configuration and navigation

Consider these improvements:

  1. The 30-second timeout seems excessive for local development
  2. The hardcoded URL should be replaced with a configurable base URL
- await page.goto('http://localhost:3000/settings', { timeout: 30000 });+ await page.goto('/settings');

Add this to your playwright.config.ts:

use: {baseURL: process.env.BASE_URL||'http://localhost:3000',}

Copy link
Copy Markdown
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!

Comment threade2e/settings.spec.ts Outdated
Comment threade2e/settings.spec.ts Outdated
Comment threade2e/settings.spec.ts
import { test, expect } from "@playwright/test";
import { loggedInAsUserOne } from "./utils";

test.describe("Unauthenticated setttings Page", () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we change this to authenticated settings page. Because the user is authenticated for these tests

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'm not sure exactly what you're saying here?

Did you want a separate file for auth vs. un-auth tests, because doesn't a user have to be logged in to edit their profile?

I guess I could use more detail on this 👌🏻

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Your new test is ran inside a test suite called 'Unauthenticated setttings Page'

But this is an authenticated test because users need to login to change their username.

If you just change the name of the test it will be fixed

Comment threade2e/settings.spec.ts Outdated
// Test that the input field can be filled with a valid value and saves it
await inputField.fill('codu-rules');
await page.locator('button[type="submit"]').click();
await expect(inputField).toHaveValue('codu-rules');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Will this wait for the username change to take effect?

If you fill in the new username and then click submit.

Will this test see the new username you have entered as the value of the input and complete straight away?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I mean the tests pass for it. But it could be just catching the still filled in form from before the reset.

Would you like me to change it to a page refresh instead?

Or would you like some kind of timeOut in-between the state change and checking for the change to persist?

I would be happy to add either one 👍🏻

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah I am not sure is there a loading indicator for these types of change? It would be nice to see

  1. Click submit
  2. Loading indicator appears
  3. Loading indicator hidden
  4. Check new username has taken effect

@JohnAllenTechJohnAllenTech left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just made some general comments. I am not a maintainer here so everything is just a suggestion

@NiallJoeMaher

Copy link
Copy Markdown
Contributor

@JohnAllenTech let me know when this is good to go since you are the overlord of tests.

@petercr

Copy link
Copy Markdown
ContributorAuthor

@JohnAllenTech I made some changes and added the extra tests you had suggested.
Tests now cover:

  • waiting for toast to show
  • waiting for toast to disappear
  • full page refresh
  • checking new value persists in input field

I did have to change a field in /e2e/setup/setup.ts to add https:// to it.
Otherwise you get an error on the form in E2E testing.

I also added new class names to both the toast messages for UI testing.

Thanks

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

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

Line range hint 4-8: Fix typo and remove empty test suite.

  1. Fix the typo in "setttings" (three 't's).
  2. The empty test suite for unauthenticated users should either be implemented or removed to maintain clean code.
-test.describe("Unauthenticated setttings Page", () => {- //- // Replace with tests for unauthenticated users-});+// TODO: Implement tests for unauthenticated users being redirected to /get-started+test.describe("Unauthenticated settings Page", () => {+ test("redirects to get-started page", async ({ page }) => {+ await page.goto("/settings");+ await expect(page).toHaveURL("/get-started");+ });+});

27-32: Improve error message validation.

The error message validation could be more robust by:

  1. Using data-testid for reliable selection
  2. Centralizing error messages
  3. Verifying error styling
+ // Define error messages+ const ERROR_MESSAGES = {+ INVALID_CHARS: 'Username can only contain alphanumerics and dashes.'+ } as const;+- const errorMessage = page.locator('p:text-is("Username can only contain alphanumerics and dashes.")')+ const errorMessage = page.locator('[data-testid="username-error"]');
await expect(errorMessage).toBeVisible();
- await expect(errorMessage).toHaveText('Username can only contain alphanumerics and dashes.');+ await expect(errorMessage).toHaveText(ERROR_MESSAGES.INVALID_CHARS);+ await expect(errorMessage).toHaveCSS('color', 'rgb(220, 38, 38)'); // Verify error styling
e2e/setup.ts (1)

123-123: Document the reason for URL format change.

While the change to use an absolute URL is sensible, it would be helpful to document why this change was necessary, especially since it seems tangential to the main PR objective of testing username changes.

Add a comment explaining the URL format requirement:

+ // Using absolute URL to comply with website URL validation requirements
websiteUrl: "https://codu.co",
app/(app)/settings/_client.tsx (2)

Line range hint 261-276: Consider adding a loading indicator during username validation.

While the username field implementation is solid, it could benefit from a visual indicator during validation to improve user experience. This would be particularly useful when checking for username availability.

Consider adding a loading state:

 <Field>
<Input
id="username"
type="text"
autoComplete="username"
invalid={!!errors?.username}
+ className={isValidating ? "opacity-50" : ""}
{...register("username")}
/>
+ {isValidating && (+ <div className="mt-2 flex items-center text-sm text-gray-500">+ <Loader2 className="mr-2 h-4 w-4 animate-spin" />+ Checking username availability...+ </div>+ )}
{errors?.username && (
<ErrorMessage>{errors.username.message}</ErrorMessage>
)}
</Field>

Line range hint 1-458: Consider breaking down the Settings component for better maintainability.

The component is well-structured but handles multiple responsibilities. Consider splitting it into smaller, focused components for better maintainability and testing.

Suggested structure:

  1. Create separate components for each section:

    • ProfilePhotoSection
    • PersonalInfoSection (name, username, bio)
    • ContactSection (location, website)
    • EmailSection
    • NotificationsSection
  2. Move the file upload logic to a custom hook:

    // hooks/useProfilePhotoUpload.tsconstuseProfilePhotoUpload=()=>{const[profilePhoto,setProfilePhoto]=useState<ProfilePhoto>({...});// ... file upload logicreturn{ profilePhoto, handleImageChange };};

This refactoring would:

  • Improve code organization
  • Make testing easier
  • Reduce cognitive load when maintaining the component
  • Allow for better error boundary placement
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e6883a5 and f9140cf.

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

43-45: Verify username persistence more thoroughly.

The current persistence check could be enhanced by:

  1. Verifying the username in the UI header/profile
  2. Checking the API response
  3. Testing persistence across multiple page navigations
✅ Verification successful

Current username persistence testing is sufficient

The current e2e test adequately verifies username persistence because:

  1. The username is properly integrated throughout the application (Nav, BioBar, Settings)
  2. The page reload test verifies server-side persistence
  3. Additional UI checks would be redundant as the username update automatically propagates through the layout and components

The implementation shows the username is:

  • Stored in the database and fetched server-side (layout.tsx)
  • Consistently displayed across navigation and profile components
  • Properly validated and persisted in settings
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash# Description: Verify username persistence across the application# Note: This script helps identify places where the username should be updated# Find files that might display or use the usernameecho"Files potentially using username:"
rg -l "username" --type=tsx --type=ts
# Find API endpoints handling usernameecho"\nAPI endpoints for username:"
rg -l "username.*api" --type=ts

Length of output: 245


Script:

#!/bin/bash# Let's try a different approach to find username-related code# Search for username-related patterns in all filesecho"Files containing username-related patterns:"
rg -l -i "username|user.*name"# Look for settings or profile-related componentsecho -e "\nSettings and profile-related files:"
fd -e ts -e tsx -e js -e jsx "settings|profile" --type f
# Search for API calls or endpointsecho -e "\nAPI-related patterns:"
rg -l "api.*username|username.*api"# Look specifically in the e2e test file to understand the context betterecho -e "\nContext from the e2e test file:"
rg -C 5 "username""e2e/settings.spec.ts"

Length of output: 3690


Script:

#!/bin/bash# Let's examine the settings page implementation and username persistence logic# Check settings page implementationecho"Settings page implementation:"
rg -C 10 "username""app/(app)/settings/_client.tsx"# Check username usage in layout and navigationecho -e "\nUsername usage in layout:"
rg -C 5 "username""app/(app)/layout.tsx"# Check profile/bio components that might display usernameecho -e "\nUsername display in BioBar:"
rg -C 5 "username""components/BioBar/BioBar.tsx"# Check navigation components for username displayecho -e "\nUsername in navigation:"
rg -C 5 "username""components/Nav/Nav.tsx"

Length of output: 4555

e2e/setup.ts (1)

123-123: Verify URL format change impact on tests.

The change from relative URL "codu.co" to absolute URL "https://codu.co" looks good, but let's ensure this aligns with the validation requirements.

Let's verify the URL validation requirements:

✅ Verification successful

URL format change aligns with schema requirements

The change from "codu.co" to "https://codu.co" is correct as the websiteUrl field in schema/profile.ts uses Zod's .url() validator, which requires a fully qualified URL with protocol. This validation would reject the previous "codu.co" format.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash# Description: Check URL validation schema and related tests# Look for URL validation schema
rg -A 5 'websiteUrl.*zod'# Look for website URL related tests
rg -A 5 'websiteUrl.*test'

Length of output: 56


Script:

#!/bin/bash# Let's try a broader search for URL validation patterns and website-related schemas# Search for any URL validation patterns
rg -i "url.*validation|validate.*url" -A 5
# Search for website URL usage in tests
rg "website.*url|url.*website" -A 5
# Search for zod schema definitions that might include URL
rg "z\.string\(\).*url|url.*z\.string" -A 5
# Look for any URL-related constants or configurations
rg "URL_PATTERN|URL_REGEX" -A 5

Length of output: 2168

app/(app)/settings/_client.tsx (1)

89-94: LGTM: Toast styling changes are clean and consistent.

The addition of className props to toast notifications provides better styling control while maintaining the existing functionality.

Comment threade2e/settings.spec.ts Outdated
Comment threade2e/settings.spec.ts Outdated
@JohnAllenTech

Copy link
Copy Markdown
Contributor

@JohnAllenTech I made some changes and added the extra tests you had suggested.

Tests now cover:

  • waiting for toast to show

  • waiting for toast to disappear

  • full page refresh

  • checking new value persists in input field

I did have to change a field in /e2e/setup/setup.ts to add https:// to it.

Otherwise you get an error on the form in E2E testing.

I also added new class names to both the toast messages for UI testing.

Thanks

Hey @petercr apologies I was AFK for a few days. I'll take a look at this in a while and reply properly

@NiallJoeMaher

Copy link
Copy Markdown
Contributor

Tests failing here.

@petercr

Copy link
Copy Markdown
ContributorAuthor

Well crap 😕 that's no good.
I will look into this over the weekend (next 2 days) and see if I can figure it out. 👌🏻

I wonder if this has to do with the newsletter sub function?
Either way I'm on it 👍🏻

@petercr

Copy link
Copy Markdown
ContributorAuthor

When I run the test locally, they all pass 🤷🏼‍♂️ see pic below.
I'm not sure but this may have to do with /server/lib/newsletter.ts.

I added extra code on line 39 to keep from getting the email API errors for the newsletter.
You can see some controller errors from posts.sidebarData and the tRPC error for profile.edit.

Here's what I added locally for this:

if(process.env.ENV==="local"||"development"){returntrue;}

But it might be simpler to go with:

if(process.env.ENV!=="production"){returntrue;}

Here is the image of the tests passing.

msrdc_ttyjHMMI1j

Sign up for freeto 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

3 participants

@petercr@NiallJoeMaher@JohnAllenTech
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

UI Tests for username change on /settings page. - #1203

Closed
petercr wants to merge 9 commits into
codu-code:developfrom
petercr:develop
Closed

UI Tests for username change on /settings page.#1203
petercr wants to merge 9 commits into
codu-code:developfrom
petercr:develop

Conversation

@petercr

Copy link
Copy Markdown
Contributor

✨ Codu Pull Request 💻

Fixes#1168
** Only Part 3.**

Pull Request details

Added UI tests for /settings to:

  • tests for input field & types
  • tries to submit a bad user name
  • checks for error visibility
  • resets the form
  • changes user name, saves, and checks for update

Any Breaking changes

None

Associated Screenshots

None, but the tests pass 😅 I promise!

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

Like this, only instead of Monday, Wed, Friday it's like start, middle, end 😆
A dog that starts out grumpy, then get glad, then gets happy.

@petercr
petercr requested a review from a team as a code ownerOctober 31, 2024 23:33
@vercel

vercelBot commented Oct 31, 2024

Copy link
Copy Markdown

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

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitaiBot commented Oct 31, 2024

Copy link
Copy Markdown
Contributor

Walkthrough

The changes in this pull request enhance the end-to-end test suite for the authenticated settings page by adding a new test case focused on the username input field. The modifications include updating the import statements and implementing a series of assertions that validate the visibility, attributes, and functionality of the username input, including error handling for invalid inputs and confirmation of valid submissions.

Changes

FileChange Summary
e2e/settings.spec.tsUpdated import statements; added a new test case for username input validation, including checks for visibility, attributes, error messages, and form reset functionality.
app/(app)/settings/_client.tsxEnhanced toast notifications for success and error handling during settings save operations by adding custom class names.
e2e/setup.tsUpdated bio property in userData with a grammatical error; changed websiteUrl from a relative to an absolute URL.

Assessment against linked issues

ObjectiveAddressedExplanation
Add E2E tests for the username field (1168)
Ensure tests are standalone and focused (1168)
Validate input fields against Zod schema (1168)No explicit validation against Zod schema shown.
Cover edge cases for username input (1168)

Possibly related PRs

  • Fix/e2e tests #1061: This PR focuses on fixing and stabilizing end-to-end tests, which may relate to the enhancements made in the main PR for the settings page tests, as both involve improving test coverage and reliability.
  • fix: update e2e tests for newer changes in site #1085: This PR updates E2E tests, including modifications to the homepage tests, which may share similar testing strategies or structures with the new tests added for the settings page.
  • Feat/improving existing e2e tests #1125: This PR improves existing E2E tests, which could be relevant as it aims to enhance the overall testing framework, similar to the enhancements made in the main PR for the settings page.
  • feat: adding e2e test for article commenting #1158: This PR adds tests for commenting functionality, which may share testing principles with the username input validation in the settings tests, focusing on user input and feedback.
  • Isolating E2E test suite from seed script #1192: The isolation of the E2E test suite from the seed script may impact how tests are structured, potentially relating to the main PR's enhancements in testing.

Suggested labels

hacktoberfest-accepted, hacktoberfest

Suggested reviewers

  • NiallJoeMaher

🐰 In the land of code, where rabbits hop,
A test was added, and we won't stop!
For usernames bright, we check and we see,
Valid or not, they must be error-free!
With each little change, our coverage grows,
Hopping through tests, as the confidence flows! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fcd1dbb and c6949d0.

📒 Files selected for processing (1)
  • e2e/setup.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • e2e/setup.ts

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.

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

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

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

Line range hint 4-7: Implement missing unauthenticated tests

The PR objectives mention testing unauthenticated user redirection to /get-started, but this test is missing.

Would you like me to provide an implementation for the unauthenticated test case that verifies redirection?

Comment threade2e/settings.spec.ts Outdated
Comment on lines +14 to +16
// Test for changing username
test('Username input field', async ({ page }) => {
await page.goto('http://localhost:3000/settings', { timeout: 30000 });

@coderabbitaicoderabbitaiBotOct 31, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve test configuration and navigation

Consider these improvements:

  1. The 30-second timeout seems excessive for local development
  2. The hardcoded URL should be replaced with a configurable base URL
- await page.goto('http://localhost:3000/settings', { timeout: 30000 });+ await page.goto('/settings');

Add this to your playwright.config.ts:

use: {baseURL: process.env.BASE_URL||'http://localhost:3000',}

Copy link
Copy Markdown
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!

Comment threade2e/settings.spec.ts Outdated
Comment threade2e/settings.spec.ts Outdated
Comment threade2e/settings.spec.ts
import { test, expect } from "@playwright/test";
import { loggedInAsUserOne } from "./utils";

test.describe("Unauthenticated setttings Page", () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we change this to authenticated settings page. Because the user is authenticated for these tests

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'm not sure exactly what you're saying here?

Did you want a separate file for auth vs. un-auth tests, because doesn't a user have to be logged in to edit their profile?

I guess I could use more detail on this 👌🏻

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Your new test is ran inside a test suite called 'Unauthenticated setttings Page'

But this is an authenticated test because users need to login to change their username.

If you just change the name of the test it will be fixed

Comment threade2e/settings.spec.ts Outdated
// Test that the input field can be filled with a valid value and saves it
await inputField.fill('codu-rules');
await page.locator('button[type="submit"]').click();
await expect(inputField).toHaveValue('codu-rules');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Will this wait for the username change to take effect?

If you fill in the new username and then click submit.

Will this test see the new username you have entered as the value of the input and complete straight away?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I mean the tests pass for it. But it could be just catching the still filled in form from before the reset.

Would you like me to change it to a page refresh instead?

Or would you like some kind of timeOut in-between the state change and checking for the change to persist?

I would be happy to add either one 👍🏻

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah I am not sure is there a loading indicator for these types of change? It would be nice to see

  1. Click submit
  2. Loading indicator appears
  3. Loading indicator hidden
  4. Check new username has taken effect

@JohnAllenTechJohnAllenTech left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just made some general comments. I am not a maintainer here so everything is just a suggestion

@NiallJoeMaher

Copy link
Copy Markdown
Contributor

@JohnAllenTech let me know when this is good to go since you are the overlord of tests.

@petercr

Copy link
Copy Markdown
ContributorAuthor

@JohnAllenTech I made some changes and added the extra tests you had suggested.
Tests now cover:

  • waiting for toast to show
  • waiting for toast to disappear
  • full page refresh
  • checking new value persists in input field

I did have to change a field in /e2e/setup/setup.ts to add https:// to it.
Otherwise you get an error on the form in E2E testing.

I also added new class names to both the toast messages for UI testing.

Thanks

@coderabbitaicoderabbitaiBot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

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

Line range hint 4-8: Fix typo and remove empty test suite.

  1. Fix the typo in "setttings" (three 't's).
  2. The empty test suite for unauthenticated users should either be implemented or removed to maintain clean code.
-test.describe("Unauthenticated setttings Page", () => {- //- // Replace with tests for unauthenticated users-});+// TODO: Implement tests for unauthenticated users being redirected to /get-started+test.describe("Unauthenticated settings Page", () => {+ test("redirects to get-started page", async ({ page }) => {+ await page.goto("/settings");+ await expect(page).toHaveURL("/get-started");+ });+});

27-32: Improve error message validation.

The error message validation could be more robust by:

  1. Using data-testid for reliable selection
  2. Centralizing error messages
  3. Verifying error styling
+ // Define error messages+ const ERROR_MESSAGES = {+ INVALID_CHARS: 'Username can only contain alphanumerics and dashes.'+ } as const;+- const errorMessage = page.locator('p:text-is("Username can only contain alphanumerics and dashes.")')+ const errorMessage = page.locator('[data-testid="username-error"]');
await expect(errorMessage).toBeVisible();
- await expect(errorMessage).toHaveText('Username can only contain alphanumerics and dashes.');+ await expect(errorMessage).toHaveText(ERROR_MESSAGES.INVALID_CHARS);+ await expect(errorMessage).toHaveCSS('color', 'rgb(220, 38, 38)'); // Verify error styling
e2e/setup.ts (1)

123-123: Document the reason for URL format change.

While the change to use an absolute URL is sensible, it would be helpful to document why this change was necessary, especially since it seems tangential to the main PR objective of testing username changes.

Add a comment explaining the URL format requirement:

+ // Using absolute URL to comply with website URL validation requirements
websiteUrl: "https://codu.co",
app/(app)/settings/_client.tsx (2)

Line range hint 261-276: Consider adding a loading indicator during username validation.

While the username field implementation is solid, it could benefit from a visual indicator during validation to improve user experience. This would be particularly useful when checking for username availability.

Consider adding a loading state:

 <Field>
<Input
id="username"
type="text"
autoComplete="username"
invalid={!!errors?.username}
+ className={isValidating ? "opacity-50" : ""}
{...register("username")}
/>
+ {isValidating && (+ <div className="mt-2 flex items-center text-sm text-gray-500">+ <Loader2 className="mr-2 h-4 w-4 animate-spin" />+ Checking username availability...+ </div>+ )}
{errors?.username && (
<ErrorMessage>{errors.username.message}</ErrorMessage>
)}
</Field>

Line range hint 1-458: Consider breaking down the Settings component for better maintainability.

The component is well-structured but handles multiple responsibilities. Consider splitting it into smaller, focused components for better maintainability and testing.

Suggested structure:

  1. Create separate components for each section:

    • ProfilePhotoSection
    • PersonalInfoSection (name, username, bio)
    • ContactSection (location, website)
    • EmailSection
    • NotificationsSection
  2. Move the file upload logic to a custom hook:

    // hooks/useProfilePhotoUpload.tsconstuseProfilePhotoUpload=()=>{const[profilePhoto,setProfilePhoto]=useState<ProfilePhoto>({...});// ... file upload logicreturn{ profilePhoto, handleImageChange };};

This refactoring would:

  • Improve code organization
  • Make testing easier
  • Reduce cognitive load when maintaining the component
  • Allow for better error boundary placement
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e6883a5 and f9140cf.

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

43-45: Verify username persistence more thoroughly.

The current persistence check could be enhanced by:

  1. Verifying the username in the UI header/profile
  2. Checking the API response
  3. Testing persistence across multiple page navigations
✅ Verification successful

Current username persistence testing is sufficient

The current e2e test adequately verifies username persistence because:

  1. The username is properly integrated throughout the application (Nav, BioBar, Settings)
  2. The page reload test verifies server-side persistence
  3. Additional UI checks would be redundant as the username update automatically propagates through the layout and components

The implementation shows the username is:

  • Stored in the database and fetched server-side (layout.tsx)
  • Consistently displayed across navigation and profile components
  • Properly validated and persisted in settings
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash# Description: Verify username persistence across the application# Note: This script helps identify places where the username should be updated# Find files that might display or use the usernameecho"Files potentially using username:"
rg -l "username" --type=tsx --type=ts
# Find API endpoints handling usernameecho"\nAPI endpoints for username:"
rg -l "username.*api" --type=ts

Length of output: 245


Script:

#!/bin/bash# Let's try a different approach to find username-related code# Search for username-related patterns in all filesecho"Files containing username-related patterns:"
rg -l -i "username|user.*name"# Look for settings or profile-related componentsecho -e "\nSettings and profile-related files:"
fd -e ts -e tsx -e js -e jsx "settings|profile" --type f
# Search for API calls or endpointsecho -e "\nAPI-related patterns:"
rg -l "api.*username|username.*api"# Look specifically in the e2e test file to understand the context betterecho -e "\nContext from the e2e test file:"
rg -C 5 "username""e2e/settings.spec.ts"

Length of output: 3690


Script:

#!/bin/bash# Let's examine the settings page implementation and username persistence logic# Check settings page implementationecho"Settings page implementation:"
rg -C 10 "username""app/(app)/settings/_client.tsx"# Check username usage in layout and navigationecho -e "\nUsername usage in layout:"
rg -C 5 "username""app/(app)/layout.tsx"# Check profile/bio components that might display usernameecho -e "\nUsername display in BioBar:"
rg -C 5 "username""components/BioBar/BioBar.tsx"# Check navigation components for username displayecho -e "\nUsername in navigation:"
rg -C 5 "username""components/Nav/Nav.tsx"

Length of output: 4555

e2e/setup.ts (1)

123-123: Verify URL format change impact on tests.

The change from relative URL "codu.co" to absolute URL "https://codu.co" looks good, but let's ensure this aligns with the validation requirements.

Let's verify the URL validation requirements:

✅ Verification successful

URL format change aligns with schema requirements

The change from "codu.co" to "https://codu.co" is correct as the websiteUrl field in schema/profile.ts uses Zod's .url() validator, which requires a fully qualified URL with protocol. This validation would reject the previous "codu.co" format.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash# Description: Check URL validation schema and related tests# Look for URL validation schema
rg -A 5 'websiteUrl.*zod'# Look for website URL related tests
rg -A 5 'websiteUrl.*test'

Length of output: 56


Script:

#!/bin/bash# Let's try a broader search for URL validation patterns and website-related schemas# Search for any URL validation patterns
rg -i "url.*validation|validate.*url" -A 5
# Search for website URL usage in tests
rg "website.*url|url.*website" -A 5
# Search for zod schema definitions that might include URL
rg "z\.string\(\).*url|url.*z\.string" -A 5
# Look for any URL-related constants or configurations
rg "URL_PATTERN|URL_REGEX" -A 5

Length of output: 2168

app/(app)/settings/_client.tsx (1)

89-94: LGTM: Toast styling changes are clean and consistent.

The addition of className props to toast notifications provides better styling control while maintaining the existing functionality.

Comment threade2e/settings.spec.ts Outdated
Comment threade2e/settings.spec.ts Outdated
@JohnAllenTech

Copy link
Copy Markdown
Contributor

@JohnAllenTech I made some changes and added the extra tests you had suggested.

Tests now cover:

  • waiting for toast to show

  • waiting for toast to disappear

  • full page refresh

  • checking new value persists in input field

I did have to change a field in /e2e/setup/setup.ts to add https:// to it.

Otherwise you get an error on the form in E2E testing.

I also added new class names to both the toast messages for UI testing.

Thanks

Hey @petercr apologies I was AFK for a few days. I'll take a look at this in a while and reply properly

@NiallJoeMaher

Copy link
Copy Markdown
Contributor

Tests failing here.

@petercr

Copy link
Copy Markdown
ContributorAuthor

Well crap 😕 that's no good.
I will look into this over the weekend (next 2 days) and see if I can figure it out. 👌🏻

I wonder if this has to do with the newsletter sub function?
Either way I'm on it 👍🏻

@petercr

Copy link
Copy Markdown
ContributorAuthor

When I run the test locally, they all pass 🤷🏼‍♂️ see pic below.
I'm not sure but this may have to do with /server/lib/newsletter.ts.

I added extra code on line 39 to keep from getting the email API errors for the newsletter.
You can see some controller errors from posts.sidebarData and the tRPC error for profile.edit.

Here's what I added locally for this:

if(process.env.ENV==="local"||"development"){returntrue;}

But it might be simpler to go with:

if(process.env.ENV!=="production"){returntrue;}

Here is the image of the tests passing.

msrdc_ttyjHMMI1j

Sign up for freeto 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

3 participants

@petercr@NiallJoeMaher@JohnAllenTech