From cb96463bf4b512d9acad64662caa4501576c3a9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eline=20J=C3=A5sund?= Date: Wed, 18 Nov 2026 13:46:59 +0100 Subject: [PATCH 1/4] chore: as FetchDiscountedGenres --- Backend/Schema.ts | 1 + Backend/logic/GenresLogicBackend.ts | 16 ++++++++++++++ Backend/resolvers/GameResolvers.ts | 3 ++- .../FrontendLogic/MainPageLogicFrontend.ts | 5 +++++ Frontend/src/pages/MainPage/MainPage.tsx | 21 +++++++++++++++---- 5 files changed, 41 insertions(+), 5 deletions(-) diff --git a/Backend/Schema.ts b/Backend/Schema.ts index 38c43ca..46b5fd8 100644 --- a/Backend/Schema.ts +++ b/Backend/Schema.ts @@ -65,6 +65,7 @@ export const typeDefs = `#graphql isGameWishlisted(userId: Int!, gameId: Int!): Boolean! game(appid: Int!): Game genres: [String!]! + discountedGenres: [String!]! profile(userId: Int!): Profile gameOptions: [GameOption!]! totalGameCount( diff --git a/Backend/logic/GenresLogicBackend.ts b/Backend/logic/GenresLogicBackend.ts index cff35f5..a2cd4ce 100644 --- a/Backend/logic/GenresLogicBackend.ts +++ b/Backend/logic/GenresLogicBackend.ts @@ -4,3 +4,19 @@ export async function FetchGenres(): Promise { const { rows } = await pool.query(`SELECT genre_name FROM genres ORDER BY genre_name`) return rows.map((r) => r.genre_name as string) } + +export async function FetchGenresWithDiscounts(): Promise { + const { rows } = await pool.query( + `SELECT ge.genre_name + FROM genres ge + WHERE EXISTS ( + SELECT 1 + FROM genretogame gg + JOIN games g ON g.game_id = gg.game_id + WHERE gg.genre_id = ge.genre_id + AND g.discount_percent > 0 + ) + ORDER BY ge.genre_name` + ) + return rows.map((r) => r.genre_name as string) +} diff --git a/Backend/resolvers/GameResolvers.ts b/Backend/resolvers/GameResolvers.ts index 143d514..f45d6fb 100644 --- a/Backend/resolvers/GameResolvers.ts +++ b/Backend/resolvers/GameResolvers.ts @@ -1,5 +1,5 @@ import { pool } from '../DatabaseConnection.ts' -import { FetchGenres } from '../logic/GenresLogicBackend.ts' +import { FetchGenres, FetchGenresWithDiscounts } from '../logic/GenresLogicBackend.ts' import { GAME_COLUMNS } from '../types/GameColumns.ts' import { FetchDiscountedGames, @@ -123,6 +123,7 @@ export const gameQueryResolvers = { }, genres: () => FetchGenres(), + discountedGenres: () => FetchGenresWithDiscounts(), gameOptions: async () => { const { rows } = await pool.query( diff --git a/Frontend/src/FrontendLogic/MainPageLogicFrontend.ts b/Frontend/src/FrontendLogic/MainPageLogicFrontend.ts index 0ee588a..e72c8cd 100644 --- a/Frontend/src/FrontendLogic/MainPageLogicFrontend.ts +++ b/Frontend/src/FrontendLogic/MainPageLogicFrontend.ts @@ -88,3 +88,8 @@ export async function LoadDiscountedGames(genre: string): Promise { ) return data.discountedGames } + +export async function LoadDiscountedGenres(): Promise { + const data = await Gql<{ discountedGenres: string[] }>(`query { discountedGenres }`, {}) + return data.discountedGenres +} diff --git a/Frontend/src/pages/MainPage/MainPage.tsx b/Frontend/src/pages/MainPage/MainPage.tsx index 01437ed..2ff3deb 100644 --- a/Frontend/src/pages/MainPage/MainPage.tsx +++ b/Frontend/src/pages/MainPage/MainPage.tsx @@ -5,7 +5,8 @@ import { useDocumentTitle } from '../../hooks/useDocumentTitle' import { LoadTop3Games, LoadTopGamesByGenre, - LoadDiscountedGames + LoadDiscountedGames, + LoadDiscountedGenres } from '../../FrontendLogic/MainPageLogicFrontend' import { FetchGenres } from '../../FrontendLogic/SearchPageLogicFrontend' import { Link } from 'react-router-dom' @@ -22,11 +23,14 @@ import TopGames from '../../components/TopGames' export default function MainPage() { const [featuredGames, setFeaturedGames] = useState([]) const [genres, setGenres] = useState([]) + const [discountedGenres, setDiscountedGenres] = useState([]) const [isLoadingFeatured, setIsLoadingFeatured] = useState(true) const [isLoadingGenres, setIsLoadingGenres] = useState(true) + const [isLoadingDiscountedGenres, setIsLoadingDiscountedGenres] = useState(true) // One error per section, so each failure is shown inside the box it belongs to const [featuredError, setFeaturedError] = useState(null) const [genresError, setGenresError] = useState(null) + const [discountedGenresError, setDiscountedGenresError] = useState(null) const [reviewsError, setReviewsError] = useState(null) const [recentReviews, setRecentReviews] = useState([]) const [isLoadingReviews, setIsLoadingReviews] = useState(true) @@ -58,6 +62,15 @@ export default function MainPage() { if (!cancelled) setIsLoadingGenres(false) }) + LoadDiscountedGenres() + .then((loaded) => { + if (!cancelled) setDiscountedGenres([...loaded].sort()) + }) + .catch(ReportError(setDiscountedGenresError, 'Could not load discounted genres')) + .finally(() => { + if (!cancelled) setIsLoadingDiscountedGenres(false) + }) + GetRecentReviews() .then((reviews) => { if (!cancelled) setRecentReviews(reviews) @@ -133,9 +146,9 @@ export default function MainPage() { /> Date: Wed, 18 Nov 2026 13:47:08 +0100 Subject: [PATCH 2/4] test: update testing --- Backend/tests/GenresBackend.test.ts | 18 ++++++++++- Frontend/src/tests/MainPage.test.tsx | 46 +++++++++++++++++++++++++--- 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/Backend/tests/GenresBackend.test.ts b/Backend/tests/GenresBackend.test.ts index 3e539a5..5484891 100644 --- a/Backend/tests/GenresBackend.test.ts +++ b/Backend/tests/GenresBackend.test.ts @@ -5,7 +5,7 @@ const { Query } = vi.hoisted(() => ({ Query: vi.fn() })) vi.mock('../DatabaseConnection.ts', () => ({ pool: { query: Query } })) -import { FetchGenres } from '../logic/GenresLogicBackend.ts' +import { FetchGenres, FetchGenresWithDiscounts } from '../logic/GenresLogicBackend.ts' describe('fetchGenres (backend)', () => { beforeEach(() => { @@ -57,4 +57,20 @@ describe('fetchGenres (backend)', () => { await expect(FetchGenres()).rejects.toThrow('connection refused') }) + + it('returns only genres that have at least one discounted game', async () => { + Query.mockResolvedValue({ + rows: [{ genre_name: 'Action' }, { genre_name: 'Indie' }] + }) + + expect(await FetchGenresWithDiscounts()).toEqual(['Action', 'Indie']) + + const sql = String(Query.mock.calls[0][0]) + expect(sql).toContain('FROM genres ge') + expect(sql).toContain('WHERE EXISTS') + expect(sql).toContain('FROM genretogame gg') + expect(sql).toContain('JOIN games g ON g.game_id = gg.game_id') + expect(sql).toContain('g.discount_percent > 0') + expect(sql).toContain('ORDER BY ge.genre_name') + }) }) diff --git a/Frontend/src/tests/MainPage.test.tsx b/Frontend/src/tests/MainPage.test.tsx index 6602af8..5ab1d1f 100644 --- a/Frontend/src/tests/MainPage.test.tsx +++ b/Frontend/src/tests/MainPage.test.tsx @@ -10,6 +10,7 @@ const { LoadTop3Games, LoadTopGamesByGenre, LoadDiscountedGames, + LoadDiscountedGenres, FetchGenres, GetRecentReviews, UseMediaQuery @@ -17,6 +18,7 @@ const { LoadTop3Games: vi.fn<() => Promise>(), LoadTopGamesByGenre: vi.fn<(genre: string) => Promise>(), LoadDiscountedGames: vi.fn<(genre: string) => Promise>(), + LoadDiscountedGenres: vi.fn<() => Promise>(), FetchGenres: vi.fn<() => Promise>(), GetRecentReviews: vi.fn<() => Promise>(), UseMediaQuery: vi.fn<(query: string) => boolean>(() => false) @@ -25,7 +27,13 @@ const { // Keep the real sessionStorage helpers, replace only the network loaders vi.mock('../FrontendLogic/MainPageLogicFrontend', async (importOriginal) => { const actual = await importOriginal() - return { ...actual, LoadTop3Games, LoadTopGamesByGenre, LoadDiscountedGames } + return { + ...actual, + LoadTop3Games, + LoadTopGamesByGenre, + LoadDiscountedGames, + LoadDiscountedGenres + } }) vi.mock('../FrontendLogic/SearchPageLogicFrontend', () => ({ FetchGenres })) vi.mock('../FrontendLogic/ReviewLogicFrontend', () => ({ GetRecentReviews })) @@ -114,6 +122,7 @@ describe('MainPage', () => { LoadTop3Games, LoadTopGamesByGenre, LoadDiscountedGames, + LoadDiscountedGenres, FetchGenres, GetRecentReviews ]) { @@ -123,6 +132,7 @@ describe('MainPage', () => { LoadTop3Games.mockResolvedValue([]) LoadTopGamesByGenre.mockResolvedValue([]) LoadDiscountedGames.mockResolvedValue([]) + LoadDiscountedGenres.mockResolvedValue([]) FetchGenres.mockResolvedValue([]) UseMediaQuery.mockReset() UseMediaQuery.mockReturnValue(false) @@ -137,6 +147,7 @@ describe('MainPage', () => { it('shows loading states while data is being fetched', () => { LoadTop3Games.mockReturnValue(new Promise(() => {})) FetchGenres.mockReturnValue(new Promise(() => {})) + LoadDiscountedGenres.mockReturnValue(new Promise(() => {})) RenderMainPage() @@ -145,6 +156,7 @@ describe('MainPage', () => { expect(screen.getByText('Loading reviews...')).toBeTruthy() expect(LoadTop3Games).toHaveBeenCalledOnce() expect(FetchGenres).toHaveBeenCalledOnce() + expect(LoadDiscountedGenres).toHaveBeenCalledOnce() expect(LoadTopGamesByGenre).not.toHaveBeenCalled() expect(LoadDiscountedGames).not.toHaveBeenCalled() expect( @@ -177,6 +189,7 @@ describe('MainPage', () => { MakeReview(1, 1, 'TestUser1', 5, 'Great game') ]) FetchGenres.mockResolvedValue(['Adventure', 'Action']) + LoadDiscountedGenres.mockResolvedValue(['Action']) LoadTopGamesByGenre.mockImplementation( GamesByGenre({ Action: [MakeGame(1, 'Action, Adventure', '25'), MakeGame(4, 'Action')] @@ -218,6 +231,7 @@ describe('MainPage', () => { 'Action', 'Adventure' ]) + expect(Array.from(selectors[1].options).map((option) => option.value)).toEqual(['Action']) expect(LoadTopGamesByGenre).toHaveBeenCalledWith('Action') expect(LoadDiscountedGames).toHaveBeenCalledWith('Action') @@ -262,6 +276,7 @@ describe('MainPage', () => { sessionStorage.setItem('GameStart:genreMainpage:top10', JSON.stringify('Action')) sessionStorage.setItem('GameStart:genreMainpage:discounts', JSON.stringify('Adventure')) FetchGenres.mockResolvedValue(['Action', 'Adventure']) + LoadDiscountedGenres.mockResolvedValue(['Action', 'Adventure']) LoadTopGamesByGenre.mockImplementation(GamesByGenre({ Action: [MakeGame(1, 'Action')] })) LoadDiscountedGames.mockImplementation( GamesByGenre({ Adventure: [MakeGame(2, 'Adventure', '25')] }) @@ -302,6 +317,7 @@ describe('MainPage', () => { it('loads discounted games per genre and links to the search page', async () => { FetchGenres.mockResolvedValue(['Action', 'Adventure']) + LoadDiscountedGenres.mockResolvedValue(['Action', 'Adventure']) LoadDiscountedGames.mockImplementation( GamesByGenre({ Action: [MakeGame(2, 'Action', '25')], @@ -393,15 +409,33 @@ describe('MainPage', () => { RenderMainPage() - const alerts = await screen.findAllByRole('alert') - expect(alerts).toHaveLength(2) - for (const alert of alerts) expect(alert.textContent).toContain('Genres unavailable') - expect(screen.queryByText('No games found for this genre.')).toBeNull() + const topGamesSection = SectionOf('Top 10 Games by Genre') + expect((await within(topGamesSection).findByRole('alert')).textContent).toContain( + 'Genres unavailable' + ) + expect( + within(SectionOf('Discounts by Genre')).queryByRole('alert') + ).toBeNull() + expect(within(topGamesSection).queryByText('No games found for this genre.')).toBeNull() expect((screen.getAllByLabelText('Choose a genre')[0] as HTMLSelectElement).disabled).toBe( true ) }) + it('shows a separate error when discounted genres fail to load', async () => { + LoadDiscountedGenres.mockRejectedValue(new Error('Discount genres unavailable')) + + RenderMainPage() + + const discountSection = SectionOf('Discounts by Genre') + expect((await within(discountSection).findByRole('alert')).textContent).toContain( + 'Discount genres unavailable' + ) + expect( + within(SectionOf('Top 10 Games by Genre')).queryByRole('alert') + ).toBeNull() + }) + it('shows an error inside a section when its games fail to load', async () => { FetchGenres.mockResolvedValue(['Action']) LoadTopGamesByGenre.mockRejectedValue(new Error('Server down')) @@ -418,6 +452,7 @@ describe('MainPage', () => { it('shows one game per genre row on phone-sized screens', async () => { UseMediaQuery.mockImplementation((query) => query.includes('43.75rem')) FetchGenres.mockResolvedValue(['Action']) + LoadDiscountedGenres.mockResolvedValue(['Action']) const games = [ MakeGame(1, 'Action', '25'), MakeGame(2, 'Action', '50'), @@ -443,6 +478,7 @@ describe('MainPage', () => { }) ) FetchGenres.mockReturnValue(new Promise(() => {})) + LoadDiscountedGenres.mockReturnValue(new Promise(() => {})) const { unmount } = RenderMainPage() unmount() From 264719f40e7927c464683a0fb1479a0b37fb63c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eline=20J=C3=A5sund?= Date: Wed, 18 Nov 2026 13:50:56 +0100 Subject: [PATCH 3/4] fix: handle lint error --- .../ActiveGameCard/ActiveGameCard.tsx | 85 ++++++++++++++----- 1 file changed, 62 insertions(+), 23 deletions(-) diff --git a/Frontend/src/components/ActiveGameCard/ActiveGameCard.tsx b/Frontend/src/components/ActiveGameCard/ActiveGameCard.tsx index 824496e..5d0e587 100644 --- a/Frontend/src/components/ActiveGameCard/ActiveGameCard.tsx +++ b/Frontend/src/components/ActiveGameCard/ActiveGameCard.tsx @@ -17,43 +17,64 @@ type ActiveGameCardProps = { onAddToWishlist?: (gameId: number) => void } +type WishlistCheckResult = + | { userId: number; gameId: number; status: 'loaded'; isWishlisted: boolean } + | { userId: number; gameId: number; status: 'error'; message: string } + export default function ActiveGameCard({ game, onAddToWishlist, onRemoveFromWishlist }: ActiveGameCardProps) { - const [isWishlisted, setIsWishlisted] = useState(false) - const [isChecking, setIsChecking] = useState(() => GetSavedUser() !== null) + const [wishlistCheck, setWishlistCheck] = useState(null) const [isBusy, setIsBusy] = useState(false) - const [error, setError] = useState(null) - + const [actionError, setActionError] = useState<{ + userId: number | null + gameId: number + message: string + } | null>(null) + const user = GetSavedUser() const userId = user?.id ?? null const isLoggedIn = userId !== null + const currentCheck = + userId !== null && wishlistCheck?.userId === userId && wishlistCheck.gameId === game.id + ? wishlistCheck + : null + const isWishlisted = currentCheck?.status === 'loaded' && currentCheck.isWishlisted + const isChecking = isLoggedIn && currentCheck === null + const error = + (currentCheck?.status === 'error' ? currentCheck.message : null) ?? + (actionError?.userId === userId && actionError.gameId === game.id + ? actionError.message + : null) // Finds out if the signed in user already has this game on their wishlist useEffect(() => { let cancelled = false - if (userId == null) { - setIsChecking(false) - setIsWishlisted(false) - return - } - - setIsChecking(true) - setError(null) + if (userId == null) return FetchIsGameWishlistedFrontend(userId, game.id) .then((wishlisted) => { - if (!cancelled) - setIsWishlisted(wishlisted) + if (!cancelled) { + setWishlistCheck({ + userId, + gameId: game.id, + status: 'loaded', + isWishlisted: wishlisted + }) + } }) .catch(() => { - if (!cancelled) setError('Could not check your wishlist') - }) - .finally(() => { - if (!cancelled) setIsChecking(false) + if (!cancelled) { + setWishlistCheck({ + userId, + gameId: game.id, + status: 'error', + message: 'Could not check your wishlist' + }) + } }) return () => { @@ -65,24 +86,42 @@ export default function ActiveGameCard({ async function HandleToggleWishlist() { const user = GetSavedUser() if (!user) { - setError('You need to sign in to change your wishlist') + setActionError({ + userId: null, + gameId: game.id, + message: 'You need to sign in to change your wishlist' + }) return } setIsBusy(true) - setError(null) + setActionError(null) try { if (isWishlisted) { await RemoveFromWishlistFrontend(user.id, game.id) - setIsWishlisted(false) + setWishlistCheck({ + userId: user.id, + gameId: game.id, + status: 'loaded', + isWishlisted: false + }) onRemoveFromWishlist?.(game.id) } else { await AddToWishlistFrontend(user.id, game.id) - setIsWishlisted(true) + setWishlistCheck({ + userId: user.id, + gameId: game.id, + status: 'loaded', + isWishlisted: true + }) onAddToWishlist?.(game.id) } } catch (err: unknown) { - setError(err instanceof Error ? err.message : 'Could not update wishlist') + setActionError({ + userId: user.id, + gameId: game.id, + message: err instanceof Error ? err.message : 'Could not update wishlist' + }) } finally { setIsBusy(false) } From 7cf7090d8ced363bd6c1dbcf96d45e76ca2d88a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eline=20J=C3=A5sund?= Date: Wed, 18 Nov 2026 13:51:08 +0100 Subject: [PATCH 4/4] chore: run prettier and lint --- Backend/resolvers/WishlistResolvers.ts | 4 +-- .../FrontendLogic/WishlistLogicFrontend.ts | 1 - .../ActiveGameCardInfo/ActiveGameCardInfo.css | 2 +- .../ActiveGameCardInfo/ActiveGameCardInfo.tsx | 2 +- .../ActiveGameCardReviews.css | 2 +- .../ActiveGameCardReviews.tsx | 2 +- Frontend/src/tests/ActiveGameCard.test.tsx | 32 ++++++------------- Frontend/src/tests/MainPage.test.tsx | 8 ++--- 8 files changed, 18 insertions(+), 35 deletions(-) diff --git a/Backend/resolvers/WishlistResolvers.ts b/Backend/resolvers/WishlistResolvers.ts index 70345ba..30b6701 100644 --- a/Backend/resolvers/WishlistResolvers.ts +++ b/Backend/resolvers/WishlistResolvers.ts @@ -12,7 +12,7 @@ export const wishlistQueryResolvers = { { token }: GraphQLContext ): Promise => { await RequireUser(token, userId) - + const { rows } = await pool.query( `SELECT ${GAME_COLUMNS} FROM wishlist w @@ -29,7 +29,7 @@ export const wishlistQueryResolvers = { { token }: GraphQLContext ): Promise => { await RequireUser(token, userId) - + const { rows } = await pool.query( `SELECT EXISTS ( SELECT 1 diff --git a/Frontend/src/FrontendLogic/WishlistLogicFrontend.ts b/Frontend/src/FrontendLogic/WishlistLogicFrontend.ts index f2ea76a..724e4bf 100644 --- a/Frontend/src/FrontendLogic/WishlistLogicFrontend.ts +++ b/Frontend/src/FrontendLogic/WishlistLogicFrontend.ts @@ -66,4 +66,3 @@ export async function FetchIsGameWishlistedFrontend( return data.isGameWishlisted } - diff --git a/Frontend/src/components/ActiveGameCardInfo/ActiveGameCardInfo.css b/Frontend/src/components/ActiveGameCardInfo/ActiveGameCardInfo.css index 3716887..7a0ffb9 100644 --- a/Frontend/src/components/ActiveGameCardInfo/ActiveGameCardInfo.css +++ b/Frontend/src/components/ActiveGameCardInfo/ActiveGameCardInfo.css @@ -41,4 +41,4 @@ align-items: flex-start; flex-direction: column; } -} \ No newline at end of file +} diff --git a/Frontend/src/components/ActiveGameCardInfo/ActiveGameCardInfo.tsx b/Frontend/src/components/ActiveGameCardInfo/ActiveGameCardInfo.tsx index a87b53d..f79bcbd 100644 --- a/Frontend/src/components/ActiveGameCardInfo/ActiveGameCardInfo.tsx +++ b/Frontend/src/components/ActiveGameCardInfo/ActiveGameCardInfo.tsx @@ -61,4 +61,4 @@ export default function ActiveGameCardInfo({ game }: ActiveGameInfoProps) { ) -} \ No newline at end of file +} diff --git a/Frontend/src/components/ActiveGameCardReviews/ActiveGameCardReviews.css b/Frontend/src/components/ActiveGameCardReviews/ActiveGameCardReviews.css index 9b7aae3..e8e4c3e 100644 --- a/Frontend/src/components/ActiveGameCardReviews/ActiveGameCardReviews.css +++ b/Frontend/src/components/ActiveGameCardReviews/ActiveGameCardReviews.css @@ -8,4 +8,4 @@ .activeGameReviewsCard { display: flex; min-height: 0; -} \ No newline at end of file +} diff --git a/Frontend/src/components/ActiveGameCardReviews/ActiveGameCardReviews.tsx b/Frontend/src/components/ActiveGameCardReviews/ActiveGameCardReviews.tsx index 9d4a40a..dd98136 100644 --- a/Frontend/src/components/ActiveGameCardReviews/ActiveGameCardReviews.tsx +++ b/Frontend/src/components/ActiveGameCardReviews/ActiveGameCardReviews.tsx @@ -71,4 +71,4 @@ export default function ActiveGameCardReviews({ gameId }: ActiveGameReviewsProps /> ) -} \ No newline at end of file +} diff --git a/Frontend/src/tests/ActiveGameCard.test.tsx b/Frontend/src/tests/ActiveGameCard.test.tsx index 20e5460..08a7a3f 100644 --- a/Frontend/src/tests/ActiveGameCard.test.tsx +++ b/Frontend/src/tests/ActiveGameCard.test.tsx @@ -1,21 +1,16 @@ - // @vitest-environment jsdom import { cleanup, render, screen, fireEvent, waitFor } from '@testing-library/react' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { MemoryRouter } from 'react-router-dom' import type { GameData } from '../types/Game' -const { - getSavedUserMock, - addToWishlistMock, - removeFromWishlistMock, - fetchIsGameWishlistedMock -} = vi.hoisted(() => ({ - getSavedUserMock: vi.fn(), - addToWishlistMock: vi.fn(), - removeFromWishlistMock: vi.fn(), - fetchIsGameWishlistedMock: vi.fn() -})) +const { getSavedUserMock, addToWishlistMock, removeFromWishlistMock, fetchIsGameWishlistedMock } = + vi.hoisted(() => ({ + getSavedUserMock: vi.fn(), + addToWishlistMock: vi.fn(), + removeFromWishlistMock: vi.fn(), + fetchIsGameWishlistedMock: vi.fn() + })) vi.mock('../context/AuthContext', () => ({ UseAuth: () => ({ user: null }) @@ -112,7 +107,6 @@ describe('ActiveGameCard', () => { }) }) - describe('wishlist', () => { it('shows the Add to wishlist button when the game is not wishlisted', async () => { getSavedUserMock.mockReturnValue({ id: 1 }) @@ -120,9 +114,7 @@ describe('ActiveGameCard', () => { RenderActiveGameCard(testGame) - expect( - await screen.findByRole('button', { name: 'Add to wishlist' }) - ).not.toBeNull() + expect(await screen.findByRole('button', { name: 'Add to wishlist' })).not.toBeNull() expect(fetchIsGameWishlistedMock).toHaveBeenCalledWith(1, testGame.id) }) @@ -175,9 +167,7 @@ describe('ActiveGameCard', () => { expect(removeFromWishlistMock).toHaveBeenCalledWith(1, testGame.id) }) - expect( - await screen.findByRole('button', { name: 'Add to wishlist' }) - ).not.toBeNull() + expect(await screen.findByRole('button', { name: 'Add to wishlist' })).not.toBeNull() }) it('does not show the wishlist button when the user is not logged in', () => { @@ -185,9 +175,7 @@ describe('ActiveGameCard', () => { RenderActiveGameCard(testGame) - expect( - screen.queryByRole('button', { name: 'Add to wishlist' }) - ).toBeNull() + expect(screen.queryByRole('button', { name: 'Add to wishlist' })).toBeNull() expect(fetchIsGameWishlistedMock).not.toHaveBeenCalled() }) diff --git a/Frontend/src/tests/MainPage.test.tsx b/Frontend/src/tests/MainPage.test.tsx index 5ab1d1f..dcf059c 100644 --- a/Frontend/src/tests/MainPage.test.tsx +++ b/Frontend/src/tests/MainPage.test.tsx @@ -413,9 +413,7 @@ describe('MainPage', () => { expect((await within(topGamesSection).findByRole('alert')).textContent).toContain( 'Genres unavailable' ) - expect( - within(SectionOf('Discounts by Genre')).queryByRole('alert') - ).toBeNull() + expect(within(SectionOf('Discounts by Genre')).queryByRole('alert')).toBeNull() expect(within(topGamesSection).queryByText('No games found for this genre.')).toBeNull() expect((screen.getAllByLabelText('Choose a genre')[0] as HTMLSelectElement).disabled).toBe( true @@ -431,9 +429,7 @@ describe('MainPage', () => { expect((await within(discountSection).findByRole('alert')).textContent).toContain( 'Discount genres unavailable' ) - expect( - within(SectionOf('Top 10 Games by Genre')).queryByRole('alert') - ).toBeNull() + expect(within(SectionOf('Top 10 Games by Genre')).queryByRole('alert')).toBeNull() }) it('shows an error inside a section when its games fail to load', async () => {