commons/client/src/routes/Publish/index.test.tsx

50 lines
1.5 KiB
TypeScript
Raw Normal View History

2019-04-30 19:19:28 +02:00
import React from 'react'
2019-06-18 00:05:40 +02:00
import { MemoryRouter } from 'react-router'
2019-06-03 15:13:17 +02:00
import { render, fireEvent } from '@testing-library/react'
2019-04-30 19:19:28 +02:00
import Publish from '.'
2019-06-03 15:13:17 +02:00
import { User } from '../../context'
import { userMockConnected } from '../../../__mocks__/user-mock'
2019-04-30 19:19:28 +02:00
2019-06-03 15:13:17 +02:00
describe('Publish', () => {
2019-04-30 19:19:28 +02:00
it('renders without crashing', () => {
2019-06-03 15:13:17 +02:00
const { container, getByText } = render(
<User.Provider value={userMockConnected}>
2019-06-18 00:05:40 +02:00
<MemoryRouter>
<Publish />
</MemoryRouter>
2019-06-03 15:13:17 +02:00
</User.Provider>
)
2019-04-30 19:19:28 +02:00
expect(container.firstChild).toBeInTheDocument()
expect(getByText('Next →')).toHaveAttribute('disabled')
})
2019-06-03 15:13:17 +02:00
it('next button works', () => {
const { getByText, getByLabelText, getByTestId } = render(
<User.Provider value={userMockConnected}>
2019-06-18 00:05:40 +02:00
<MemoryRouter>
<Publish />
</MemoryRouter>
2019-06-03 15:13:17 +02:00
</User.Provider>
)
// Title
const inputName = getByLabelText('Title')
fireEvent.change(inputName, {
target: { value: 'Hello' }
})
// Files
const inputFiles = getByTestId('files')
fireEvent.change(inputFiles, {
target: {
value: JSON.stringify([
{ url: 'https://demo.com', contentType: '', found: false }
])
}
})
// expect(getByText('Next →')).not.toHaveAttribute('disabled')
fireEvent.click(getByText('Next →'))
})
2019-04-30 19:19:28 +02:00
})