1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00
commons/client/src/routes/Publish/index.test.tsx

62 lines
2.0 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-07-12 00:24:29 +02:00
import { createMemoryHistory, createLocation } from 'history'
2019-04-30 19:19:28 +02:00
import Publish from '.'
2019-06-03 15:13:17 +02:00
import { User } from '../../context'
2020-01-31 18:03:13 +01:00
import { userMockConnected } from '../../__mocks__/user-mock'
2019-04-30 19:19:28 +02:00
2019-07-12 00:24:29 +02:00
const history = createMemoryHistory()
const location = createLocation('/publish')
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>
2019-07-12 00:24:29 +02:00
<Publish
history={history}
location={location}
match={{ params: '', path: '', url: '', isExact: true }}
/>
2019-06-18 00:05:40 +02:00
</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>
2019-07-12 00:24:29 +02:00
<Publish
history={history}
location={location}
2019-07-12 00:24:29 +02:00
match={{ params: '', path: '', url: '', isExact: true }}
/>
2019-06-18 00:05:40 +02:00
</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
})