Skip to content

Commit

Permalink
update TotalsNumber to vitest
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholas-codecov committed Sep 19, 2024
1 parent 0ecb48e commit 53c9465
Showing 1 changed file with 46 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,42 +1,70 @@
import { render, screen } from '@testing-library/react'
import { cleanup, render, screen } from '@testing-library/react'

import TotalsNumber from '.'
import TotalsNumber from './TotalsNumber'

describe('TotalsNumber', () => {
function setup({ value, variant }: { value?: number; variant: string }) {
render(
<TotalsNumber
value={value}
variant={variant}
showChange
data-testid="change-value"
plain
/>
)
}
afterEach(() => {
cleanup()
})

describe('TotalsNumber', () => {
describe('when rendered', () => {
it('renders commit change when there is a valid value', () => {
setup({ value: 23, variant: 'default' })
render(
<TotalsNumber
value={23}
variant="default"
showChange
data-testid="change-value"
plain
/>
)

const changeValue = screen.getByTestId('number-value')
expect(changeValue).toHaveTextContent('23.00%')
expect(changeValue).toHaveClass("before:content-['+']")
})

it('renders negative number when change is negative', () => {
setup({ value: -17, variant: 'default' })
render(
<TotalsNumber
value={-17}
variant="default"
showChange
data-testid="change-value"
plain
/>
)

const changeValue = screen.getByTestId('change-value')
expect(changeValue).toHaveTextContent('-17.00%')
})

it('renders - when there is an invalid value', () => {
setup({ value: undefined, variant: 'default' })
render(
<TotalsNumber
value={undefined}
variant="default"
showChange
data-testid="change-value"
plain
/>
)

const changeValue = screen.getByTestId('change-value')
expect(changeValue).toHaveTextContent('-')
})

it('renders 0 when you get 0 change', () => {
setup({ value: 0, variant: 'default' })
render(
<TotalsNumber
value={0}
variant="default"
showChange
data-testid="change-value"
plain
/>
)

const changeValue = screen.getByTestId('change-value')
expect(changeValue).toHaveTextContent('0')
})
Expand Down

0 comments on commit 53c9465

Please sign in to comment.