Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Naszalyi committed Dec 2, 2024
1 parent cd75d63 commit 691afe7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 102 deletions.
93 changes: 5 additions & 88 deletions packages/react/components/popover/test/Popover.test.tsx
Original file line number Diff line number Diff line change
@@ -1,103 +1,20 @@
// Dependencies
import * as React from 'react'
import { is } from '../../../services/index'

// Testing methods
import { render, screen } from '@testing-library/react'
import { render } from '@testing-library/react'

// Component to test
import { Popover, PopoverContent } from '../'
import { Popover } from '../'
import { Link } from '@/components/link'

describe('Popover component', () => {
test('should have "popover" className', () => {
const { getByTestId } = render(
<Popover data-testid='popover-id'>
<PopoverContent>DEFAULT</PopoverContent>
<Popover data-testid="popover-id" trigger={<Link>Hello</Link>}>
DEFAULT
</Popover>,
)
expect(getByTestId('popover-id')).toHaveClass('popover')
})

test('should contain toto as text', () => {
const { getByTestId } = render(
<Popover data-testid='popover-id'>
<PopoverContent>toto</PopoverContent>
</Popover>,
)
expect(getByTestId('popover-id')).toBeInTheDocument()
})

test('should be left', () => {
const { getByTestId } = render(
<Popover data-testid='popover-id' direction='left'>
<PopoverContent>toto</PopoverContent>
</Popover>,
)
expect(getByTestId('popover-id')).toHaveClass(is(`popover-left`))
})

test('should be right', () => {
const { getByTestId } = render(
<Popover data-testid='popover-id' direction='right'>
<PopoverContent>toto</PopoverContent>
</Popover>,
)
expect(getByTestId('popover-id')).toHaveClass(is(`popover-right`))
})

test('should be bottom', () => {
const { getByTestId } = render(
<Popover data-testid='popover-id' direction='bottom'>
<PopoverContent>toto</PopoverContent>
</Popover>,
)
expect(getByTestId('popover-id')).toHaveClass(is(`popover-bottom`))
})

test('should have "is-popover-active" className', () => {
render(
<Popover data-testid='popover-id' active={true}>
<PopoverContent>POPOVER ACTIVE</PopoverContent>
</Popover>,
)

expect(screen.getByTestId('popover-id')).toHaveClass(is('popover-active'))
})

test('should not have "is-popover-active" className', () => {
render(
<Popover data-testid='popover-id-1'>
<PopoverContent>DEFAULT</PopoverContent>
</Popover>,
)
render(
<Popover data-testid='popover-id-2' active={false}>
<PopoverContent>POPOVER ACTIVE</PopoverContent>
</Popover>,
)

expect(screen.getByTestId('popover-id-1')).not.toHaveClass(is('popover-active'))
expect(screen.getByTestId('popover-id-2')).not.toHaveClass(is('popover-active'))
})

test('should have "toto" className', () => {
render(
<Popover data-testid='toto-id' className='toto'>
<PopoverContent>TOTO</PopoverContent>
</Popover>,
)

expect(screen.getByTestId('toto-id')).toHaveClass('toto')
})

test('should have "CONTENT" content', () => {
render(
<Popover>
<PopoverContent>CONTENT</PopoverContent>
</Popover>,
)

expect(screen.getByText('CONTENT')).toHaveClass('popover-content')
expect(screen.getByText('CONTENT')).toBeInTheDocument()
})
})
22 changes: 8 additions & 14 deletions packages/react/components/price/test/Price.test.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import { checkCents } from '../PriceHelpers'
import { render } from '@testing-library/react'
import * as React from 'react'
import { Price } from '@/components/price'

describe('Price', () => {
it('returns "00" when passed an empty string', async () => {
const result = await checkCents('')
expect(result).toBe('00')
})

it('adds a "0" to the end of a string with length of 1', async () => {
const result = await checkCents('5')
expect(result).toBe('50')
})

it('returns the same string if it has length greater than 1', async () => {
const result = await checkCents('50')
expect(result).toBe('50')
test('should have "price" className', () => {
const { getByTestId } = render(
<Price amount={10.99} data-testid="testId" />,
)
expect(getByTestId('testId')).toHaveClass('price')
})
})

0 comments on commit 691afe7

Please sign in to comment.