Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/forms / src / __tests__ / validation.test.tsx
Size: Mime:
// - [ ] validation
// - run through validators with test data (don't fill it overly much, ask qa to fill)
// - test plugin validation
import * as React from 'react'
import * as snapshotDiff from 'snapshot-diff'
import { render, cleanup, fireEvent } from 'react-testing-library'
import './_setup'
import { OneFormState, OneObserverForm } from '..//new-forms/OneForm/OneForm'
import { PluginsContext } from '../new-forms/plugins/PluginsContext'
import { TextBoxPlugin } from '../new-forms/plugins/TextPlugin'
import { SerializedObj } from '../new-forms/typings'

describe('@skava/forms - validation', () => {
  afterEach(cleanup)

  it('validate on submit using default render', () => {
    const inputsList = [
      {
        type: 'text',
      },
    ]
    const formState = new OneFormState().setInputsList(inputsList)

    const handleSubmit = (serialized: SerializedObj) => {
      // doing nothing now
      // console.log(serialized)
    }
    const mockSubmit = jest.fn(handleSubmit)
    const view = (
      <PluginsContext.Provider value={[TextBoxPlugin]}>
        <OneObserverForm state={formState} onSubmit={mockSubmit} />
      </PluginsContext.Provider>
    )
    // const rendered = render(view)
    const { getByText, asFragment } = render(view)
    expect(mockSubmit.mock.calls.length).toEqual(0)

    const firstRender = asFragment()

    fireEvent.click(getByText(/Continue/))
    expect(mockSubmit.mock.calls.length).toEqual(1)

    const renderDiff = snapshotDiff(firstRender, asFragment())
    expect(renderDiff).toMatchSnapshot()

    // const renderer = ReactTestRenderer.create(view)
    // expect(renderer.toJSON()).toMatchSnapshot()
  })
})