2019-04-30 19:19:28 +02:00
|
|
|
import React from 'react'
|
2019-05-31 13:38:38 +02:00
|
|
|
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()
|
|
|
|
})
|
|
|
|
})
|