@navinc/base-react-components
Version:
Nav's Pattern Library
70 lines (59 loc) • 1.94 kB
JavaScript
import React from 'react'
import WaitForDependencies from './wait-for-dependencies.js'
import { render } from '@testing-library/react'
describe('<WaitForDependencies />', () => {
it('renders children if all hasDependencyProps are true', () => {
const { getByText } = render(
<WaitForDependencies hasDependencyProps={[true, true]}>
<div>yoyo</div>
</WaitForDependencies>
)
expect(getByText('yoyo'))
})
it('doesnt render children if one of hasDependencyProps is false', () => {
const { queryByText } = render(
<WaitForDependencies hasDependencyProps={[true, false]}>
<div>yoyo</div>
</WaitForDependencies>
)
expect(queryByText('yoyo')).toBe(null)
})
it(
'renders LoadingContent if one of the hasDependencyProps is false' +
' and one of loadingProps is true and LoadingContent is provided',
() => {
const { getByText } = render(
<WaitForDependencies
hasDependencyProps={[true, false]}
loadingProps={[false, true]}
LoadingContent={<div>loading</div>}
/>
)
expect(getByText('loading'))
}
)
it(
'doesnt render LoadingContent if one of the hasDependencyProps is false' +
' and one of loadingProps is true and LoadingContent is not provided',
() => {
const { queryByText } = render(
<WaitForDependencies hasDependencyProps={[true, false]} loadingProps={[false, true]} />
)
expect(queryByText('loading')).toBe(null)
}
)
it(
'renders ErrorContent if one of the hasDependencyProps is false,' +
' all of loadingProps are false, and ErrorContent is provided',
() => {
const { getByText } = render(
<WaitForDependencies
hasDependencyProps={[true, false]}
loadingProps={[false, false]}
ErrorContent={<div>error</div>}
/>
)
expect(getByText('error'))
}
)
})