diff --git a/test/components/common/StatsTable.spec.js b/test/components/common/StatsTable.spec.js new file mode 100644 index 0000000..806a9eb --- /dev/null +++ b/test/components/common/StatsTable.spec.js @@ -0,0 +1,53 @@ +import React from 'react' +import { render } from '@testing-library/react-native' + +import StatsTable from '../../../components/common/StatsTable' + +jest.mock('react-i18next', () => ({ + useTranslation: () => ({ + t: (str, options) => str + (options ? JSON.stringify(options) : ''), + }), +})) + +const mockGetStats = jest + .fn() + .mockImplementationOnce(() => [ + { date: '2022-07-01', cycleLength: 31, bleedingLength: 5 }, + { date: '2022-06-01', cycleLength: 31, bleedingLength: 5 }, + ]) + .mockImplementationOnce(() => []) + .mockImplementationOnce(() => null) + .mockImplementationOnce(() => undefined) + +jest.mock('../../../lib/cycle', () => ({ + __esModule: true, + default: () => ({ + getStats: mockGetStats, + }), +})) + +describe('StatsTable screen', () => { + test('when provided correct data set, renders it', async () => { + const { toJSON } = render() + + expect(toJSON()).toMatchSnapshot() + }) + + test('when provided no data, renders nothing', async () => { + const { toJSON } = render() + + expect(toJSON()).toMatchSnapshot() + }) + + test('when provided null, renders nothing', async () => { + const { toJSON } = render() + + expect(toJSON()).toMatchSnapshot() + }) + + test('when provided undefined, renders nothing', async () => { + const { toJSON } = render() + + expect(toJSON()).toMatchSnapshot() + }) +}) diff --git a/test/components/common/__snapshots__/StatsTable.spec.js.snap b/test/components/common/__snapshots__/StatsTable.spec.js.snap new file mode 100644 index 0000000..1b2b2c3 --- /dev/null +++ b/test/components/common/__snapshots__/StatsTable.spec.js.snap @@ -0,0 +1,433 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`StatsTable screen when provided correct data set, renders it 1`] = ` + + + + +  + + + + + + + + + + cycle_start + + + + + cycle_length + + + + + bleeding + + + + + + + + + 01. Jul 22 + + + + + day{"count":31} + + + + + day{"count":5} + + + + + + + + + + 01. Jun 22 + + + + + day{"count":31} + + + + + day{"count":5} + + + + + + + +`; + +exports[`StatsTable screen when provided no data, renders nothing 1`] = `null`; + +exports[`StatsTable screen when provided null, renders nothing 1`] = `null`; + +exports[`StatsTable screen when provided undefined, renders nothing 1`] = `null`;