Skip to content

test(web): add tests for user profile page render and 404 flow#512

Open
Satvik-art-creator wants to merge 13 commits into
Dev-Card:mainfrom
Satvik-art-creator:feat/web-profile-tests
Open

test(web): add tests for user profile page render and 404 flow#512
Satvik-art-creator wants to merge 13 commits into
Dev-Card:mainfrom
Satvik-art-creator:feat/web-profile-tests

Conversation

@Satvik-art-creator

Copy link
Copy Markdown
Contributor

Summary

This PR adds unit tests to verify that the user profile page properly renders profile data and handles missing users. It sets up the Vitest testing environment with @testing-library/svelte and jsdom, and implements the specific test cases outlined in the issue.

This issue was successfully solved as part of the GirlScript Summer of Code (GSSoC) 2026 program.

Contributor: Satvik-art-creator (GSSoC '26)

Closes #16


Type of Change

  • Bug fix
  • New feature
  • Refactor (no functional change)
  • UI / Design change
  • Tests only
  • Documentation
  • Infrastructure / DevOps
  • Security

What Changed

  • apps/web/package.json: Added test script and installed testing dependencies including vitest, svelte, @testing-library/svelte, jsdom, @testing-library/jest-dom, and @sveltejs/vite-plugin-svelte.
  • apps/web/vitest.config.ts & apps/web/vitest-setup.ts: Configured Vitest to run in a jsdom environment, load jest-dom custom matchers, and properly resolve Svelte browser conditions.
  • apps/web/src/routes/u/[username]/+page.svelte: Created a mock Svelte component to consume loader data and render profile information or error messages.
  • apps/web/src/routes/u/[username]/+page.test.ts: Created tests to assert that the profile name and avatar are rendered when data is present, and that the "User Not Found" message appears when a loader error is simulated.

How to Test

  1. Fetch and checkout the branch: git fetch origin main && git checkout feat/web-profile-tests
  2. Install the new dependencies: run npm --prefix apps/web install (or your respective package manager command).
  3. Run the tests: npm --prefix apps/web run test
  4. Verify that the Vitest suite executes and both Profile Page tests pass successfully.

Checklist

  • My code follows the project's coding style (pnpm -r run lint passes).
  • TypeScript compiles without errors (pnpm -r run typecheck).
  • I have added or updated tests for the changes I made.
  • All tests pass locally (pnpm -r run test).
  • I have updated documentation where necessary.
  • No new console.log or debug statements left in the code.
  • Breaking changes are documented in this PR description.

Screenshots / Recordings

N/A


Additional Context

Per the explicit instructions of Issue #16, the tests were written using @testing-library/svelte and test files were placed in the apps/web/src/routes/u/[username]/ directory.

Copilot AI review requested due to automatic review settings June 9, 2026 06:21
@vercel

vercel Bot commented Jun 9, 2026

Copy link
Copy Markdown

@Satvik-art-creator is attempting to deploy a commit to the Prashantkumar Khatri's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

CI — Checks Failed

Backend — SKIP

Check Result
Lint -
Test -
Typecheck -

Mobile — SKIP

Check Result
Lint -
Test -

Web — FAIL

Check Result
Check FAIL
Build PASS

Last updated: Sat, 13 Jun 2026 11:38:42 GMT

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a Vitest + Testing Library setup for the web app and introduces an initial Svelte route (“profile page”) with component tests.

Changes:

  • Add Vitest configuration and global test setup for jsdom + Testing Library matchers
  • Add a Svelte profile page (+page.svelte) and corresponding Vitest test (+page.test.ts)
  • Add required devDependencies and a test script to run Vitest

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
apps/web/vitest.config.ts Introduces Vitest config (jsdom env, setup file, test include pattern, resolve conditions)
apps/web/vitest-setup.ts Registers Testing Library DOM matchers globally for tests
apps/web/src/routes/u/[username]/+page.test.ts Adds component tests for the profile page rendering and error state
apps/web/src/routes/u/[username]/+page.svelte Adds the profile page UI with conditional rendering based on data
apps/web/package.json Adds vitest run script and testing/Svelte-related devDependencies
Files not reviewed (1)
  • apps/web/package-lock.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread apps/web/vitest-setup.ts Outdated
Comment thread apps/web/src/routes/u/[username]/+page.test.ts Outdated
Comment thread apps/web/vitest.config.ts Outdated
Comment thread apps/web/src/routes/u/[username]/+page.svelte Outdated
@Satvik-art-creator

Copy link
Copy Markdown
Contributor Author

@ShantKhatri Kindly review my pr and merge it under the GSSOC 26 program

Copilot AI review requested due to automatic review settings June 9, 2026 06:35

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

Pull request overview

Copilot reviewed 12 out of 13 changed files in this pull request and generated 5 comments.

Files not reviewed (1)
  • apps/web/package-lock.json: Language not supported

Comment thread apps/web/src/pages/ProfilePage.tsx Outdated
Comment thread apps/web/src/pages/ProfilePage.tsx
Comment thread apps/web/src/pages/CardPage.tsx
Comment thread apps/web/src/pages/ProfilePage.tsx Outdated
Comment thread apps/web/src/routes/u/[username]/$types.ts Outdated
@Harxhit Harxhit added web gssoc:approved Required label for every approved PR. Gives the base +50 points and enables contribution tracking. labels Jun 9, 2026
Copilot AI review requested due to automatic review settings June 9, 2026 06:44

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

Pull request overview

Copilot reviewed 12 out of 13 changed files in this pull request and generated 6 comments.

Files not reviewed (1)
  • apps/web/package-lock.json: Language not supported

@@ -0,0 +1,11 @@
<script lang="ts">
import type { PageData } from './types';
"lib": ["ES2023", "DOM"],
"module": "esnext",
"types": ["vite/client"],
"types": ["vite/client", "@testing-library/jest-dom"],
"noFallthroughCasesInSwitch": true
},
"include": ["src"]
"include": ["src", "vitest-setup.ts"]
Comment thread apps/web/src/pages/ProfilePage.tsx Outdated
const [copyStatus, setCopyStatus] = useState<'success' | 'error'>('success');

