Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: const override #1037

Merged
merged 4 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions packages/legacy/core/App/constants.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { PINValidationRules } from './types/security'

const lengthOfhiddenAttributes = 10
const lengthOfHiddenAttributes = 10
const unicodeForBulletCharacter = '\u2022'

export const whereToUseWalletUrl = 'http://example.com'

export const dateIntFormat = 'YYYYMMDD'

export const hiddenFieldValue = Array(lengthOfhiddenAttributes).fill(unicodeForBulletCharacter).join('')
export const hiddenFieldValue = Array(lengthOfHiddenAttributes).fill(unicodeForBulletCharacter).join('')
// Used to property prefix TestIDs so they can be looked up
// by on-device automated testing systems like SauceLabs.
export const testIdPrefix = 'com.ariesbifold:id/'
Expand Down
5 changes: 3 additions & 2 deletions packages/legacy/core/App/contexts/configuration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,11 @@ export interface ConfigurationContext {
OCABundleResolver: OCABundleResolverType
proofTemplateBaseUrl?: string
scan: React.FC<ScanProps>
useBiometry: React.FC
record: React.FC<RecordProps>
PINSecurity: PINSecurityParams
indyLedgers: IndyVdrPoolConfig[]
settings: SettingSection[]
customNotification: NotificationConfiguration
useCustomNotifications: () => { total: number; notifications: any }
supportedLanguages: Locales[]
connectionTimerDelay?: number
autoRedirectConnectionToHome?: boolean
Expand All @@ -50,6 +48,9 @@ export interface ConfigurationContext {
enableReuseConnections?: boolean
showPreface?: boolean
disableOnboardingSkip?: boolean
useBiometry: React.FC
useCustomNotifications: () => { total: number; notifications: any }
whereToUseWalletUrl: string
}

export const ConfigurationContext = createContext<ConfigurationContext>(null as unknown as ConfigurationContext)
Expand Down
5 changes: 3 additions & 2 deletions packages/legacy/core/App/defaultConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export const defaultConfiguration: ConfigurationContext = {
brandingOverlayType: BrandingOverlayType.Branding10,
}),
scan: Scan,
useBiometry: UseBiometry,
record: Record,
PINSecurity: { rules: PINRules, displayHelper: false },
indyLedgers: defaultIndyLedgers,
Expand All @@ -49,10 +48,12 @@ export const defaultConfiguration: ConfigurationContext = {
buttonTitle: '',
pageTitle: '',
},
useCustomNotifications: useNotifications,
proofRequestTemplates: useProofRequestTemplates,
enableTours: false,
supportedLanguages: Object.keys(translationResources) as Locales[],
showPreface: false,
disableOnboardingSkip: false,
useCustomNotifications: useNotifications,
useBiometry: UseBiometry,
whereToUseWalletUrl: 'https://example.com',
}
3 changes: 2 additions & 1 deletion packages/legacy/core/App/screens/ScanHelp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { Linking, ScrollView, StyleSheet, Text } from 'react-native'
import { SafeAreaView } from 'react-native-safe-area-context'

import Link from '../components/texts/Link'
import { whereToUseWalletUrl } from '../constants'
import { useConfiguration } from '../contexts/configuration'
import { useTheme } from '../contexts/theme'
import { testIdWithKey } from '../utils/testable'

const ScanHelp: React.FC = () => {
const { t } = useTranslation()
const { whereToUseWalletUrl } = useConfiguration()

const { TextTheme } = useTheme()
const style = StyleSheet.create({
Expand Down
2 changes: 1 addition & 1 deletion packages/legacy/core/__tests__/contexts/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { useNotifications } from '../../App/hooks/notifications'
import { useProofRequestTemplates } from '../../verifier/request-templates'
import { Locales } from '../../App/localization'


const configurationContext: ConfigurationContext = {
pages: () => [],
terms: () => null,
Expand Down Expand Up @@ -48,6 +47,7 @@ const configurationContext: ConfigurationContext = {
useCustomNotifications: useNotifications,
proofRequestTemplates: useProofRequestTemplates,
supportedLanguages: [Locales.en, Locales.fr, Locales.ptBr],
whereToUseWalletUrl: 'https://example.com',
}

export default configurationContext
14 changes: 12 additions & 2 deletions packages/legacy/core/__tests__/screens/ScanHelp.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { fireEvent, render } from '@testing-library/react-native'
import React from 'react'

import ScanHelp from '../../App/screens/ScanHelp'
import { ConfigurationContext } from '../../App/contexts/configuration'
import configurationContext from '../contexts/configuration'
import { testIdWithKey } from '../../App/utils/testable'

jest.mock('@react-navigation/core', () => {
Expand All @@ -13,12 +15,20 @@ jest.mock('@react-navigation/native', () => {

describe('ScanHelp Screen', () => {
test('Renders correctly', async () => {
const tree = render(<ScanHelp />)
const tree = render(
<ConfigurationContext.Provider value={configurationContext}>
<ScanHelp />
</ConfigurationContext.Provider>
)
expect(tree).toMatchSnapshot()
})

test('Link button exists and is accessible', async () => {
const tree = render(<ScanHelp />)
const tree = render(
<ConfigurationContext.Provider value={configurationContext}>
<ScanHelp />
</ConfigurationContext.Provider>
)
const { getByTestId } = tree
const linkButton = getByTestId(testIdWithKey('WhereToUseLink'))

Expand Down