import formUtils from '../../src/utils/formUtils';

describe('Testing formUtils', () => {
  describe('functions', () => {
    it('checkEmptyField should work', () => {
      // const checkEmptyField = (table: object[], columns: object[]): boolean
      // Valid
      expect(formUtils.checkEmptyField(
        [{ id: 1, name: 'test' }, { id: 2, name: 'test2' }],
        [{
          dataIndex: 'id',
          required: true,
        }, {
          dataIndex: 'name',
          required: true,
        }],
      )).toEqual(false);

      // Not Valid - null props
      expect(formUtils.checkEmptyField(
        [{ id: 1, name: 'test' }, { id: 2, name: null }],
        [{
          dataIndex: 'id',
          required: true,
        }, {
          dataIndex: 'name',
          required: true,
        }],
      )).toEqual(true);

      // Not Valid  - undefined props
      expect(formUtils.checkEmptyField(
        [{ name: 'test' }, { id: 2, name: 'test2' }],
        [{
          dataIndex: 'id',
          required: true,
        }, {
          dataIndex: 'name',
          required: true,
        }],
      )).toEqual(true);

      // Valid - dont check not required props
      expect(formUtils.checkEmptyField(
        [{ id: 1, name: 'test' }, { id: 2, name: null }],
        [{
          dataIndex: 'id',
          required: true,
        }, {
          dataIndex: 'name',
          required: false,
        }],
      )).toEqual(false);


    });
  });
});
