diff --git a/test/components/__snapshots__/stats.spec.js.snap b/test/components/__snapshots__/stats.spec.js.snap new file mode 100644 index 0000000..b3aa698 --- /dev/null +++ b/test/components/__snapshots__/stats.spec.js.snap @@ -0,0 +1,395 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Stats screen when provided data, renders stats 1`] = ` + + + + + cycle_length_explainer + + + + + + + 30.33 + + + days + + + + average + + + + + + + + + show_stats + + + + + + +`; + +exports[`Stats screen when provided no data, renders no_data text 1`] = ` + + + + + cycle_length_explainer + + + no_data + + + + +`; + +exports[`Stats screen when provided null, renders no_data text 1`] = ` + + + + + cycle_length_explainer + + + no_data + + + + +`; + +exports[`Stats screen when provided undefined, renders no_data text 1`] = ` + + + + + cycle_length_explainer + + + no_data + + + + +`; diff --git a/test/components/stats.spec.js b/test/components/stats.spec.js new file mode 100644 index 0000000..ad153bd --- /dev/null +++ b/test/components/stats.spec.js @@ -0,0 +1,55 @@ +import React from 'react' +import { render } from '@testing-library/react-native' + +import Stats from '../../components/stats' + +jest.mock('../../components/common/AppHelp', () => 'AppHelp') +jest.mock('../../components/common/StatsOverview', () => 'StatsOverview') +jest.mock('../../components/common/StatsTable', () => 'StatsTable') +jest.mock('../../assets/cycle-icon.png', () => 'image') + +jest.mock('react-i18next', () => ({ + useTranslation: () => ({ + t: (str, options) => str + (options ? JSON.stringify(options) : ''), + }), +})) + +const mockGetAllCycleLengths = jest + .fn() + .mockImplementationOnce(() => []) + .mockImplementationOnce(() => [30, 31, 30]) + .mockImplementationOnce(() => null) + .mockImplementationOnce(() => undefined) + +jest.mock('../../lib/cycle', () => ({ + __esModule: true, + default: () => ({ + getAllCycleLengths: mockGetAllCycleLengths, + }), +})) + +describe('Stats screen', () => { + test('when provided no data, renders no_data text', async () => { + const { toJSON } = render() + + expect(toJSON()).toMatchSnapshot() + }) + + test('when provided data, renders stats', async () => { + const { toJSON } = render() + + expect(toJSON()).toMatchSnapshot() + }) + + test('when provided null, renders no_data text', async () => { + const { toJSON } = render() + + expect(toJSON()).toMatchSnapshot() + }) + + test('when provided undefined, renders no_data text', async () => { + const { toJSON } = render() + + expect(toJSON()).toMatchSnapshot() + }) +})