diff --git a/test/AcceptLicense.spec.js b/test/AcceptLicense.spec.js new file mode 100644 index 0000000..c11de9d --- /dev/null +++ b/test/AcceptLicense.spec.js @@ -0,0 +1,37 @@ +import React from 'react' +import { render, screen, fireEvent } from '@testing-library/react-native' +import AcceptLicense from '../components/AcceptLicense' + +import { saveLicenseFlag } from '../local-storage' + +jest.mock('../local-storage', () => ({ + saveLicenseFlag: jest.fn(() => Promise.resolve()), +})) + +jest.mock('react-i18next', () => ({ + useTranslation: () => ({ + t: (str, options) => { + return str + (options ? JSON.stringify(options) : '') + }, + }), +})) + +describe('AcceptLicense', () => { + test('On clicking OK button, the license is accepted', async () => { + const mockedSetLicense = jest.fn() + render() + + const okButton = screen.getByText('ok', { exact: false }) + + fireEvent(okButton, 'click') + + await expect(saveLicenseFlag).toHaveBeenCalled() + expect(mockedSetLicense).toHaveBeenCalled() + }) + + test('There is a Cancel button', async () => { + render() + + screen.getByText('cancel', { exact: false }) + }) +}) diff --git a/test/License.spec.js b/test/License.spec.js index c68e7e9..4abc19c 100644 --- a/test/License.spec.js +++ b/test/License.spec.js @@ -12,8 +12,15 @@ jest.mock('react-i18next', () => ({ describe('License screen', () => { test('It should have a correct year', async () => { - render( {}} />) + render() const year = new Date().getFullYear().toString() + screen.getByText(year, { exact: false }) }) + + test('It should match the snapshot', async () => { + const licenseScreen = render() + + expect(licenseScreen).toMatchSnapshot() + }) }) diff --git a/test/__snapshots__/License.spec.js.snap b/test/__snapshots__/License.spec.js.snap new file mode 100644 index 0000000..c4d0706 --- /dev/null +++ b/test/__snapshots__/License.spec.js.snap @@ -0,0 +1,85 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`License screen It should match the snapshot 1`] = ` + + + + + title + + + + text{"currentYear":2022} + + + https://www.gnu.org/licenses/gpl-3.0.html + + + + + +`;