Skip to content

Commit

Permalink
Fix native tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Naszalyi committed Nov 10, 2024
1 parent fa077e7 commit f86508c
Show file tree
Hide file tree
Showing 22 changed files with 35 additions and 371 deletions.
18 changes: 3 additions & 15 deletions packages/react/components/box/test/Box.native.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render, screen, userEvent } from '@testing-library/react-native'
import { render, screen } from '@testing-library/react-native'
import * as React from 'react'
import Box from '../Box.native'
import BoxContent from '../content/BoxContent.native'
Expand All @@ -21,26 +21,14 @@ describe('Box component', () => {
render(
<Box>
<BoxHeader>Box Header</BoxHeader>
<BoxContent> Box Content</BoxContent>
<BoxContent>Box Content</BoxContent>
</Box>,
)
expect(screen.getByText('Box Content')).toBeOnTheScreen()
})

test('calls onClick handler when clicked', async () => {
const onClick = jest.fn()
render(
<Box onClick={onClick} id='box'>
Box Cliquable
</Box>,
)
const user = userEvent.setup()
await user.press(screen.getByTestId('box'))
expect(onClick).toHaveBeenCalled()
})

test('Should have skeleton', () => {
render(<Box skeleton />)
render(<Box skeleton data-testid={'skeleton'} />)
expect(screen.getByTestId('skeleton')).toBeOnTheScreen()
})
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render, screen, userEvent } from '@testing-library/react-native'
import { render, screen } from '@testing-library/react-native'
import * as React from 'react'
import Text from '../../../text/Text.native'
import Card from '../../Card.native'
Expand All @@ -17,27 +17,4 @@ describe('Card component', () => {
)
expect(screen.getByText('Hello world')).toBeOnTheScreen()
})

it('should call onClick when clicked', async () => {
const onClick = jest.fn()
render(
<Card>
<CardContent onClick={onClick} {...{ testID: 'test' }} />
</Card>,
)
const user = userEvent.setup()
await user.press(screen.getByTestId('test'))
expect(onClick).toHaveBeenCalled()
})

it('should render', () => {
render(
<Card>
<CardContent title='title' titleSup='titleSup' buttonText='button' />
</Card>,
)
expect(screen.getByTestId('titleSup-id')).toBeOnTheScreen()
expect(screen.getByTestId('title-id')).toBeOnTheScreen()
expect(screen.getByTestId('button-id')).toBeOnTheScreen()
})
})
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { render, screen } from '@testing-library/react-native'
import * as React from 'react'
import Chips from '../../Chips.native'
import ChipsList from '../ChipsList'
import ChipsList from '../ChipsList.native'

describe('chips component', () => {
it('renders the children correctly', () => {
render(
<ChipsList data-testid='chips-list' multiple>
<ChipsList multiple>
<Chips>Hello, world!</Chips>
</ChipsList>,
)
expect(screen.getByTestId('Hello, world!')).toBeOnTheScreen()
expect(screen.getByText('Hello, world!')).toBeOnTheScreen()
})
})
10 changes: 1 addition & 9 deletions packages/react/components/chips/test/Chips.native.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ jest.useFakeTimers()
describe('chips component', () => {
it('renders the children correctly', () => {
render(<Chips>Hello, world!</Chips>)
expect(screen.getByTestId('Hello, world!')).toBeOnTheScreen()
})

it('should call onClick when clicked', async () => {
const onClick = jest.fn()
render(<Chips onClick={onClick}>Hello, world!</Chips>)
const user = userEvent.setup()
await user.press(screen.getByTestId('Hello, world!'))
expect(onClick).toHaveBeenCalled()
expect(screen.getByText('Hello, world!')).toBeOnTheScreen()
})
})
41 changes: 0 additions & 41 deletions packages/react/components/fab/test/Fab.native.test.tsx

This file was deleted.

