Skip to content

Commit

Permalink
test: Add CozyTheme in AppLike to avoid hook usage warning
Browse files Browse the repository at this point in the history
  • Loading branch information
JF-Cozy committed May 30, 2024
1 parent 538a317 commit 87c885a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 32 deletions.
16 changes: 7 additions & 9 deletions src/components/HeroHeader/Corner.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react'
import { render } from '@testing-library/react'
import Corner from './Corner'

import flag from 'cozy-flags'
import I18n from 'cozy-ui/transpiled/react/providers/I18n'
import enLocale from 'locales/en.json'
import { BreakpointsProvider } from 'cozy-ui/transpiled/react/providers/Breakpoints'
import { WebviewIntentProvider } from 'cozy-intent'

import AppLike from 'test/AppLike'
import Corner from './Corner'

jest.mock(
'./SettingsButton',
() =>
Expand All @@ -22,11 +22,9 @@ describe('Corner', () => {
it('should only render the log out button', () => {
const root = render(
<WebviewIntentProvider>
<BreakpointsProvider>
<I18n dictRequire={() => enLocale} lang="en">
<Corner />
</I18n>
</BreakpointsProvider>
<AppLike>
<Corner />
</AppLike>
</WebviewIntentProvider>
)

Expand Down
21 changes: 7 additions & 14 deletions src/components/Shortcuts/ShortcutsView.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ import '@testing-library/jest-dom'

import { ShortcutsView } from './ShortcutsView'
import AppLike from 'test/AppLike'
import CozyTheme from 'cozy-ui/transpiled/react/providers/CozyTheme'

describe('Shortcuts', () => {
it('Should display nothing if nothing was found', () => {
const { container } = render(
<AppLike>
<CozyTheme>
<ShortcutsView shortcutsDirectories={null} />
</CozyTheme>
<ShortcutsView shortcutsDirectories={null} />
</AppLike>
)
expect(container).toMatchSnapshot()
Expand All @@ -25,13 +22,11 @@ describe('Shortcuts', () => {

const root = render(
<AppLike>
<CozyTheme>
<ShortcutsView
shortcutsDirectories={[
{ name: listName, items: [{ name: listItem }] }
]}
/>
</CozyTheme>
<ShortcutsView
shortcutsDirectories={[
{ name: listName, items: [{ name: listItem }] }
]}
/>
</AppLike>
)
expect(root).toMatchSnapshot()
Expand All @@ -45,9 +40,7 @@ describe('Shortcuts', () => {

const root = render(
<AppLike>
<CozyTheme>
<ShortcutsView shortcutsDirectories={shortcutsDirectories} />
</CozyTheme>
<ShortcutsView shortcutsDirectories={shortcutsDirectories} />
</AppLike>
)

Expand Down
21 changes: 12 additions & 9 deletions test/AppLike.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createMockClient } from 'cozy-client/dist/mock'
import { Provider as ReduxProvider } from 'react-redux'
import PropTypes from 'prop-types'
import { BreakpointsProvider } from 'cozy-ui/transpiled/react/providers/Breakpoints'
import CozyTheme from 'cozy-ui/transpiled/react/providers/CozyTheme'
import I18n from 'cozy-ui/transpiled/react/providers/I18n'
import { BackupDataProvider } from 'components/BackupNotification/useBackupData'
import enLocale from '../src/locales/en.json'
Expand All @@ -31,15 +32,17 @@ class AppLike extends React.Component {

render() {
return (
<BreakpointsProvider>
<CozyProvider client={this.props.client || defaultClient}>
<ReduxProvider store={this.props.store || defaultClient.store}>
<I18n dictRequire={() => enLocale} lang="en">
<BackupDataProvider>{this.props.children}</BackupDataProvider>
</I18n>
</ReduxProvider>
</CozyProvider>
</BreakpointsProvider>
<CozyTheme>
<BreakpointsProvider>
<CozyProvider client={this.props.client || defaultClient}>
<ReduxProvider store={this.props.store || defaultClient.store}>
<I18n dictRequire={() => enLocale} lang="en">
<BackupDataProvider>{this.props.children}</BackupDataProvider>
</I18n>
</ReduxProvider>
</CozyProvider>
</BreakpointsProvider>
</CozyTheme>
)
}
}
Expand Down

0 comments on commit 87c885a

Please sign in to comment.