From f6a90994b6d50e7af6be04ceb37efea731992cd9 Mon Sep 17 00:00:00 2001 From: Sofiya Tepikin Date: Sun, 18 Sep 2022 13:02:43 +0000 Subject: [PATCH] Distinction between License and AcceptLicense screens --- components/AcceptLicense.js | 43 ++++++++++++++++++++++++++++ components/License.js | 51 ---------------------------------- components/app-wrapper.js | 4 +-- components/settings/index.js | 2 +- components/settings/license.js | 8 +++++- test/license.spec.js | 21 -------------- 6 files changed, 53 insertions(+), 76 deletions(-) create mode 100644 components/AcceptLicense.js delete mode 100644 components/License.js delete mode 100644 test/license.spec.js diff --git a/components/AcceptLicense.js b/components/AcceptLicense.js new file mode 100644 index 0000000..2992d5b --- /dev/null +++ b/components/AcceptLicense.js @@ -0,0 +1,43 @@ +import React from 'react' +import PropTypes from 'prop-types' +import { BackHandler, StyleSheet, View } from 'react-native' +import { useTranslation } from 'react-i18next' + +import License from './settings/License' +import Button from './common/button' + +import { saveLicenseFlag } from '../local-storage' + +import { Containers } from '../styles' + +export default function AcceptLicense({ setLicense }) { + const onAcceptLicense = async () => { + await saveLicenseFlag() + setLicense() + } + + const { t } = useTranslation() + + return ( + + + + + + + ) +} + +AcceptLicense.propTypes = { + setLicense: PropTypes.func.isRequired, +} + +const styles = StyleSheet.create({ + container: { + ...Containers.rowContainer, + }, +}) diff --git a/components/License.js b/components/License.js deleted file mode 100644 index 9611f86..0000000 --- a/components/License.js +++ /dev/null @@ -1,51 +0,0 @@ -import React from 'react' -import PropTypes from 'prop-types' -import { BackHandler, StyleSheet, View } from 'react-native' -import { useTranslation } from 'react-i18next' - -import AppPage from './common/app-page' -import AppText from './common/app-text' -import Button from './common/button' -import Segment from './common/segment' - -import { saveLicenseFlag } from '../local-storage' - -import { Containers } from '../styles' - -export default function License({ setLicense }) { - const onAcceptLicense = async () => { - await saveLicenseFlag() - setLicense() - } - - const { t } = useTranslation() - const currentYear = new Date().getFullYear() - - return ( - - - - {t('settings.license.text', { currentYear })} - - - - - - - - ) -} - -License.propTypes = { - setLicense: PropTypes.func.isRequired, -} - -const styles = StyleSheet.create({ - container: { - ...Containers.rowContainer, - }, -}) diff --git a/components/app-wrapper.js b/components/app-wrapper.js index 3afcca3..3674c2b 100644 --- a/components/app-wrapper.js +++ b/components/app-wrapper.js @@ -7,7 +7,7 @@ import { openDb } from '../db' import App from './app' import AppLoadingView from './common/app-loading' import AppStatusBar from './common/app-status-bar' -import License from './License' +import AcceptLicense from './AcceptLicense' import PasswordPrompt from './password-prompt' export default function AppWrapper() { @@ -38,7 +38,7 @@ export default function AppWrapper() { } if (!isLicenseAccepted) { - return setIsLicenseAccepted(true)} /> + return setIsLicenseAccepted(true)} /> } return ( diff --git a/components/settings/index.js b/components/settings/index.js index 5fd6453..cd50c84 100644 --- a/components/settings/index.js +++ b/components/settings/index.js @@ -3,7 +3,7 @@ import NfpSettings from './nfp-settings' import DataManagement from './data-management' import Password from './password' import About from './about' -import License from './license' +import License from './License' import PrivacyPolicy from './privacy-policy' export default { diff --git a/components/settings/license.js b/components/settings/license.js index c01b5f9..69b1fcd 100644 --- a/components/settings/license.js +++ b/components/settings/license.js @@ -1,11 +1,12 @@ import React from 'react' +import PropTypes from 'prop-types' import { useTranslation } from 'react-i18next' import AppPage from '../common/app-page' import AppText from '../common/app-text' import Segment from '../common/segment' -const License = () => { +const License = ({ children }) => { const { t } = useTranslation() const currentYear = new Date().getFullYear() @@ -13,9 +14,14 @@ const License = () => { {t('settings.license.text', { currentYear })} + {children} ) } +License.propTypes = { + children: PropTypes.node, +} + export default License diff --git a/test/license.spec.js b/test/license.spec.js deleted file mode 100644 index e0bac2c..0000000 --- a/test/license.spec.js +++ /dev/null @@ -1,21 +0,0 @@ -import React from 'react' -import { render, screen } from '@testing-library/react-native' -import License from '../components/License' - -jest.mock('../local-storage', () => ({ saveLicenseFlag: jest.fn() })) - -jest.mock('react-i18next', () => ({ - useTranslation: () => ({ - t: (str, options) => { - return str + (options ? JSON.stringify(options) : '') - }, - }), -})) - -describe('License screen', () => { - test('It should have a correct year', async () => { - render( {}} />) - const year = new Date().getFullYear().toString() - screen.getByText(year, { exact: false }) - }) -})