Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -31,12 +31,12 @@ export default function ActiveGameCardInfo({ game }: ActiveGameInfoProps) {
className={`activeGamePrice${showOriginalPrice ? ' activeGameSalePrice' : ''}`}
component="p"
>
{game.price.toFixed(2)} $
{FormatPrice(game.price)}
</Typography>
{showOriginalPrice && (
<Typography className="activeGameOriginalPrice" component="s">
<span className="activeGameVisuallyHidden">Original price: </span>
{game.originalPrice!.toFixed(2)} $
{FormatPrice(game.originalPrice!)}
</Typography>
)}
</Box>
Expand Down
4 changes: 2 additions & 2 deletions Frontend/src/components/PassiveGameCard/PassiveGameCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -73,7 +73,7 @@ export default function PassiveGameCard({ game, rank }: Props) {
{isOnSale ? `-${game.salePercent}%` : ''}
</div>
<Typography className="passiveGameCardPrice" component="p">
{game.price.toFixed(2)} $
{FormatPrice(game.price)}
</Typography>
</div>
</CardContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -66,7 +67,7 @@ export default function WishlistGameCard({
size="small"
/>
)}
<p className="wishlistGameCardPrice">{game.price.toFixed(2)} $</p>
<p className="wishlistGameCardPrice">{FormatPrice(game.price)}</p>
</div>

{error && (
Expand Down
8 changes: 4 additions & 4 deletions Frontend/src/tests/ActiveGameCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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()
})
Expand Down
4 changes: 4 additions & 0 deletions Frontend/src/types/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ export type PageGame = {
}

export type PassiveGameData = Pick<GameData, 'id' | 'name' | 'price' | 'image' | 'salePercent'>

export const FormatPrice = (price: number): string => {
return price === 0 ? "Free" : `$${price.toFixed(2)}`;
};