Distinction between License and AcceptLicense screens

This commit is contained in:
Sofiya Tepikin
2022-09-18 13:02:43 +00:00
parent fb863c832b
commit f6a90994b6
6 changed files with 53 additions and 76 deletions
+43
View File
@@ -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 (
<License>
<View style={styles.container}>
<Button onPress={BackHandler.exitApp} testID="licenseCancelButton">
{t('labels.shared.cancel')}
</Button>
<Button isCTA onPress={onAcceptLicense} testID="licenseOkButton">
{t('labels.shared.ok')}
</Button>
</View>
</License>
)
}
AcceptLicense.propTypes = {
setLicense: PropTypes.func.isRequired,
}
const styles = StyleSheet.create({
container: {
...Containers.rowContainer,
},
})
-51
View File
@@ -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 (
<AppPage testID="licensePage">
<Segment last testID="test" title={t('settings.license.title')}>
<AppText testID="test">
{t('settings.license.text', { currentYear })}
</AppText>
<View style={styles.container}>
<Button onPress={BackHandler.exitApp} testID="licenseCancelButton">
{t('labels.shared.cancel')}
</Button>
<Button isCTA onPress={onAcceptLicense} testID="licenseOkButton">
{t('labels.shared.ok')}
</Button>
</View>
</Segment>
</AppPage>
)
}
License.propTypes = {
setLicense: PropTypes.func.isRequired,
}
const styles = StyleSheet.create({
container: {
...Containers.rowContainer,
},
})
+2 -2
View File
@@ -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 <License setLicense={() => setIsLicenseAccepted(true)} />
return <AcceptLicense setLicense={() => setIsLicenseAccepted(true)} />
}
return (
+1 -1
View File
@@ -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 {
+7 -1
View File
@@ -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 = () => {
<AppPage title={t('settings.license.title')}>
<Segment last>
<AppText>{t('settings.license.text', { currentYear })}</AppText>
{children}
</Segment>
</AppPage>
)
}
License.propTypes = {
children: PropTypes.node,
}
export default License
-21
View File
@@ -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(<License setLicense={() => {}} />)
const year = new Date().getFullYear().toString()
screen.getByText(year, { exact: false })
})
})