Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed May 29, 2024
1 parent 0016a5a commit ee845f5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
34 changes: 24 additions & 10 deletions src/components/settings/SettingsHeader/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import SettingsHeader from '@/components/settings/SettingsHeader/index'
import { SettingsHeader } from '@/components/settings/SettingsHeader/index'
import { CONFIG_SERVICE_CHAINS } from '@/tests/mocks/chains'
import * as safeAddress from '@/hooks/useSafeAddress'
import * as feature from '@/hooks/useChains'

import { render } from '@/tests/test-utils'
import { faker } from '@faker-js/faker'
import { FEATURES } from '@/utils/chains'
import type { ChainInfo } from '@safe-global/safe-gateway-typescript-sdk'

describe('SettingsHeader', () => {
beforeEach(() => {
Expand All @@ -17,15 +19,21 @@ describe('SettingsHeader', () => {
})

it('displays safe specific preferences if on a safe', () => {
const result = render(<SettingsHeader />)
const result = render(<SettingsHeader safeAddress="0x1234" chain={CONFIG_SERVICE_CHAINS[0]} />)

expect(result.getByText('Setup')).toBeInTheDocument()
})

it('displays Notifications if feature is enabled', () => {
jest.spyOn(feature, 'useHasFeature').mockReturnValue(true)

const result = render(<SettingsHeader />)
const result = render(
<SettingsHeader
safeAddress="0x1234"
chain={{
...CONFIG_SERVICE_CHAINS[0],
features: [FEATURES.PUSH_NOTIFICATIONS] as unknown as ChainInfo['features'],
}}
/>,
)

expect(result.getByText('Notifications')).toBeInTheDocument()
})
Expand All @@ -38,7 +46,7 @@ describe('SettingsHeader', () => {
})

it('displays general preferences if no safe is open', () => {
const result = render(<SettingsHeader />)
const result = render(<SettingsHeader safeAddress="" chain={CONFIG_SERVICE_CHAINS[0]} />)

expect(result.getByText('Cookies')).toBeInTheDocument()
expect(result.getByText('Appearance')).toBeInTheDocument()
Expand All @@ -47,9 +55,15 @@ describe('SettingsHeader', () => {
})

it('displays Notifications if feature is enabled', () => {
jest.spyOn(feature, 'useHasFeature').mockReturnValue(true)

const result = render(<SettingsHeader />)
const result = render(
<SettingsHeader
safeAddress=""
chain={{
...CONFIG_SERVICE_CHAINS[0],
features: [FEATURES.PUSH_NOTIFICATIONS] as unknown as ChainInfo['features'],
}}
/>,
)

expect(result.getByText('Notifications')).toBeInTheDocument()
})
Expand Down
17 changes: 12 additions & 5 deletions src/components/settings/SettingsHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ import css from '@/components/common/PageHeader/styles.module.css'
import useSafeAddress from '@/hooks/useSafeAddress'
import { useCurrentChain } from '@/hooks/useChains'
import { isRouteEnabled } from '@/utils/chains'
import madProps from '@/utils/mad-props'

const SettingsHeader = (): ReactElement => {
const safeAddress = useSafeAddress()
const chain = useCurrentChain()

export const SettingsHeader = ({
safeAddress,
chain,
}: {
safeAddress: ReturnType<typeof useSafeAddress>
chain: ReturnType<typeof useCurrentChain>
}): ReactElement => {
const navItems = safeAddress
? settingsNavItems.filter((route) => isRouteEnabled(route.href, chain))
: generalSettingsNavItems
Expand All @@ -28,4 +32,7 @@ const SettingsHeader = (): ReactElement => {
)
}

export default SettingsHeader
export default madProps(SettingsHeader, {
safeAddress: useSafeAddress,
chain: useCurrentChain,
})

0 comments on commit ee845f5

Please sign in to comment.