import {
  emptyValidation,
  mediumTextValidation,
  minValidation,
  maxValidation,
  dateBeforeValidation,
  dateAfterValidation,
  dateSameOrAfterValidation,
  dateSameOrBeforeValidation,
  passwordValidation,
} from './validators';

describe('Validators', () => {
  const $t = (str) => str;

  test('emptyValidation', () => {
    expect(emptyValidation()('', $t)).toEqual('components.thisFieldIsRequired');
    expect(emptyValidation()(' ', $t)).toEqual('components.thisFieldIsRequired');
    expect(emptyValidation()(null, $t)).toEqual('components.thisFieldIsRequired');
    expect(emptyValidation()(undefined, $t)).toEqual('components.thisFieldIsRequired');
    expect(emptyValidation()('1', $t)).toEqual(true);
    expect(emptyValidation()(' 1 ', $t)).toEqual(true);
  });

  test('minValidation', () => {
    expect(minValidation()(0, $t)).toEqual(true);
    expect(minValidation()(null, $t)).toEqual('components.theValueMustBeGreaterThanOrEqualToMin');
    expect(minValidation()(undefined, $t)).toEqual('components.theValueMustBeGreaterThanOrEqualToMin');
    expect(minValidation(1)(0, $t)).toEqual('components.theValueMustBeGreaterThanOrEqualToMin');
    expect(minValidation(1)('0', $t)).toEqual('components.theValueMustBeGreaterThanOrEqualToMin');
  });

  test('maxValidation', () => {
    expect(maxValidation(1)(0, $t)).toEqual(true);
    expect(maxValidation()(null, $t)).toEqual('components.mustBeLessThanMax');
    expect(maxValidation()(undefined, $t)).toEqual('components.mustBeLessThanMax');
    expect(maxValidation(1)(0, $t)).toEqual(true);
    expect(maxValidation(1)('0', $t)).toEqual(true);
  });

  test('dateBeforeValidation', () => {
    expect(dateBeforeValidation()(0, $t)).toEqual(true);
    expect(dateBeforeValidation()(null, $t)).toEqual(true);
    expect(dateBeforeValidation()(undefined, $t)).toEqual(true);
    expect(dateBeforeValidation('2020-01-02')('2020-01-01', $t)).toEqual(true);
    expect(dateBeforeValidation('2020-01-01')('2020-01-02', $t)).toEqual('components.dateBefore');
    expect(dateBeforeValidation('2020-01-01')('2020-01-01', $t)).toEqual('components.dateBefore');
  });

  test('dateAfterValidation', () => {
    expect(dateAfterValidation()(0, $t)).toEqual(true);
    expect(dateAfterValidation()(null, $t)).toEqual(true);
    expect(dateAfterValidation()(undefined, $t)).toEqual(true);
    expect(dateAfterValidation('2020-01-02')('2020-01-01', $t)).toEqual('components.dateAfter');
    expect(dateAfterValidation('2020-01-01')('2020-01-02', $t)).toEqual(true);
    expect(dateAfterValidation('2020-01-01')('2020-01-01', $t)).toEqual('components.dateAfter');
  });

  test('dateSameOrAfterValidation', () => {
    expect(dateSameOrAfterValidation()(0, $t)).toEqual(true);
    expect(dateSameOrAfterValidation()(null, $t)).toEqual(true);
    expect(dateSameOrAfterValidation()(undefined, $t)).toEqual(true);
    expect(dateSameOrAfterValidation('2020-01-02')('2020-01-01', $t)).toEqual('components.dateSameOrAfter');
    expect(dateSameOrAfterValidation('2020-01-01')('2020-01-02', $t)).toEqual(true);
    expect(dateSameOrAfterValidation('2020-01-01')('2020-01-01', $t)).toEqual(true);
  });

  test('dateSameOrBeforeValidation', () => {
    expect(dateSameOrBeforeValidation()(0, $t)).toEqual(true);
    expect(dateSameOrBeforeValidation()(null, $t)).toEqual(true);
    expect(dateSameOrBeforeValidation()(undefined, $t)).toEqual(true);
    expect(dateSameOrBeforeValidation('2020-01-02')('2020-01-01', $t)).toEqual(true);
    expect(dateSameOrBeforeValidation('2020-01-01')('2020-01-02', $t)).toEqual('components.dateSameOrBefore');
    expect(dateSameOrBeforeValidation('2020-01-01')('2020-01-01', $t)).toEqual(true);
  });

  test('mediumTextValidation', () => {
    expect(mediumTextValidation()(0, $t)).toEqual(true);
    expect(mediumTextValidation()(null, $t)).toEqual(true);
    expect(mediumTextValidation()(undefined, $t)).toEqual(true);
    expect(mediumTextValidation()('abc', $t)).toEqual(true);
    expect(mediumTextValidation()('0'.repeat(16777215), $t)).toEqual(true);
    expect(mediumTextValidation()('0'.repeat(16777216), $t)).toEqual('components.mediumTextLength');
  });


  test('passwordValidation', () => {
    expect(passwordValidation()('', $t)).toEqual('components.passwordValidation');
    expect(passwordValidation()(' ', $t)).toEqual('components.passwordValidation');
    expect(passwordValidation()(null, $t)).toEqual('components.passwordValidation');
    expect(passwordValidation()(undefined, $t)).toEqual('components.passwordValidation');
    expect(passwordValidation()(' тесттест ', $t)).toEqual('components.passwordValidation');
    expect(passwordValidation()(' ТЕСТТЕСТ ', $t)).toEqual('components.passwordValidation');
    expect(passwordValidation()(' ТестТест ', $t)).toEqual('components.passwordValidation');
    expect(passwordValidation()(' ТестТест1 ', $t)).toEqual('components.passwordValidation');
    expect(passwordValidation()(' ТестТест1@ ', $t)).toEqual(true);
  });
});
