Add test checking if StatsTable is shown on button click
This commit is contained in:
+4
-1
@@ -77,7 +77,10 @@ const Stats = () => {
|
||||
|
||||
{isStatsVisible && (
|
||||
<AppModal onClose={() => setIsStatsVisible(false)}>
|
||||
<StatsTable onClose={() => setIsStatsVisible(false)} />
|
||||
<StatsTable
|
||||
onClose={() => setIsStatsVisible(false)}
|
||||
testID="statsTable"
|
||||
/>
|
||||
</AppModal>
|
||||
)}
|
||||
</SafeAreaView>
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user