chronograf/ui/test/CheckSource.test.tsx

71 lines
1.5 KiB
TypeScript
Raw Normal View History

2018-04-04 04:10:06 +00:00
import React from 'react'
2018-04-04 05:07:31 +00:00
import {shallow} from 'enzyme'
2018-04-04 04:10:06 +00:00
import {CheckSources} from 'src/CheckSources'
import MockChild from 'mocks/MockChild'
2018-10-30 22:45:39 +00:00
import PageSpinner from 'src/shared/components/PageSpinner'
2018-04-04 04:10:06 +00:00
2018-04-04 05:07:31 +00:00
import {source} from 'test/resources'
2018-04-04 04:10:06 +00:00
jest.mock('src/sources/apis', () => require('mocks/sources/apis'))
const getSources = jest.fn(() => Promise.resolve)
const setup = (override?) => {
const props = {
getSources,
sources: [source],
params: {
sourceID: source.id,
},
router: {},
location: {
pathname: 'sources',
},
auth: {
isUsingAuth: false,
me: {},
},
notify: () => {},
errorThrown: () => {},
...override,
}
2018-04-04 05:07:31 +00:00
const wrapper = shallow(
2018-04-04 04:10:06 +00:00
<CheckSources {...props}>
<MockChild />
</CheckSources>
)
return {
wrapper,
props,
}
}
describe('CheckSources', () => {
describe('rendering', () => {
it('renders', async () => {
const {wrapper} = setup()
expect(wrapper.exists()).toBe(true)
})
it('renders a spinner when the component is fetching', () => {
const {wrapper} = setup()
2018-10-30 22:45:39 +00:00
const spinner = wrapper.find(PageSpinner)
2018-04-04 04:10:06 +00:00
expect(spinner.exists()).toBe(true)
})
2018-04-04 22:39:46 +00:00
it('renders its children when it is done fetching', done => {
2018-04-04 04:10:06 +00:00
const {wrapper} = setup()
2018-04-04 05:07:31 +00:00
// ensure that assertion runs after async behavior of getSources
2018-04-04 18:00:43 +00:00
process.nextTick(() => {
wrapper.update()
const child = wrapper.find(MockChild)
expect(child.exists()).toBe(true)
2018-04-04 22:39:46 +00:00
done()
2018-04-04 18:00:43 +00:00
})
2018-04-04 04:10:06 +00:00
})
})
})