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__ / serialization.test.tsx
Size: Mime:
import './_setup'
import * as React from 'react'
import { render, cleanup, fireEvent } from 'react-testing-library'
import { OnSubmitFormArgs } from '../new-forms/forms/typings'
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('serializes properly by default', () => {
    expect.assertions(2)

    const inputsList = [
      {
        propertyName: 'eh',
        value: 'canada',
        type: 'text',
      },
    ]
    const formState = new OneFormState().setInputsList(inputsList)

    const handleSubmit = (args: OnSubmitFormArgs) => {
      const serialized = args.state.toJSON() as SerializedObj
      expect(serialized.eh).toEqual('canada')
      expect(Object.keys(serialized).length).toEqual(1)
    }

    // const MockedTextPlugin = jest.fn(TextBoxPlugin)
    const view = (
      <PluginsContext.Provider value={[TextBoxPlugin]}>
        <OneObserverForm state={formState} onSubmit={handleSubmit} />
      </PluginsContext.Provider>
    )

    const { getByText } = render(view)
    fireEvent.click(getByText(/Continue/))
  })

  // it.skip('supports custom serialization with plugins', () => {
  //   //
  // })
  // it.skip('serializes with custom form state', () => {
  //   //
  // })
})