Add test checking if StatsTable is shown on button click

This commit is contained in:
MariaZ
2022-09-20 13:42:21 +02:00
parent 57c8e31a9a
commit bee6b145ed
2 changed files with 15 additions and 2 deletions
+4 -1
View File
@@ -77,7 +77,10 @@ const Stats = () => {
{isStatsVisible && (
<AppModal onClose={() => setIsStatsVisible(false)}>
<StatsTable onClose={() => setIsStatsVisible(false)} />
<StatsTable
onClose={() => setIsStatsVisible(false)}
testID="statsTable"
/>
</AppModal>
)}
</SafeAreaView>
+11 -1
View File
@@ -1,5 +1,5 @@
import React from 'react'
import { render } from '@testing-library/react-native'
import { fireEvent, render } from '@testing-library/react-native'
import Stats from '../../components/stats'
@@ -13,6 +13,7 @@ const mockGetAllCycleLengths = jest
.mockImplementationOnce(() => [30, 31, 30])
.mockImplementationOnce(() => null)
.mockImplementationOnce(() => undefined)
.mockImplementationOnce(() => [30, 31, 30])
jest.mock('../../lib/cycle', () => ({
__esModule: true,
@@ -45,4 +46,13 @@ describe('Stats screen', () => {
expect(toJSON()).toMatchSnapshot()
})
test('when button is clicked, StatsTable is rendered', async () => {
const { getByText, findByTestId } = render(<Stats />)
const button = getByText('show_stats')
fireEvent(button, 'click')
await expect(findByTestId('statsTable')).toBeTruthy()
})
})