1
0
mirror of https://github.com/kremalicious/blowfish.git synced 2024-11-23 02:00:23 +01:00
blowfish/tests/Providers.test.jsx

48 lines
1.4 KiB
React
Raw Normal View History

2020-02-25 15:16:44 +01:00
import React from 'react'
2020-02-26 21:49:11 +01:00
import {
render,
waitForElementToBeRemoved,
2020-03-22 00:49:10 +01:00
fireEvent,
wait
2020-02-26 21:49:11 +01:00
} from '@testing-library/react'
2020-02-25 15:16:44 +01:00
import AppProvider from '../src/renderer/store/AppProvider'
import PriceProvider from '../src/renderer/store/PriceProvider'
2020-02-26 21:49:11 +01:00
import { PriceContext, AppContext } from '../src/renderer/store/createContext'
2020-02-25 15:16:44 +01:00
import { priceContext } from './__fixtures__/context'
describe('Providers', () => {
2020-02-26 21:49:11 +01:00
describe('PriceProvider', () => {
it('renders without crashing', async () => {
const { getByText } = render(
<PriceProvider>
<PriceContext.Consumer>
{({ priceChanges }) => JSON.stringify(priceChanges)}
</PriceContext.Consumer>
</PriceProvider>
)
await waitForElementToBeRemoved(() => getByText(/"eur":0/))
expect(getByText(/eur/)).toBeInTheDocument()
})
2020-02-25 15:16:44 +01:00
})
2020-02-26 21:49:11 +01:00
describe('AppProvider', () => {
it('renders without crashing', async () => {
const { getByText } = render(
<PriceContext.Provider value={priceContext}>
<AppProvider>
<AppContext.Consumer>
{({ toggleCurrencies }) => (
<button onClick={() => toggleCurrencies('eur')}>Click</button>
)}
</AppContext.Consumer>
</AppProvider>
</PriceContext.Provider>
)
2020-03-22 00:49:10 +01:00
await wait(() => getByText('Click'))
2020-02-26 21:49:11 +01:00
expect(getByText('Click')).toBeInTheDocument()
fireEvent.click(getByText('Click'))
})
2020-02-25 15:16:44 +01:00
})
})