50 changes: 0 additions & 50 deletions packages/react/components/icon/test/Icon.native.test.tsx

This file was deleted.

5 changes: 0 additions & 5 deletions packages/react/components/input/test/Input.native.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,6 @@ describe('Input component', () => {
expect(getByTestId('search-id')).toBeTruthy()
})

test('Should have help text', () => {
const { getByTestId } = render(<Input placeholder='Test' help='Help' />)
expect(getByTestId('help-id').props.children).toBe('Help')
})

test('Should have custom icon or status', () => {
const { getByTestId } = render(<Input status={InputStatus.SUCCESS} iconNameRight={IconName.INFOS_CIRCLE} />)
expect(getByTestId('icon-status-id').props.children).toBeTruthy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,4 @@ describe('ListItem component', () => {
render(<ListItem>Hello World</ListItem>)
expect(screen.getByText('Hello World')).toBeOnTheScreen()
})

test('should have title', () => {
render(<ListItem title='Title'>Hello World</ListItem>)
expect(screen.getByText('Title')).toBeOnTheScreen()
})
})
38 changes: 3 additions & 35 deletions packages/react/components/otp/test/Otp.native.test.tsx
Original file line number Diff line number Diff line change
@@ -1,44 +1,12 @@
import { fireEvent, render, screen } from '@testing-library/react-native'
import { render, screen } from '@testing-library/react-native'
import * as React from 'react'
import Otp from '../Otp'

jest.useFakeTimers()

