import React from 'react';
import { createShallow } from '@material-ui/core/test-utils';

import FormMemo, { Form } from './Form';

const testFields = [
  {
    fieldName: 'currentPassword',
    placeholder: 'Inserisci password attuale',
    label: 'Password attuale',
    type: 'password',
    margin: 'none',
    required: true
  },
  {
    fieldName: 'password',
    placeholder: 'Inserisci nuova password',
    label: 'Nuova password',
    type: 'password',
    margin: 'none',
    required: true,
    helperText:
      'Assicurati che la password risulti solida: digita almeno 8 caratteri che contengano lettere in maiuscolo, minuscole, numeri e caratteri speciali'
  },
  {
    fieldName: 'confirmNewPassword',
    placeholder: 'Conferma nuova password',
    label: 'Conferma nuova password',
    type: 'password',
    required: true,
    margin: 'none'
  }
];

describe('<Form />', () => {
  const shallow = createShallow();

  it('shallow render without crashing', () => {
    const wrapper = shallow(
      <Form
        fields={testFields}
        title='Title'
        description='Description'
        onSubmit={() => {}}
        onValidate={() => {}}
      />
    );
    expect(wrapper).toMatchSnapshot();
  });

  it('shallow render memoized component without crashing', () => {
    const wrapper = shallow(
      <FormMemo
        fields={testFields}
        title='Title'
        description='Description'
        onSubmit={() => {}}
        onValidate={() => {}}
      />
    );
    expect(wrapper).toMatchSnapshot();
  });
});
