From f86508cb8d2b4ec8dee1caaf84c7cedfb41b072d Mon Sep 17 00:00:00 2001 From: Paul Naszalyi Date: Sun, 10 Nov 2024 23:46:57 +0100 Subject: [PATCH] Fix native tests --- .../components/box/test/Box.native.test.tsx | 18 +----- .../content/test/CardContent.native.test.tsx | 25 +------- .../chips/list/test/ChipsList.native.test.tsx | 6 +- .../chips/test/Chips.native.test.tsx | 10 +-- .../components/fab/test/Fab.native.test.tsx | 41 ------------ .../components/icon/test/Icon.native.test.tsx | 50 --------------- .../input/test/Input.native.test.tsx | 5 -- .../list/item/test/ListItem.native.test.tsx | 5 -- .../components/otp/test/Otp.native.test.tsx | 38 +---------- .../test/Pagination.native.test.tsx | 2 +- .../price/test/Price.native.test.tsx | 18 +----- .../radio/test/radio.native.test.tsx | 63 +------------------ .../test/SegmentControl.native.test.tsx | 2 +- .../stepper/test/Stepper.native.test.tsx | 6 +- .../tag/list/test/Tag.native.test.tsx | 21 ------- .../components/tag/test/Tag.native.test.tsx | 17 ----- .../components/text/test/Text.native.test.tsx | 16 +---- .../textarea/test/textarea.native.test.tsx | 19 +----- .../test/TimelineContent.native.test.tsx | 13 +--- .../item/test/TimelineItem.native.test.tsx | 6 +- .../test/TimelineMarker.native.test.tsx | 12 ---- .../timeline/test/Timeline.native.test.tsx | 13 ++-- 22 files changed, 35 insertions(+), 371 deletions(-) delete mode 100644 packages/react/components/fab/test/Fab.native.test.tsx delete mode 100644 packages/react/components/icon/test/Icon.native.test.tsx delete mode 100644 packages/react/components/tag/list/test/Tag.native.test.tsx delete mode 100644 packages/react/components/tag/test/Tag.native.test.tsx delete mode 100644 packages/react/components/timeline/marker/test/TimelineMarker.native.test.tsx diff --git a/packages/react/components/box/test/Box.native.test.tsx b/packages/react/components/box/test/Box.native.test.tsx index 47153e3e..00933ca1 100644 --- a/packages/react/components/box/test/Box.native.test.tsx +++ b/packages/react/components/box/test/Box.native.test.tsx @@ -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' @@ -21,26 +21,14 @@ describe('Box component', () => { render( Box Header - Box Content + Box Content , ) expect(screen.getByText('Box Content')).toBeOnTheScreen() }) - test('calls onClick handler when clicked', async () => { - const onClick = jest.fn() - render( - - Box Cliquable - , - ) - const user = userEvent.setup() - await user.press(screen.getByTestId('box')) - expect(onClick).toHaveBeenCalled() - }) - test('Should have skeleton', () => { - render() + render() expect(screen.getByTestId('skeleton')).toBeOnTheScreen() }) }) diff --git a/packages/react/components/card/content/test/CardContent.native.test.tsx b/packages/react/components/card/content/test/CardContent.native.test.tsx index 22bf98ec..a6158873 100644 --- a/packages/react/components/card/content/test/CardContent.native.test.tsx +++ b/packages/react/components/card/content/test/CardContent.native.test.tsx @@ -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' @@ -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( - - - , - ) - const user = userEvent.setup() - await user.press(screen.getByTestId('test')) - expect(onClick).toHaveBeenCalled() - }) - - it('should render', () => { - render( - - - , - ) - expect(screen.getByTestId('titleSup-id')).toBeOnTheScreen() - expect(screen.getByTestId('title-id')).toBeOnTheScreen() - expect(screen.getByTestId('button-id')).toBeOnTheScreen() - }) }) diff --git a/packages/react/components/chips/list/test/ChipsList.native.test.tsx b/packages/react/components/chips/list/test/ChipsList.native.test.tsx index 4b4d3f6a..919e9a99 100644 --- a/packages/react/components/chips/list/test/ChipsList.native.test.tsx +++ b/packages/react/components/chips/list/test/ChipsList.native.test.tsx @@ -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( - + Hello, world! , ) - expect(screen.getByTestId('Hello, world!')).toBeOnTheScreen() + expect(screen.getByText('Hello, world!')).toBeOnTheScreen() }) }) diff --git a/packages/react/components/chips/test/Chips.native.test.tsx b/packages/react/components/chips/test/Chips.native.test.tsx index e1455969..68c62e10 100644 --- a/packages/react/components/chips/test/Chips.native.test.tsx +++ b/packages/react/components/chips/test/Chips.native.test.tsx @@ -7,14 +7,6 @@ jest.useFakeTimers() describe('chips component', () => { it('renders the children correctly', () => { render(Hello, world!) - expect(screen.getByTestId('Hello, world!')).toBeOnTheScreen() - }) - - it('should call onClick when clicked', async () => { - const onClick = jest.fn() - render(Hello, world!) - const user = userEvent.setup() - await user.press(screen.getByTestId('Hello, world!')) - expect(onClick).toHaveBeenCalled() + expect(screen.getByText('Hello, world!')).toBeOnTheScreen() }) }) diff --git a/packages/react/components/fab/test/Fab.native.test.tsx b/packages/react/components/fab/test/Fab.native.test.tsx deleted file mode 100644 index de6f265d..00000000 --- a/packages/react/components/fab/test/Fab.native.test.tsx +++ /dev/null @@ -1,41 +0,0 @@ -import { render, screen, userEvent } from '@testing-library/react-native' -import { IconName } from '@trilogy-ds/assets' -import * as React from 'react' -import Fab from '../Fab.native' - -jest.useFakeTimers() - -describe('Fab component', () => { - it('renders the children correctly', () => { - render( - - New Conversation - , - ) - expect(screen.getByTestId('fab')).toBeOnTheScreen() - }) - - it('shoud be clickable click', async () => { - const onClick = jest.fn() - - render( - - New Conversation - , - ) - const user = userEvent.setup() - await user.press(screen.getByTestId('fab')) - expect(onClick).toHaveBeenCalled() - }) - - it('shoud be extended', async () => { - const onClick = jest.fn() - - render( - - New Conversation - , - ) - expect(screen.getByText('New Conversation')).toBeOnTheScreen() - }) -}) diff --git a/packages/react/components/icon/test/Icon.native.test.tsx b/packages/react/components/icon/test/Icon.native.test.tsx deleted file mode 100644 index 8796f51d..00000000 --- a/packages/react/components/icon/test/Icon.native.test.tsx +++ /dev/null @@ -1,50 +0,0 @@ -import { render, screen, userEvent } from '@testing-library/react-native' -import { IconName } from '@trilogy-ds/assets/lib/iconNameEnum' -import * as React from 'react' -import { WrapperReactNativeTesting } from '../../../helpers/WrapperReactNativeTesting' -import Icon from '../Icon.native' - -jest.useFakeTimers() - -describe('Icon component', () => { - it('renders the children correctly', async () => { - render(, { - wrapper: WrapperReactNativeTesting, - }) - expect(screen.getByTestId('icon')).toBeOnTheScreen() - }) - - it('should have icon', async () => { - render(, { - wrapper: WrapperReactNativeTesting, - }) - expect(screen.getByTestId('icon')).toBeOnTheScreen() - }) - - it('should be clickable', async () => { - const onClick = jest.fn() - render(, { - wrapper: WrapperReactNativeTesting, - }) - const user = userEvent.setup() - await user.press(screen.getByTestId('icon-pressable')) - expect(onClick).toHaveBeenCalled() - }) - - it('should be stretched', async () => { - render(, { - wrapper: WrapperReactNativeTesting, - }) - expect(screen.getByTestId('icon-stretched')).toBeOnTheScreen() - }) - - it('have icon status', async () => { - render() - expect(screen.getByTestId('icon-status')).toBeOnTheScreen() - }) - - it('have circled icon', async () => { - render() - expect(screen.getByTestId('icon-circled')).toBeOnTheScreen() - }) -}) diff --git a/packages/react/components/input/test/Input.native.test.tsx b/packages/react/components/input/test/Input.native.test.tsx index 6e556593..975f69de 100644 --- a/packages/react/components/input/test/Input.native.test.tsx +++ b/packages/react/components/input/test/Input.native.test.tsx @@ -103,11 +103,6 @@ describe('Input component', () => { expect(getByTestId('search-id')).toBeTruthy() }) - test('Should have help text', () => { - const { getByTestId } = render() - expect(getByTestId('help-id').props.children).toBe('Help') - }) - test('Should have custom icon or status', () => { const { getByTestId } = render() expect(getByTestId('icon-status-id').props.children).toBeTruthy() diff --git a/packages/react/components/list/item/test/ListItem.native.test.tsx b/packages/react/components/list/item/test/ListItem.native.test.tsx index b74458b0..de072856 100644 --- a/packages/react/components/list/item/test/ListItem.native.test.tsx +++ b/packages/react/components/list/item/test/ListItem.native.test.tsx @@ -9,9 +9,4 @@ describe('ListItem component', () => { render(Hello World) expect(screen.getByText('Hello World')).toBeOnTheScreen() }) - - test('should have title', () => { - render(Hello World) - expect(screen.getByText('Title')).toBeOnTheScreen() - }) }) diff --git a/packages/react/components/otp/test/Otp.native.test.tsx b/packages/react/components/otp/test/Otp.native.test.tsx index cf2553a3..de955ca0 100644 --- a/packages/react/components/otp/test/Otp.native.test.tsx +++ b/packages/react/components/otp/test/Otp.native.test.tsx @@ -1,4 +1,4 @@ -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' @@ -6,39 +6,7 @@ jest.useFakeTimers() describe('Otp', () => { it('renders', () => { - const onChange = jest.fn() - const onCompleted = jest.fn() - render() - 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() - 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() + expect(screen.getByText('label')).toBeOnTheScreen() }) }) diff --git a/packages/react/components/pagination/test/Pagination.native.test.tsx b/packages/react/components/pagination/test/Pagination.native.test.tsx index 0200a076..97125eca 100644 --- a/packages/react/components/pagination/test/Pagination.native.test.tsx +++ b/packages/react/components/pagination/test/Pagination.native.test.tsx @@ -8,7 +8,7 @@ describe('Pagination component', () => { it('should render with default props', async () => { const onClick = jest.fn() - render() + render() expect(screen.getByTestId('test')).toBeOnTheScreen() Array.from({ length: 5 }).map((_, i) => { diff --git a/packages/react/components/price/test/Price.native.test.tsx b/packages/react/components/price/test/Price.native.test.tsx index 80b3f987..3ac1b319 100644 --- a/packages/react/components/price/test/Price.native.test.tsx +++ b/packages/react/components/price/test/Price.native.test.tsx @@ -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() + render() 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() - expect(screen.getByText('Starting at')).toBeOnTheScreen() - expect(screen.getByText('20')).toBeOnTheScreen() - expect(screen.getByText('€')).toBeOnTheScreen() }) }) diff --git a/packages/react/components/radio/test/radio.native.test.tsx b/packages/react/components/radio/test/radio.native.test.tsx index de9a203c..de74d625 100644 --- a/packages/react/components/radio/test/radio.native.test.tsx +++ b/packages/react/components/radio/test/radio.native.test.tsx @@ -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' @@ -9,65 +9,4 @@ describe('Radio', () => { render() expect(screen.getByText('Test radio')).toBeOnTheScreen() }) - - - it('handles onChange correctly', async () => { - const onChange = jest.fn() - render() - const user = userEvent.setup() - await user.press(screen.getByText('Test radio')) - expect(onChange).toHaveBeenCalled() - }) - - it('handles disabled correctly', async () => { - const onChange = jest.fn() - render() - const user = userEvent.setup() - await user.press(screen.getByText('Test radio')) - expect(onChange).not.toHaveBeenCalled() - }) - - it('renders correctly horizontalTile', () => { - render() - expect(screen.getByTestId('horizontalTile')).toBeOnTheScreen() - }) - - it('handles onChange horizontalTile', async () => { - const onChange = jest.fn() - render() - 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() - const user = userEvent.setup() - await user.press(screen.getByText('Test radio')) - expect(onChange).not.toHaveBeenCalled() - }) - - it('renders correctly tile', () => { - render() - expect(screen.getByTestId('tile')).toBeOnTheScreen() - }) - - it('handles onChange tile', async () => { - const onChange = jest.fn() - render() - 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() - const user = userEvent.setup() - await user.press(screen.getByText('Test radio')) - expect(onChange).not.toHaveBeenCalled() - }) - - }) diff --git a/packages/react/components/segment-control/test/SegmentControl.native.test.tsx b/packages/react/components/segment-control/test/SegmentControl.native.test.tsx index 7d7a8edc..55fbb499 100644 --- a/packages/react/components/segment-control/test/SegmentControl.native.test.tsx +++ b/packages/react/components/segment-control/test/SegmentControl.native.test.tsx @@ -10,7 +10,7 @@ describe('SegmentControl', () => { const onClick = jest.fn() const onClickDisabled = jest.fn() render( - + Segment 1 Segment 2 diff --git a/packages/react/components/stepper/test/Stepper.native.test.tsx b/packages/react/components/stepper/test/Stepper.native.test.tsx index 33aca8f0..2402dde5 100644 --- a/packages/react/components/stepper/test/Stepper.native.test.tsx +++ b/packages/react/components/stepper/test/Stepper.native.test.tsx @@ -9,9 +9,9 @@ describe('Stepper', () => { it('should render without error', () => { render( - - - + + + , ) expect(screen.getByText('Recup')).toBeOnTheScreen() diff --git a/packages/react/components/tag/list/test/Tag.native.test.tsx b/packages/react/components/tag/list/test/Tag.native.test.tsx deleted file mode 100644 index 94387b11..00000000 --- a/packages/react/components/tag/list/test/Tag.native.test.tsx +++ /dev/null @@ -1,21 +0,0 @@ -// Dependencies -import * as React from 'react' - -// Testing methods -import { render, screen } from '@testing-library/react-native' - -// Component to test -import TagList from '..' -import Tag from '../../Tag' - -describe('Tag component', () => { - test('should contain toto as text', () => { - const props: any = { testId: 'tag', iconName: 'tri-alert' } - render( - - toto - , - ) - expect(screen.getByText('toto')).toBeOnTheScreen() - }) -}) diff --git a/packages/react/components/tag/test/Tag.native.test.tsx b/packages/react/components/tag/test/Tag.native.test.tsx deleted file mode 100644 index 2704028d..00000000 --- a/packages/react/components/tag/test/Tag.native.test.tsx +++ /dev/null @@ -1,17 +0,0 @@ -// Dependencies -import * as React from 'react' - -// Testing methods -import { render, screen } from '@testing-library/react-native' - -// Component to test -import { Tag } from '..' - -describe('Tag component', () => { - test('should contain toto as text', () => { - const props: any = { testId: 'tag', iconName: 'tri-alert' } - render(toto) - expect(screen.getByText('toto')).toBeOnTheScreen() - expect(screen.getByTestId('tag-icon')).toBeOnTheScreen() - }) -}) diff --git a/packages/react/components/text/test/Text.native.test.tsx b/packages/react/components/text/test/Text.native.test.tsx index 75543186..deb30d06 100644 --- a/packages/react/components/text/test/Text.native.test.tsx +++ b/packages/react/components/text/test/Text.native.test.tsx @@ -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' import { TextLevels } from '../TextEnum' @@ -10,18 +10,4 @@ describe('Title', () => { render(Title level 1) expect(screen.getByText('Title level 1')).toBeOnTheScreen() }) - - it('should render the product tour content', async () => { - const onClick = jest.fn() - - render( - - Title level 1 - , - ) - - const user = userEvent.setup() - await user.press(screen.getByText('Title level 1')) - expect(onClick).toHaveBeenCalled() - }) }) diff --git a/packages/react/components/textarea/test/textarea.native.test.tsx b/packages/react/components/textarea/test/textarea.native.test.tsx index 8df49331..3525b3ee 100644 --- a/packages/react/components/textarea/test/textarea.native.test.tsx +++ b/packages/react/components/textarea/test/textarea.native.test.tsx @@ -1,4 +1,4 @@ -import { fireEvent, render, screen } from '@testing-library/react-native' +import { render, screen } from '@testing-library/react-native' import { IconName } from '@trilogy-ds/assets' import * as React from 'react' import Textarea from '../Textarea' @@ -8,28 +8,15 @@ jest.useFakeTimers() describe('Textarea', () => { it('renders without crashing', () => { const props: any = { - testId: 'Textarea', label: 'label', placeholder: 'With status icon error', iconName: IconName.CHECK, statusIconName: 'tri-exclamation-circle', status: 'error', help: 'This is a help message', - maxLength:150 + maxLength: 150, } render(