-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Paul Naszalyi
committed
Dec 2, 2024
1 parent
cd75d63
commit 691afe7
Showing
2 changed files
with
13 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
}) | ||
}) |