From fa0874e270a0f2057b8a7537c9633c5d16bd142b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eline=20J=C3=A5sund?= Date: Tue, 17 Nov 2026 14:00:38 +0100 Subject: [PATCH 1/5] chore: update save on favorite game change --- .../components/ProfileEditor/ProfileEditor.tsx | 4 ++-- Frontend/src/pages/ProfilePage/ProfilePage.tsx | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Frontend/src/components/ProfileEditor/ProfileEditor.tsx b/Frontend/src/components/ProfileEditor/ProfileEditor.tsx index bbda504..ef54f8f 100644 --- a/Frontend/src/components/ProfileEditor/ProfileEditor.tsx +++ b/Frontend/src/components/ProfileEditor/ProfileEditor.tsx @@ -24,7 +24,7 @@ interface ProfileCardProps { onSave: (input: { description: string | null setup: string | null - favouriteGame: number | null + favouriteGame: GameOption | null }) => Promise } @@ -124,7 +124,7 @@ export default function ProfileCard({ profile, gameOptions, onSave }: ProfileCar await onSave({ description: description.trim() || null, setup: setup || null, - favouriteGame: game?.appid ?? null + favouriteGame: game }) setMessage({ type: 'success', text: 'Profile saved.' }) } catch (err) { diff --git a/Frontend/src/pages/ProfilePage/ProfilePage.tsx b/Frontend/src/pages/ProfilePage/ProfilePage.tsx index 5f7c31b..eb3b329 100644 --- a/Frontend/src/pages/ProfilePage/ProfilePage.tsx +++ b/Frontend/src/pages/ProfilePage/ProfilePage.tsx @@ -77,10 +77,22 @@ export default function ProfilePage() { async function HandleSave(input: { description: string | null setup: string | null - favouriteGame: number | null + favouriteGame: GameOption | null }) { if (userId === undefined) return - setProfile(await UpdateProfileFrontend(userId, input)) + + const updatedProfile = await UpdateProfileFrontend(userId, { + description: input.description, + setup: input.setup, + favouriteGame: input.favouriteGame?.appid ?? null + }) + + setProfile(updatedProfile) + + const savedGame = + updatedProfile.favouriteGame === input.favouriteGame?.appid ? input.favouriteGame : null + + setGameOptions(savedGame ? [savedGame] : []) setIsEditing(false) } From 226d1bb83b662725bf5ee077237222ee9664b6e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eline=20J=C3=A5sund?= Date: Tue, 17 Nov 2026 14:05:42 +0100 Subject: [PATCH 2/5] chore: remove unused resolver --- Backend/Schema.ts | 1 - Backend/resolvers/GameResolvers.ts | 7 ------- 2 files changed, 8 deletions(-) diff --git a/Backend/Schema.ts b/Backend/Schema.ts index 398d8ac..02e551f 100644 --- a/Backend/Schema.ts +++ b/Backend/Schema.ts @@ -65,7 +65,6 @@ export const typeDefs = `#graphql game(appid: Int!): Game genres: [String!]! profile(userId: Int!): Profile - gameOptions: [GameOption!]! totalGameCount( search: String genres: [String!] diff --git a/Backend/resolvers/GameResolvers.ts b/Backend/resolvers/GameResolvers.ts index 143d514..9ce697f 100644 --- a/Backend/resolvers/GameResolvers.ts +++ b/Backend/resolvers/GameResolvers.ts @@ -124,13 +124,6 @@ export const gameQueryResolvers = { genres: () => FetchGenres(), - gameOptions: async () => { - const { rows } = await pool.query( - `SELECT game_id AS appid, game_name AS name FROM games ORDER BY game_name` - ) - return rows - }, - top3Games: () => FetchTop3Games(), topGamesByGenre: (_parent: unknown, { genre }: { genre: string }) => FetchTop10GamesPerGenre(genre), From 9f59e27b7166f4922bf909414bcac5f3c48f088a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eline=20J=C3=A5sund?= Date: Tue, 17 Nov 2026 14:13:38 +0100 Subject: [PATCH 3/5] test: add profilePage test --- Frontend/src/tests/ProfilePage.test.tsx | 141 ++++++++++++++++++++++++ tsconfig.app.json | 1 + 2 files changed, 142 insertions(+) create mode 100644 Frontend/src/tests/ProfilePage.test.tsx diff --git a/Frontend/src/tests/ProfilePage.test.tsx b/Frontend/src/tests/ProfilePage.test.tsx new file mode 100644 index 0000000..70c9edb --- /dev/null +++ b/Frontend/src/tests/ProfilePage.test.tsx @@ -0,0 +1,141 @@ +// @vitest-environment jsdom +import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import type { Profile } from '../../../Backend/logic/ProfileLogicBackend' +import type { GameOption } from '../FrontendLogic/ProfileLogicFrontend' + +type ProfileUpdate = { + description: string | null + setup: string | null + favouriteGame: number | null +} + +type ProfileSave = Omit & { + favouriteGame: GameOption | null +} + +const { FetchGameOptions, FetchProfileFrontend, UpdateProfileFrontend, UseAuth } = vi.hoisted( + () => ({ + FetchGameOptions: vi.fn< + (options?: { appid?: number; limit?: number }) => Promise + >(), + FetchProfileFrontend: vi.fn<(userId: number) => Promise>(), + UpdateProfileFrontend: vi.fn< + (userId: number, input: ProfileUpdate) => Promise + >(), + UseAuth: vi.fn<() => { user: { id: number } | null }>() + }) +) + +vi.mock('../FrontendLogic/ProfileLogicFrontend', () => ({ + FetchGameOptions, + FetchProfileFrontend, + UpdateProfileFrontend +})) +vi.mock('../context/AuthContext', () => ({ UseAuth })) +vi.mock('../components/Header/Header', () => ({ default: () => null })) +vi.mock('../components/Footer/Footer', () => ({ default: () => null })) +vi.mock('../components/PageHeading/PageHeading', () => ({ + default: ({ title, actions }: { title: string; actions?: React.ReactNode }) => ( +
+

{title}

+ {actions} +
+ ) +})) +vi.mock('../components/ProfileCard', () => ({ + default: ({ favouriteGame }: { favouriteGame: GameOption | null }) => ( +

{favouriteGame?.name ?? 'No favourite game provided'}

+ ) +})) +vi.mock('../components/ProfileEditor/ProfileEditor', () => ({ + default: ({ onSave }: { onSave: (input: ProfileSave) => Promise }) => ( + <> + + + + ) +})) +vi.mock('../components/UserReviews/UserReviews', () => ({ default: () => null })) + +import ProfilePage from '../pages/ProfilePage/ProfilePage' + +const INITIAL_PROFILE: Profile = { + username: 'test-user', + description: 'Original profile', + setup: 'PC', + favouriteGame: 570 +} + +describe('ProfilePage favorite game saving', () => { + beforeEach(() => { + FetchGameOptions.mockReset() + FetchProfileFrontend.mockReset() + UpdateProfileFrontend.mockReset() + UseAuth.mockReset() + + UseAuth.mockReturnValue({ user: { id: 7 } }) + FetchProfileFrontend.mockResolvedValue(INITIAL_PROFILE) + FetchGameOptions.mockResolvedValue([{ appid: 570, name: 'Dota 2' }]) + UpdateProfileFrontend.mockImplementation(async (_userId, input) => ({ + ...INITIAL_PROFILE, + ...input + })) + }) + + afterEach(() => cleanup()) + + it('saves the selected game id and immediately displays its name', async () => { + render() + + expect(await screen.findByText('Dota 2')).toBeTruthy() + fireEvent.click(screen.getByRole('button', { name: 'Edit profile' })) + fireEvent.click(screen.getByRole('button', { name: 'Save selected game' })) + + await waitFor(() => { + expect(UpdateProfileFrontend).toHaveBeenCalledWith(7, { + description: 'Updated profile', + setup: 'PC', + favouriteGame: 730 + }) + }) + expect(await screen.findByText('Counter-Strike 2')).toBeTruthy() + }) + + it('clears the displayed favorite game when the selection is removed', async () => { + render() + + expect(await screen.findByText('Dota 2')).toBeTruthy() + fireEvent.click(screen.getByRole('button', { name: 'Edit profile' })) + fireEvent.click(screen.getByRole('button', { name: 'Clear favorite game' })) + + await waitFor(() => { + expect(UpdateProfileFrontend).toHaveBeenCalledWith(7, { + description: 'Updated profile', + setup: 'PC', + favouriteGame: null + }) + }) + expect(await screen.findByText('No favourite game provided')).toBeTruthy() + }) +}) diff --git a/tsconfig.app.json b/tsconfig.app.json index d209b68..06b9374 100644 --- a/tsconfig.app.json +++ b/tsconfig.app.json @@ -38,6 +38,7 @@ "Frontend/src/tests/TokenFrontend.test.ts", "Frontend/src/tests/PageHeading.test.tsx", "Frontend/src/tests/ProfileLogicFrontend.test.ts", + "Frontend/src/tests/ProfilePage.test.tsx", "Frontend/src/tests/PassiveGameCard.test.tsx", "Frontend/src/tests/ReviewCard.test.tsx", "Frontend/src/tests/ReviewLogicFrontend.test.ts", From 6e5eafb6f4237e8280bdb81f58f68923cd61c304 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eline=20J=C3=A5sund?= Date: Tue, 17 Nov 2026 14:16:19 +0100 Subject: [PATCH 4/5] chore: run prettier --- Frontend/src/tests/ProfilePage.test.tsx | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Frontend/src/tests/ProfilePage.test.tsx b/Frontend/src/tests/ProfilePage.test.tsx index 70c9edb..2dbcb1a 100644 --- a/Frontend/src/tests/ProfilePage.test.tsx +++ b/Frontend/src/tests/ProfilePage.test.tsx @@ -16,13 +16,10 @@ type ProfileSave = Omit & { const { FetchGameOptions, FetchProfileFrontend, UpdateProfileFrontend, UseAuth } = vi.hoisted( () => ({ - FetchGameOptions: vi.fn< - (options?: { appid?: number; limit?: number }) => Promise - >(), + FetchGameOptions: + vi.fn<(options?: { appid?: number; limit?: number }) => Promise>(), FetchProfileFrontend: vi.fn<(userId: number) => Promise>(), - UpdateProfileFrontend: vi.fn< - (userId: number, input: ProfileUpdate) => Promise - >(), + UpdateProfileFrontend: vi.fn<(userId: number, input: ProfileUpdate) => Promise>(), UseAuth: vi.fn<() => { user: { id: number } | null }>() }) ) From d7484bc7b86bda80134c84607342a19a3fac03b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eline=20J=C3=A5sund?= Date: Wed, 18 Nov 2026 12:59:11 +0100 Subject: [PATCH 5/5] style: add green background on item selected in profile --- .../src/components/ProfileEditor/EditProfile.css | 6 ++++++ .../src/components/ProfileEditor/ProfileEditor.tsx | 13 ++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Frontend/src/components/ProfileEditor/EditProfile.css b/Frontend/src/components/ProfileEditor/EditProfile.css index bbd4d4e..6c92185 100644 --- a/Frontend/src/components/ProfileEditor/EditProfile.css +++ b/Frontend/src/components/ProfileEditor/EditProfile.css @@ -57,6 +57,12 @@ width: 100%; } +.profile-game-listbox.MuiAutocomplete-listbox + .profile-game-option.MuiAutocomplete-option[aria-selected='true'], +.MuiMenu-list .profile-setup-option.MuiMenuItem-root.Mui-selected { + background-color: var(--secondary-component-color); +} + /* Field borders and the focused label colour are styled in Global.css */ .page-shell .profile-card .MuiInputLabel-root { color: var(--primary-text-color); diff --git a/Frontend/src/components/ProfileEditor/ProfileEditor.tsx b/Frontend/src/components/ProfileEditor/ProfileEditor.tsx index ef54f8f..c3c2fab 100644 --- a/Frontend/src/components/ProfileEditor/ProfileEditor.tsx +++ b/Frontend/src/components/ProfileEditor/ProfileEditor.tsx @@ -195,6 +195,7 @@ export default function ProfileCard({ profile, gameOptions, onSave }: ProfileCar filterOptions={(options) => options} slotProps={{ listbox: { + className: 'profile-game-listbox', onScroll: (event) => { const listbox = event.currentTarget if ( @@ -211,7 +212,11 @@ export default function ProfileCard({ profile, gameOptions, onSave }: ProfileCar renderOption={(props, option) => { const { key: _key, ...rest } = props return ( -
  • +
  • {option.name}
  • ) @@ -234,9 +239,11 @@ export default function ProfileCard({ profile, gameOptions, onSave }: ProfileCar value={setup} onChange={(e) => setSetup(e.target.value)} > - None + + None + {SETUP_OPTIONS.map((option) => ( - + {option} ))}