useEffect(() => {
// eslint-disable-next-line react-hooks/set-state-in-effect
Comment thread apps/web/src/pages/ProfilePage.tsx Outdated

useEffect(() => {
if (!username) return;
// eslint-disable-next-line react-hooks/set-state-in-effect
Comment thread apps/web/src/pages/CardPage.tsx Outdated

useEffect(() => {
if (!id) return;
// eslint-disable-next-line react-hooks/set-state-in-effect
@ShantKhatri

Copy link
Copy Markdown
Collaborator

@ShantKhatri Kindly review my pr and merge it under the GSSOC 26 program

The PR is for testing, and the chore functionality changes are there.

@Satvik-art-creator

Copy link
Copy Markdown
Contributor Author

@ShantKhatri

Yes! I included the chore changes to fix existing ESLint bugs that were blocking the test builds. Since this PR also resolves those bugs, could you please add the type:bug and type:testing label as well? Let me know if it looks good to merge for GSSoC 26. Thanks! 🚀

@ShantKhatri

Copy link
Copy Markdown
Collaborator

Hi @Satvik-art-creator , We are not supposed to have changes in svelt, as devcard is fully migrated to React. Also for testing PR, we should not have changes in core.

@Satvik-art-creator

Copy link
Copy Markdown
Contributor Author

@ShantKhatri
Got it! The original issue description mentioned Svelte, so I was following that strictly. I will remove the Svelte files, rewrite the tests in React, and revert my changes to the core files so this PR is strictly for testing. I'll update the PR shortly! 🚀

Copilot AI review requested due to automatic review settings June 13, 2026 09:52

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

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated 4 comments.

Files not reviewed (1)
  • apps/web/package-lock.json: Generated file

Comment thread packages/shared/src/platforms.ts Outdated
Comment on lines +297 to +299
export function isSupportedPlatform(id: string): boolean {
return id in PLATFORMS;
}
Comment thread apps/web/src/pages/ProfilePage.test.tsx Outdated
};

it('renders loading state initially', () => {
(apiFetch as any).mockImplementation(() => new Promise(() => {}));
"lib": ["ES2023", "DOM"],
"module": "esnext",
"types": ["vite/client"],
"types": ["vite/client", "@testing-library/jest-dom"],
"noFallthroughCasesInSwitch": true
},
"include": ["src"]
"include": ["src", "vitest-setup.ts"]
- Extract useTheme hook and ThemeContext to separate files (react-refresh/only-export-components)

- Add async/await with cleanup in CardPage and ProfilePage effects (react-hooks/set-state-in-effect)

- Remove redundant mounted state in ProfilePage

- Replace 'any' with vi.mocked() and PublicProfile type in tests (no-explicit-any)

- Revert out-of-scope platforms.ts change
Copilot AI review requested due to automatic review settings June 13, 2026 10:06

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

Pull request overview

Copilot reviewed 11 out of 12 changed files in this pull request and generated 3 comments.

Files not reviewed (1)
  • apps/web/package-lock.json: Generated file

Comment thread apps/web/src/pages/ProfilePage.tsx Outdated
Comment on lines +24 to +44
useEffect(() => {
if (!username) return;
setLoading(true);
apiFetch<PublicProfile>(`/api/u/${username}?source=web`)
.then((data) => {
setProfile(data);
setError(null);
})
.catch(() => {
setProfile(null);
setError('User not found');
})
.finally(() => setLoading(false));

let cancelled = false;

const fetchProfile = async () => {
try {
const data = await apiFetch<PublicProfile>(`/api/u/${username}?source=web`);
if (!cancelled) {
setProfile(data);
setError(null);
}
} catch {
if (!cancelled) {
setProfile(null);
setError('User not found');
}
} finally {
if (!cancelled) setLoading(false);
}
};
Comment thread apps/web/src/pages/CardPage.tsx Outdated
Comment on lines +25 to +45
useEffect(() => {
if (!id) return;
setLoading(true);
apiFetch<PublicCard>(`/api/u/card/${id}`)
.then((data) => {
setCard(data);
setError(null);
})
.catch(() => {
setCard(null);
setError('Card not found');
})
.finally(() => setLoading(false));

let cancelled = false;

const fetchCard = async () => {
try {
const data = await apiFetch<PublicCard>(`/api/u/card/${id}`);
if (!cancelled) {
setCard(data);
setError(null);
}
} catch {
if (!cancelled) {
setCard(null);
setError('Card not found');
}
} finally {
if (!cancelled) setLoading(false);
}
};
import { ThemeContext } from './ThemeContext';
import type { ThemeContextValue } from './ThemeContext';

type Theme = 'light' | 'dark';
@Satvik-art-creator

Copy link
Copy Markdown
Contributor Author

Hi @ShantKhatri, all changes done — Svelte removed, tests rewritten in React, all ESLint errors fixed. CI passes now. Please review and merge under GSSoC '26. 🚀

@ShantKhatri

Copy link
Copy Markdown
Collaborator

Hi @Satvik-art-creator , We are not supposed to have changes in svelt, as devcard is fully migrated to React. Also for testing PR, we should not have changes in core.

Here with respect to core changes, I'm refering to changed under /src, which is not accepetable here.

Copilot AI review requested due to automatic review settings June 13, 2026 11:37

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

Pull request overview

Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.

Files not reviewed (1)
  • apps/web/package-lock.json: Generated file

"lib": ["ES2023", "DOM"],
"module": "esnext",
"types": ["vite/client"],
"types": ["vite/client", "@testing-library/jest-dom"],
"noFallthroughCasesInSwitch": true
},
"include": ["src"]
"include": ["src", "vitest-setup.ts"]
Comment on lines +59 to +61
await waitFor(() => {
expect(screen.getByText('Test User')).toBeInTheDocument();
});
Comment on lines +74 to +76
await waitFor(() => {
expect(screen.getByText('Profile not found')).toBeInTheDocument();
});
@Satvik-art-creator

Copy link
Copy Markdown
Contributor Author

@ShantKhatri Done! Reverted all core /src changes. The PR now only contains test files and test configuration — no changes to application source code. Please review. 🚀

@Satvik-art-creator

Copy link
Copy Markdown
Contributor Author

@ShantKhatri Kindly merge this if there has been no issue in the pr

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

Labels

gssoc:approved Required label for every approved PR. Gives the base +50 points and enables contribution tracking. web

Projects

None yet

Development

Successfully merging this pull request may close these issues.

web: add tests for user profile page render and 404 flow

4 participants