import DateTimeTimeFormatConstraint from "../DateTimeTimeFormatConstraint";

describe("dateTimeDateFormatConstraint", () => {
  it("dateTimeFormatConstraint checks for date", () => {
    const constraint = new DateTimeTimeFormatConstraint("HH:mm:ss", "hh:mm:ss");

    expect(constraint.hasValidation()).toBe(true);

    expect(constraint.id).toBe("Constraint.TimeFormat.InvalidFormat");

    expect(constraint.format).toBe("HH:mm:ss");

    expect(constraint.defaultMessage).toBe(
      "Time must be entered in the format ${format}",
    );
    expect(constraint.formatLabel).toBe("hh:mm:ss");

    expect(constraint.validate("13:37:01")).toBe(true);

    expect(constraint.validate("13:37")).toBe(false);
    expect(constraint.validate("19-01-2010")).toBe(false);
    expect(constraint.validate("19-01-2010 13:37")).toBe(false);
    expect(constraint.validate("2010-01-01 24:05")).toBe(false);
    expect(constraint.validate("2010-01-01")).toBe(false);
  });

  it("validates am/pm", () => {
    const constraint = new DateTimeTimeFormatConstraint(
      "hh:mm a",
      "hh:mm am/pm",
    );

    expect(constraint.hasValidation()).toBe(true);

    expect(constraint.id).toBe("Constraint.TimeFormat.InvalidFormat");

    expect(constraint.format).toBe("hh:mm a");
    expect(constraint.formatLabel).toBe("hh:mm am/pm");

    expect(constraint.validate("1:37 am")).toBe(true);
    expect(constraint.validate("1:37 pm")).toBe(true);
    expect(constraint.validate("1:37 AM")).toBe(true);
    expect(constraint.validate("1:37 PM")).toBe(true);

    expect(constraint.validate("13:37 PM")).toBe(false);
    expect(constraint.validate("13:37 PM")).toBe(false);

    expect(constraint.validate("13:37")).toBe(false);
    expect(constraint.validate("19-01-2010")).toBe(false);
    expect(constraint.validate("19-01-2010 13:37")).toBe(false);
    expect(constraint.validate("2010-01-01 24:05")).toBe(false);
    expect(constraint.validate("2010-01-01")).toBe(false);
  });
});
