import DatetimeFormatConstraint from "../DatetimeFormatConstraint";

describe("datetimeFormatConstraint", () => {
  it("datetimeFormatConstraint checks for datetime", () => {
    const constraint = new DatetimeFormatConstraint(
      "datetime",
      "dd-MM-yyyy HH:mm",
      "dd-mm-yyyy hh:mm",
    );

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

    expect(constraint.id).toBe("Constraint.DateTime.MissingValue");

    expect(constraint.format).toBe("dd-MM-yyyy HH:mm");

    expect(constraint.defaultMessage).toBe(
      "Date and time should both be entered",
    );
    expect(constraint.formatLabel).toBe("dd-mm-yyyy hh:mm");

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

  it("datetimeFormatConstraint checks for datetime with am / pm", () => {
    const constraint = new DatetimeFormatConstraint(
      "datetime",
      "dd-MM-yyyy hh:mm a",
      "dd-mm-yyyy hh:mm am/pm",
    );

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

    expect(constraint.id).toBe("Constraint.DateTime.MissingValue");

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

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

    expect(constraint.validate("19-01-2010 13:37 PM")).toBe(false);
    expect(constraint.validate("19-01-2010 13:37 PM")).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("1:37 am")).toBe(false);
    expect(constraint.validate("13:37")).toBe(false);
    expect(constraint.validate("2010-01-01")).toBe(false);
  });

  it("datetimeFormatConstraint checks for timestamp", () => {
    const constraint = new DatetimeFormatConstraint(
      "timestamp",
      "dd-MM-yyyy HH:mm:ss.SSS",
      "dd-mm-yyyy hh:mm:ss.sss",
    );

    expect(constraint.id).toBe("Constraint.DateTime.MissingValue");

    expect(constraint.format).toBe("dd-MM-yyyy HH:mm:ss.SSS");

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

    expect(constraint.defaultMessage).toBe(
      "Date and time should both be entered",
    );
    expect(constraint.formatLabel).toBe("dd-mm-yyyy hh:mm:ss.sss");

    expect(constraint.validate("19-01-2010 13:37:37.137")).toBe(true);
    expect(constraint.validate("2010-01-01 15:14:58.2000")).toBe(false);
    expect(constraint.validate("2010-01-01")).toBe(false);
  });
});
