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

47 lines
1.3 KiB
TypeScript
Raw Normal View History

2019-04-30 19:19:28 +02:00
import React from 'react'
import { render, fireEvent } from '@testing-library/react'
2019-06-18 00:05:40 +02:00
import { MemoryRouter } from 'react-router'
2019-04-30 19:19:28 +02:00
import Faucet from './Faucet'
import { User } from '../context'
import { userMockConnected } from '../../__mocks__/user-mock'
const setup = () => {
const utils = render(
<User.Provider value={userMockConnected}>
2019-06-18 00:05:40 +02:00
<MemoryRouter>
<Faucet />
</MemoryRouter>
2019-04-30 19:19:28 +02:00
</User.Provider>
)
const button = utils.getByText('Request Ether')
const { container } = utils
return {
button,
container,
...utils
}
}
describe('Faucet', () => {
it('renders without crashing', () => {
2019-06-18 00:05:40 +02:00
const { container } = setup()
2019-04-30 19:19:28 +02:00
expect(container.firstChild).toBeInTheDocument()
})
it('shows actions when connected', () => {
const { button } = setup()
expect(button).toBeInTheDocument()
expect(button).not.toHaveAttribute('disabled')
})
it('fires requestFromFaucet', () => {
const { button, getByText } = setup()
fireEvent.click(button)
expect(userMockConnected.requestFromFaucet).toHaveBeenCalledTimes(1)
// check for spinner
expect(getByText('Getting Ether...')).toBeInTheDocument()
})
})