Skip to content

Commit

Permalink
Last adjustments gallery and formatPrice
Browse files Browse the repository at this point in the history
  • Loading branch information
willianjusten committed Jan 22, 2021
1 parent 8435a6d commit 6689211
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 38 deletions.
4 changes: 3 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ module.exports = {
'src/**/*.ts(x)?',
'!src/**/stories.tsx',
'!src/pages/**/*.tsx',
'!src/styles/**/*.ts'
'!src/styles/**/*.ts',
'!src/utils/apollo.ts',
'!src/types/**/*.d.ts'
],
setupFilesAfterEnv: ['<rootDir>/.jest/setup.ts'],
modulePaths: ['<rootDir>/src/', '<rootDir>/.jest'],
Expand Down
2 changes: 1 addition & 1 deletion src/components/GameCard/__snapshots__/test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ exports[`<GameCard /> should render correctly 1`] = `
<div
class="c9"
>
R$ 235,00
$235.00
</div>
<button
class="c10"
Expand Down
11 changes: 7 additions & 4 deletions src/components/GameCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import {
import Ribbon, { RibbonColors, RibbonSizes } from 'components/Ribbon'
import Button from 'components/Button'
import * as S from './styles'
import formatPrice from 'utils/format-price'

export type GameCardProps = {
slug: string
title: string
developer: string
img: string
price: string
promotionalPrice?: string
price: number
promotionalPrice?: number
favorite?: boolean
ribbon?: React.ReactNode
ribbonColor?: RibbonColors
Expand Down Expand Up @@ -63,8 +64,10 @@ const GameCard = ({
)}
</S.FavButton>
<S.BuyBox>
{!!promotionalPrice && <S.Price isPromotional>{price}</S.Price>}
<S.Price>{promotionalPrice || price}</S.Price>
{!!promotionalPrice && (
<S.Price isPromotional>{formatPrice(price)}</S.Price>
)}
<S.Price>{formatPrice(promotionalPrice || price)}</S.Price>
<Button icon={<AddShoppingCart />} size="small" />
</S.BuyBox>
</S.Content>
Expand Down
4 changes: 2 additions & 2 deletions src/components/GameCard/stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export default {
title: 'Population Zero',
developer: 'Rockstar Games',
img: 'https://source.unsplash.com/user/willianjusten/300x140',
price: 'R$ 235,00',
promotionalPrice: 'R$ 215,00'
price: 235,
promotionalPrice: 215
},
argTypes: {
onFav: { action: 'clicked' },
Expand Down
10 changes: 5 additions & 5 deletions src/components/GameCard/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const props = {
title: 'Population Zero',
developer: 'Rockstar Games',
img: 'https://source.unsplash.com/user/willianjusten/300x140',
price: 'R$ 235,00'
price: 235
}

describe('<GameCard />', () => {
Expand Down Expand Up @@ -42,20 +42,20 @@ describe('<GameCard />', () => {
it('should render price in label', () => {
renderWithTheme(<GameCard {...props} />)

const price = screen.getByText('R$ 235,00')
const price = screen.getByText('$235.00')

expect(price).not.toHaveStyle({ textDecoration: 'line-through' })
expect(price).toHaveStyle({ backgroundColor: theme.colors.secondary })
})

it('should render a line-through in price when promotional', () => {
renderWithTheme(<GameCard {...props} promotionalPrice="R$ 15,00" />)
renderWithTheme(<GameCard {...props} promotionalPrice={15} />)

expect(screen.getByText('R$ 235,00')).toHaveStyle({
expect(screen.getByText('$235.00')).toHaveStyle({
textDecoration: 'line-through'
})

expect(screen.getByText('R$ 15,00')).not.toHaveStyle({
expect(screen.getByText('$15.00')).not.toHaveStyle({
textDecoration: 'line-through'
})
})
Expand Down
24 changes: 12 additions & 12 deletions src/components/GameCardSlider/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,47 @@ export default [
slug: 'population-zero',
developer: 'Rockstar Games',
img: 'https://source.unsplash.com/user/willianjusten/300x140',
price: 'R$ 235,00',
promotionalPrice: 'R$ 215,00'
price: 235,
promotionalPrice: 215
},
{
title: 'Population Zero',
slug: 'population-zero',
developer: 'Rockstar Games',
img: 'https://source.unsplash.com/user/willianjusten/300x141',
price: 'R$ 235,00',
promotionalPrice: 'R$ 215,00'
price: 235,
promotionalPrice: 215
},
{
title: 'Population Zero',
slug: 'population-zero',
developer: 'Rockstar Games',
img: 'https://source.unsplash.com/user/willianjusten/300x142',
price: 'R$ 235,00',
promotionalPrice: 'R$ 215,00'
price: 235,
promotionalPrice: 215
},
{
title: 'Population Zero',
slug: 'population-zero',
developer: 'Rockstar Games',
img: 'https://source.unsplash.com/user/willianjusten/300x143',
price: 'R$ 235,00',
promotionalPrice: 'R$ 215,00'
price: 235,
promotionalPrice: 215
},
{
title: 'Population Zero',
slug: 'population-zero',
developer: 'Rockstar Games',
img: 'https://source.unsplash.com/user/willianjusten/300x144',
price: 'R$ 235,00',
promotionalPrice: 'R$ 215,00'
price: 235,
promotionalPrice: 215
},
{
title: 'Population Zero',
slug: 'population-zero',
developer: 'Rockstar Games',
img: 'https://source.unsplash.com/user/willianjusten/300x145',
price: 'R$ 235,00',
promotionalPrice: 'R$ 215,00'
price: 235,
promotionalPrice: 215
}
]
4 changes: 2 additions & 2 deletions src/components/GameInfo/__snapshots__/test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ exports[`<GameInfo /> should render game informations 1`] = `
class="c2 c3"
color="secondary"
>
$210,00
$210.00
</div>
<p
class="c4"
Expand Down Expand Up @@ -296,4 +296,4 @@ exports[`<GameInfo /> should render game informations 1`] = `
</button>
</div>
</div>
`
`;
5 changes: 3 additions & 2 deletions src/components/GameInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import {
import Button from 'components/Button'
import Heading from 'components/Heading'
import Ribbon from 'components/Ribbon'
import formatPrice from 'utils/format-price'

import * as S from './styles'

export type GameInfoProps = {
title: string
description: string
price: string
price: number
}

const GameInfo = ({ title, description, price }: GameInfoProps) => (
Expand All @@ -21,7 +22,7 @@ const GameInfo = ({ title, description, price }: GameInfoProps) => (
{title}
</Heading>

<Ribbon color="secondary">{`$${price}`}</Ribbon>
<Ribbon color="secondary">{formatPrice(price)}</Ribbon>

<S.Description>{description}</S.Description>

Expand Down
2 changes: 1 addition & 1 deletion src/components/GameInfo/mock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default {
title: 'Borderlands 3',
price: '215,00',
price: 215,
description:
'Experience the epic space strategy games that redefined the RTS genre. Control your fleet and build an armada across more than 30 single-player missions.'
}
4 changes: 2 additions & 2 deletions src/components/GameInfo/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import GameInfo from '.'
const props = {
title: 'My Game Title',
description: 'Game Description',
price: '210,00'
price: 210
}

describe('<GameInfo />', () => {
Expand All @@ -16,7 +16,7 @@ describe('<GameInfo />', () => {
expect(
screen.getByRole('heading', { name: /my game title/i })
).toBeInTheDocument()
expect(screen.getByText(/\$210,00/)).toBeInTheDocument()
expect(screen.getByText(/\$210\.00/)).toBeInTheDocument()
expect(screen.getByText(/game description/i)).toBeInTheDocument()

expect(container.firstChild).toMatchSnapshot()
Expand Down
6 changes: 4 additions & 2 deletions src/pages/game/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { initializeApollo } from 'utils/apollo'

import Game, { GameTemplateProps } from 'templates/Game'

import galleryMock from 'components/Gallery/mock'
import gamesMock from 'components/GameCardSlider/mock'
import highlightMock from 'components/Highlight/mock'
import { QueryGames, QueryGamesVariables } from 'graphql/generated/QueryGames'
Expand Down Expand Up @@ -65,7 +64,10 @@ export const getStaticProps: GetStaticProps = async ({ params }) => {
price: game.price,
description: game.short_description
},
gallery: game.gallery,
gallery: game.gallery.map((image) => ({
src: `http://localhost:1337${image.src}`,
label: image.label
})),
description: game.description,
details: {
developer: game.developers[0].name,
Expand Down
5 changes: 1 addition & 4 deletions src/pages/games.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ export async function getStaticProps() {
slug: game.slug,
developer: game.developers[0].name,
img: `http://localhost:1337${game.cover!.url}`,
price: new Intl.NumberFormat('en', {
style: 'currency',
currency: 'USD'
}).format(game.price)
price: game.price
})),
filterItems: filterItemsMock
}
Expand Down
6 changes: 6 additions & 0 deletions src/utils/format-price.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default function formatPrice(price: number | bigint): string {
return new Intl.NumberFormat('en', {
style: 'currency',
currency: 'USD'
}).format(price)
}

0 comments on commit 6689211

Please sign in to comment.