import { makeParserPair } from "../../../src/Form/DateInput/formatter";

const locales = ["en-US", "de-DE", "zh-CN", "zh-TW", "cs-CZ", "nl-BE", "nl-NL", "en-AU", "en-GB", "en-CA", "en-NZ", "en-SG", "fr-BE", "fr-CA", "fr-FR", "fr-CH", "de-AT", "de-LI", "de-CH", "it-IT", "it-CH", "ja-JP", "ko-KR", "pl-PL", "ru-RU", "es-ES", "bg-BG", "ca-ES", "hr-HR", "da-DK", "en-IN", "en-IE", "en-ZA", "fi-FI", "el-GR", "iw-IL", "hi-IN", "hu-HU", "in-ID", "lv-LV", "lt-LT", "nb-NO", "pt-BR", "pt-PT", "ro-RO", "sr-RS", "sk-SK", "sl-SI", "es-US", "sv-SE", "tl-PH", "tr-TR", "uk-UA", "vi-VN"];

locales.forEach(locale => {
  const [formatter, parser] = makeParserPair(locale);
  const now = new Date().toDateString();

  test(`Formatted text can be parsed in ${locale}`, () => {
    expect(parser(formatter(new Date())).toDateString()).toBe(now);
  });
});

test(`Incorrect dates return false`, () => {
  const [formatter, parser] = makeParserPair("nl-NL");
  expect(parser("DEADBEEF")).toBe(false);
});

test(`Overflowing parts are rejected`, () => {
  const [formatter, parser] = makeParserPair("nl-NL");
  expect(parser("32-03-2021")).toBe(false);
  expect(parser("22-13-2021")).toBe(false);
});