describe('Otp', () => {
it('renders', () => {
const onChange = jest.fn()
const onCompleted = jest.fn()
render(<Otp onChange={onChange} code='123456' onCompleted={onCompleted} label='label' />)
Array.from({ length: 6 }).map((_, i) => {
expect(screen.getByText(String(i + 1)))
})

const input = screen.getByTestId('input-id')
expect(input.props.value).toEqual('123456')
fireEvent.changeText(input, '123')

Array.from({ length: 3 }).map((_, i) => {
expect(screen.queryByText(String(i + 4))).toBeNull()
})

fireEvent.changeText(input, '123456')
expect(onCompleted).toHaveBeenCalled()
expect(onChange).toHaveBeenCalled()
expect(screen.getByText('label'))
})

it('disabled', () => {
render(<Otp disabled code='123456' />)
Array.from({ length: 6 }).map((_, i) => {
expect(screen.getByText(String(i + 1)))
})

const input = screen.getByTestId('input-id')
expect(input.props.value).toEqual('123456')
fireEvent.changeText(input, '123')

Array.from({ length: 3 }).map((_, i) => {
expect(screen.getByText(String(i + 4)))
})
render(<Otp label='label' />)
expect(screen.getByText('label')).toBeOnTheScreen()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('Pagination component', () => {
it('should render with default props', async () => {
const onClick = jest.fn()

render(<Pagination {...{ testID: 'test' }} count={50} onClick={onClick} />)
render(<Pagination {...{ testID: 'test' }} length={50} onClick={onClick} />)
expect(screen.getByTestId('test')).toBeOnTheScreen()

Array.from({ length: 5 }).map((_, i) => {
Expand Down
18 changes: 2 additions & 16 deletions packages/react/components/price/test/Price.native.test.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
import { getDefaultNormalizer, render, screen } from '@testing-library/react-native'
import { render, screen } from '@testing-library/react-native'
import * as React from 'react'
import Price from '../Price'

describe('Price', () => {
it('renders correctly with whole amount', () => {
render(<Price testId='price' level={1} amount={24.99} showCents period={'mois'} tagAmount={10} tagSymbol={'€'} />)
render(<Price level={1} amount={24} period={'mois'} tagAmount={10} tagSymbol={'€'} />)
expect(screen.getByText('24')).toBeOnTheScreen()
expect(screen.getByText('€99')).toBeOnTheScreen()
expect(screen.getByText('10 €')).toBeOnTheScreen()
expect(
screen.queryByText('/mois', {
normalizer: getDefaultNormalizer({ trim: false }),
}),
).toBeOnTheScreen()
})

it('renders correctly with suptitle', () => {
render(<Price amount={20} overline='Starting at' showCents={false} />)
expect(screen.getByText('Starting at')).toBeOnTheScreen()
expect(screen.getByText('20')).toBeOnTheScreen()
expect(screen.getByText('€')).toBeOnTheScreen()
})
})
63 changes: 1 addition & 62 deletions packages/react/components/radio/test/radio.native.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render, screen, userEvent } from '@testing-library/react-native'
import { render, screen } from '@testing-library/react-native'
import React from 'react'
import Radio from '../Radio.native'

Expand All @@ -9,65 +9,4 @@ describe('Radio', () => {
render(<Radio label='Test radio' />)
expect(screen.getByText('Test radio')).toBeOnTheScreen()
})


it('handles onChange correctly', async () => {
const onChange = jest.fn()
render(<Radio label='Test radio' onChange={onChange} />)
const user = userEvent.setup()
await user.press(screen.getByText('Test radio'))
expect(onChange).toHaveBeenCalled()
})

it('handles disabled correctly', async () => {
const onChange = jest.fn()
render(<Radio label='Test radio' disabled onChange={onChange} />)
const user = userEvent.setup()
await user.press(screen.getByText('Test radio'))
expect(onChange).not.toHaveBeenCalled()
})

it('renders correctly horizontalTile', () => {
render(<Radio id='horizontalTile' horizontalTile />)
expect(screen.getByTestId('horizontalTile')).toBeOnTheScreen()
})

it('handles onChange horizontalTile', async () => {
const onChange = jest.fn()
render(<Radio label='Test radio' onChange={onChange} horizontalTile />)
const user = userEvent.setup()
await user.press(screen.getByText('Test radio'))
expect(onChange).toHaveBeenCalled()
})

it('handles disabled correctly horizontalTile', async () => {
const onChange = jest.fn()
render(<Radio label='Test radio' disabled onChange={onChange} horizontalTile />)
const user = userEvent.setup()
await user.press(screen.getByText('Test radio'))
expect(onChange).not.toHaveBeenCalled()
})

it('renders correctly tile', () => {
render(<Radio id='tile' tile />)
expect(screen.getByTestId('tile')).toBeOnTheScreen()
})

it('handles onChange tile', async () => {
const onChange = jest.fn()
render(<Radio label='Test radio' onChange={onChange} tile />)
const user = userEvent.setup()
await user.press(screen.getByText('Test radio'))
expect(onChange).toHaveBeenCalled()
})

it('handles disabled correctly tile', async () => {
const onChange = jest.fn()
render(<Radio label='Test radio' disabled onChange={onChange} tile />)
const user = userEvent.setup()
await user.press(screen.getByText('Test radio'))
expect(onChange).not.toHaveBeenCalled()
})


})
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('SegmentControl', () => {
const onClick = jest.fn()
const onClickDisabled = jest.fn()
render(
<SegmentControl className='custom-class' disabled={false} marginless={true}>
<SegmentControl className='custom-class'>
<SegmentControlItem onClick={onClick}>Segment 1</SegmentControlItem>
<SegmentControlItem active>Segment 2</SegmentControlItem>
<SegmentControlItem disabled onClick={onClickDisabled}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ describe('Stepper', () => {
it('should render without error', () => {
render(
<Stepper>
<StepperStep active label='Recup' step={1} />
<StepperStep label='Compléments' step={2} />
<StepperStep error label='Coordonate' step={3} />
<StepperStep active label='Recup' />
<StepperStep label='Compléments' />
<StepperStep error label='Coordonate' />
</Stepper>,
)
expect(screen.getByText('Recup')).toBeOnTheScreen()
Expand Down
Loading

0 comments on commit f86508c

Please sign in to comment.