From bee6b145ed3832b046a68f0f60f1e31c052e8846 Mon Sep 17 00:00:00 2001 From: MariaZ Date: Tue, 20 Sep 2022 13:42:21 +0200 Subject: [PATCH] Add test checking if StatsTable is shown on button click --- components/stats.js | 5 ++++- test/components/stats.spec.js | 12 +++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/components/stats.js b/components/stats.js index ef061b6..be32473 100644 --- a/components/stats.js +++ b/components/stats.js @@ -77,7 +77,10 @@ const Stats = () => { {isStatsVisible && ( setIsStatsVisible(false)}> - setIsStatsVisible(false)} /> + setIsStatsVisible(false)} + testID="statsTable" + /> )} diff --git a/test/components/stats.spec.js b/test/components/stats.spec.js index 4eaaa89..fa55366 100644 --- a/test/components/stats.spec.js +++ b/test/components/stats.spec.js @@ -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() + const button = getByText('show_stats') + + fireEvent(button, 'click') + + await expect(findByTestId('statsTable')).toBeTruthy() + }) })