Skip to content

Commit

Permalink
feat: Add WebviewProvider in BarProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
acezard committed Jan 27, 2022
1 parent f3819e6 commit bd2823e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
5 changes: 4 additions & 1 deletion react/BarContextProvider/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { BreakpointsProvider } from '../hooks/useBreakpoints'

import { CozyProvider } from 'cozy-client'
import { Provider } from 'react-redux'
import { WebviewIntentProvider } from 'cozy-intent'

const BarContextProvider = props => {
if (!props.children) return null
Expand All @@ -13,7 +14,9 @@ const BarContextProvider = props => {
<I18nContext.Provider
value={{ f: props.f, t: props.t, lang: props.lang }}
>
<BreakpointsProvider>{props.children}</BreakpointsProvider>
<BreakpointsProvider>
<WebviewIntentProvider>{props.children}</WebviewIntentProvider>
</BreakpointsProvider>
</I18nContext.Provider>
</CozyProvider>
</Provider>
Expand Down
25 changes: 25 additions & 0 deletions react/BarContextProvider/index.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ import CozyClient, {
} from 'cozy-client'
import configureStore from 'redux-mock-store'
import { Provider, useStore } from 'react-redux'
import { isFlagshipApp } from 'cozy-device-helper'

import BarContextProvider from '.'
import I18n, { useI18n, translate } from '../I18n'

jest.mock('cozy-device-helper', () => ({
isFlagshipApp: jest.fn()
}))

const locales = { helloworld: 'Hello World !' }
const localesBar = { a: 'b' }

Expand Down Expand Up @@ -64,4 +69,24 @@ describe('BarContextProvider', () => {
)
expect(root.html()).toBe('<div>Hello World !<br>6 Jan<br>en</div>')
})

it('should try to provide a cozy-intent context', async () => {
const client = createMockClient({})
const mockStore = configureStore()
const store = mockStore(x => x)
mount(
<Provider store={store}>
<CozyProvider client={client}>
<I18n lang="en" dictRequire={() => locales}>
<App />
</I18n>
</CozyProvider>
</Provider>
)

// Currently only the WebviewProvider should call this function in BarContext
// This is an easy way to test that the provider is working, albeit brittle
// A full test would need to mock cozy-intent, post-me and react-native
expect(isFlagshipApp).toHaveBeenCalled()
})
})

0 comments on commit bd2823e

Please sign in to comment.