1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00

test tweaks

This commit is contained in:
Matthias Kretschmann 2019-06-03 15:13:17 +02:00
parent 7d727bcdf9
commit e5ef417025
Signed by: m
GPG Key ID: 606EEEF3C479A91F
5 changed files with 37 additions and 18 deletions

View File

@ -115,6 +115,7 @@ export default class Files extends PureComponent<FilesProps, FilesStates> {
name={name}
value={JSON.stringify(files)}
onChange={onChange}
data-testid="files"
/>
<div className={styles.newItems}>

View File

@ -12,7 +12,6 @@ const stateMock = {
const propsMock = {
inputChange: () => null,
inputToArrayChange: () => null,
state: stateMock,
title: 'Hello',
description: 'description',

View File

@ -28,9 +28,6 @@ interface StepProps {
| ChangeEvent<HTMLSelectElement>
| ChangeEvent<HTMLTextAreaElement>
): void
inputToArrayChange(
event: ChangeEvent<HTMLSelectElement> | ChangeEvent<HTMLInputElement>
): void
fields?: Fields
state: any
title: string

View File

@ -1,11 +1,44 @@
import React from 'react'
import { render } from '@testing-library/react'
import { render, fireEvent } from '@testing-library/react'
import Publish from '.'
import { User } from '../../context'
import { userMockConnected } from '../../../__mocks__/user-mock'
describe('Progress', () => {
describe('Publish', () => {
it('renders without crashing', () => {
const { container, getByText } = render(<Publish />)
const { container, getByText } = render(
<User.Provider value={userMockConnected}>
<Publish />
</User.Provider>
)
expect(container.firstChild).toBeInTheDocument()
expect(getByText('Next →')).toHaveAttribute('disabled')
})
it('next button works', () => {
const { getByText, getByLabelText, getByTestId } = render(
<User.Provider value={userMockConnected}>
<Publish />
</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 →'))
})
})

View File

@ -83,16 +83,6 @@ export default class Publish extends Component<{}, PublishState> {
})
}
private inputToArrayChange = (
event: ChangeEvent<HTMLInputElement> | ChangeEvent<HTMLSelectElement>
) => {
this.validateInputs(event.currentTarget.name, event.currentTarget.value)
this.setState({
[event.currentTarget.name]: [event.currentTarget.value]
})
}
private next = () => {
let { currentStep } = this.state
const totalSteps = steps.length
@ -353,7 +343,6 @@ export default class Publish extends Component<{}, PublishState> {
currentStep={this.state.currentStep}
fields={step.fields}
inputChange={this.inputChange}
inputToArrayChange={this.inputToArrayChange}
state={this.state}
next={this.next}
prev={this.prev}