diff --git a/Frontend/src/components/ActiveGameCardInfo/ActiveGameCardInfo.tsx b/Frontend/src/components/ActiveGameCardInfo/ActiveGameCardInfo.tsx index a87b53d..9f17d0f 100644 --- a/Frontend/src/components/ActiveGameCardInfo/ActiveGameCardInfo.tsx +++ b/Frontend/src/components/ActiveGameCardInfo/ActiveGameCardInfo.tsx @@ -1,6 +1,6 @@ import { Box, Card, CardContent, Chip, Divider, Typography } from '@mui/material' import './ActiveGameCardInfo.css' -import type { GameData } from '../../types/Game' +import { type GameData, FormatPrice } from '../../types/Game' type ActiveGameInfoProps = { game: GameData @@ -31,12 +31,12 @@ export default function ActiveGameCardInfo({ game }: ActiveGameInfoProps) { className={`activeGamePrice${showOriginalPrice ? ' activeGameSalePrice' : ''}`} component="p" > - {game.price.toFixed(2)} $ + {FormatPrice(game.price)} {showOriginalPrice && ( Original price: - {game.originalPrice!.toFixed(2)} $ + {FormatPrice(game.originalPrice!)} )} diff --git a/Frontend/src/components/PassiveGameCard/PassiveGameCard.tsx b/Frontend/src/components/PassiveGameCard/PassiveGameCard.tsx index be5e738..0e48e2d 100644 --- a/Frontend/src/components/PassiveGameCard/PassiveGameCard.tsx +++ b/Frontend/src/components/PassiveGameCard/PassiveGameCard.tsx @@ -6,7 +6,7 @@ import Typography from '@mui/material/Typography' import CardActionArea from '@mui/material/CardActionArea' import { Link } from 'react-router-dom' import { useLayoutEffect, useRef, useState } from 'react' -import type { PassiveGameData } from '../../types/Game' +import { type PassiveGameData, FormatPrice } from '../../types/Game' type Props = { game: PassiveGameData @@ -73,7 +73,7 @@ export default function PassiveGameCard({ game, rank }: Props) { {isOnSale ? `-${game.salePercent}%` : ''} - {game.price.toFixed(2)} $ + {FormatPrice(game.price)} diff --git a/Frontend/src/components/WishlistGameCard/WishlistGameCard.tsx b/Frontend/src/components/WishlistGameCard/WishlistGameCard.tsx index a0ed4e7..0f3db8f 100644 --- a/Frontend/src/components/WishlistGameCard/WishlistGameCard.tsx +++ b/Frontend/src/components/WishlistGameCard/WishlistGameCard.tsx @@ -5,6 +5,7 @@ import { RemoveFromWishlistFrontend } from '../../FrontendLogic/WishlistLogicFro import { GetSavedUser } from '../../FrontendLogic/UserLogicFrontend' import { useState } from 'react' import { Link } from 'react-router-dom' +import { FormatPrice } from '../../types/Game' type wishlistGamecardProps = { game: PassiveGameData @@ -66,7 +67,7 @@ export default function WishlistGameCard({ size="small" /> )} -

{game.price.toFixed(2)} $

+

{FormatPrice(game.price)}

{error && ( diff --git a/Frontend/src/tests/ActiveGameCard.test.tsx b/Frontend/src/tests/ActiveGameCard.test.tsx index 20e5460..3568c1a 100644 --- a/Frontend/src/tests/ActiveGameCard.test.tsx +++ b/Frontend/src/tests/ActiveGameCard.test.tsx @@ -81,10 +81,10 @@ describe('ActiveGameCard', () => { }) await screen.findByText('-50%') - expect(screen.getByText('9.99 $').className).toContain('activeGameSalePrice') + expect(screen.getByText('$9.99').className).toContain('activeGameSalePrice') const originalPrice = container.querySelector('s.activeGameOriginalPrice')! - expect(originalPrice.textContent).toBe('Original price: 19.98 $') + expect(originalPrice.textContent).toBe('Original price: $19.98') }) it('only shows the price when the game is not on sale', async () => { @@ -94,8 +94,8 @@ describe('ActiveGameCard', () => { originalPrice: 9.99 }) - await screen.findByText('9.99 $') - expect(screen.getByText('9.99 $').className).not.toContain('activeGameSalePrice') + await screen.findByText('$9.99') + expect(screen.getByText('$9.99').className).not.toContain('activeGameSalePrice') expect(container.querySelector('.activeGameOriginalPrice')).toBeNull() expect(screen.queryByText('-0%')).toBeNull() }) diff --git a/Frontend/src/types/Game.ts b/Frontend/src/types/Game.ts index 8a26eca..7cd468e 100644 --- a/Frontend/src/types/Game.ts +++ b/Frontend/src/types/Game.ts @@ -31,3 +31,7 @@ export type PageGame = { } export type PassiveGameData = Pick + +export const FormatPrice = (price: number): string => { + return price === 0 ? "Free" : `$${price.toFixed(2)}`; +};