import { formatDate, getDayOfWeekIndex, getFirstWorkDayOfWeek, getLastWorkDayOfWeek, getWeekNumber } from "../utils";

test('získání indexu dne v týdnu', () => {
    let date = new Date("2023-10-01");
    expect(getDayOfWeekIndex(date)).toBe(6);
    date = new Date("2023-10-02");
    expect(getDayOfWeekIndex(date)).toBe(0);
    date = new Date("2023-10-03");
    expect(getDayOfWeekIndex(date)).toBe(1);
    date = new Date("2023-10-04");
    expect(getDayOfWeekIndex(date)).toBe(2);
    date = new Date("2023-10-05");
    expect(getDayOfWeekIndex(date)).toBe(3);
    date = new Date("2023-10-06");
    expect(getDayOfWeekIndex(date)).toBe(4);
    date = new Date("2023-10-07");
    expect(getDayOfWeekIndex(date)).toBe(5);
    date = new Date("2023-10-08");
    expect(getDayOfWeekIndex(date)).toBe(6);
    date = new Date("2023-10-09");
    expect(getDayOfWeekIndex(date)).toBe(0);
});

test('získání data prvního/posledního dne v týdnu', () => {
    let date = new Date("2023-10-02");
    expect(formatDate(getFirstWorkDayOfWeek(date))).toBe("2023-10-02");
    expect(formatDate(getLastWorkDayOfWeek(date))).toBe("2023-10-06");
    date = new Date("2023-10-03");
    expect(formatDate(getFirstWorkDayOfWeek(date))).toBe("2023-10-02");
    expect(formatDate(getLastWorkDayOfWeek(date))).toBe("2023-10-06");
    date = new Date("2023-10-04");
    expect(formatDate(getFirstWorkDayOfWeek(date))).toBe("2023-10-02");
    expect(formatDate(getLastWorkDayOfWeek(date))).toBe("2023-10-06");
    date = new Date("2023-10-05");
    expect(formatDate(getFirstWorkDayOfWeek(date))).toBe("2023-10-02");
    expect(formatDate(getLastWorkDayOfWeek(date))).toBe("2023-10-06");
    date = new Date("2023-10-06");
    expect(formatDate(getFirstWorkDayOfWeek(date))).toBe("2023-10-02");
    expect(formatDate(getLastWorkDayOfWeek(date))).toBe("2023-10-06");
    date = new Date("2023-10-07");
    expect(formatDate(getFirstWorkDayOfWeek(date))).toBe("2023-10-02");
    expect(formatDate(getLastWorkDayOfWeek(date))).toBe("2023-10-06");
    date = new Date("2023-10-08");
    expect(formatDate(getFirstWorkDayOfWeek(date))).toBe("2023-10-02");
    expect(formatDate(getLastWorkDayOfWeek(date))).toBe("2023-10-06");

    date = new Date("2023-01-01");
    expect(formatDate(getFirstWorkDayOfWeek(date))).toBe("2022-12-26");
    expect(formatDate(getLastWorkDayOfWeek(date))).toBe("2022-12-30");
    date = new Date("2023-01-02");
    expect(formatDate(getFirstWorkDayOfWeek(date))).toBe("2023-01-02");
    expect(formatDate(getLastWorkDayOfWeek(date))).toBe("2023-01-06");
    date = new Date("2023-01-03");
    expect(formatDate(getFirstWorkDayOfWeek(date))).toBe("2023-01-02");
    expect(formatDate(getLastWorkDayOfWeek(date))).toBe("2023-01-06");
    date = new Date("2023-01-04");
    expect(formatDate(getFirstWorkDayOfWeek(date))).toBe("2023-01-02");
    expect(formatDate(getLastWorkDayOfWeek(date))).toBe("2023-01-06");
    date = new Date("2023-01-05");
    expect(formatDate(getFirstWorkDayOfWeek(date))).toBe("2023-01-02");
    expect(formatDate(getLastWorkDayOfWeek(date))).toBe("2023-01-06");
    date = new Date("2023-01-06");
    expect(formatDate(getFirstWorkDayOfWeek(date))).toBe("2023-01-02");
    expect(formatDate(getLastWorkDayOfWeek(date))).toBe("2023-01-06");
    date = new Date("2023-01-07");
    expect(formatDate(getFirstWorkDayOfWeek(date))).toBe("2023-01-02");
    expect(formatDate(getLastWorkDayOfWeek(date))).toBe("2023-01-06");
    date = new Date("2023-01-08");
    expect(formatDate(getFirstWorkDayOfWeek(date))).toBe("2023-01-02");
    expect(formatDate(getLastWorkDayOfWeek(date))).toBe("2023-01-06");

    date = new Date("2023-12-25");
    expect(formatDate(getFirstWorkDayOfWeek(date))).toBe("2023-12-25");
    expect(formatDate(getLastWorkDayOfWeek(date))).toBe("2023-12-29");
    date = new Date("2023-12-26");
    expect(formatDate(getFirstWorkDayOfWeek(date))).toBe("2023-12-25");
    expect(formatDate(getLastWorkDayOfWeek(date))).toBe("2023-12-29");
    date = new Date("2023-12-27");
    expect(formatDate(getFirstWorkDayOfWeek(date))).toBe("2023-12-25");
    expect(formatDate(getLastWorkDayOfWeek(date))).toBe("2023-12-29");
    date = new Date("2023-12-28");
    expect(formatDate(getFirstWorkDayOfWeek(date))).toBe("2023-12-25");
    expect(formatDate(getLastWorkDayOfWeek(date))).toBe("2023-12-29");
    date = new Date("2023-12-29");
    expect(formatDate(getFirstWorkDayOfWeek(date))).toBe("2023-12-25");
    expect(formatDate(getLastWorkDayOfWeek(date))).toBe("2023-12-29");
    date = new Date("2023-12-30");
    expect(formatDate(getFirstWorkDayOfWeek(date))).toBe("2023-12-25");
    expect(formatDate(getLastWorkDayOfWeek(date))).toBe("2023-12-29");
    date = new Date("2023-12-31");
    expect(formatDate(getFirstWorkDayOfWeek(date))).toBe("2023-12-25");
    expect(formatDate(getLastWorkDayOfWeek(date))).toBe("2023-12-29");
});

test('získání čísla týdne v roce', () => {
    let date = new Date("2023-10-01");
    expect(getWeekNumber(date)).toBe(39);
    date = new Date("2023-10-02");
    expect(getWeekNumber(date)).toBe(40);
    date = new Date("2023-10-03");
    expect(getWeekNumber(date)).toBe(40);
    date = new Date("2023-10-04");
    expect(getWeekNumber(date)).toBe(40);
    date = new Date("2023-10-05");
    expect(getWeekNumber(date)).toBe(40);
    date = new Date("2023-10-06");
    expect(getWeekNumber(date)).toBe(40);
    date = new Date("2023-10-07");
    expect(getWeekNumber(date)).toBe(40);
    date = new Date("2023-10-08");
    expect(getWeekNumber(date)).toBe(40);
    date = new Date("2023-10-09");
    expect(getWeekNumber(date)).toBe(41);

    date = new Date("2022-01-01");
    expect(getWeekNumber(date)).toBe(52);

    date = new Date("2022-12-30");
    expect(getWeekNumber(date)).toBe(52);
    date = new Date("2022-12-31");
    expect(getWeekNumber(date)).toBe(52);
    date = new Date("2023-01-01");
    expect(getWeekNumber(date)).toBe(52);
    date = new Date("2023-01-02");
    expect(getWeekNumber(date)).toBe(1);
    date = new Date("2023-01-03");
    expect(getWeekNumber(date)).toBe(1);
    date = new Date("2023-01-04");
    expect(getWeekNumber(date)).toBe(1);
    date = new Date("2023-01-05");
    expect(getWeekNumber(date)).toBe(1);
    date = new Date("2023-01-06");
    expect(getWeekNumber(date)).toBe(1);
    date = new Date("2023-01-07");
    expect(getWeekNumber(date)).toBe(1);
    date = new Date("2023-01-08");
    expect(getWeekNumber(date)).toBe(1);
    date = new Date("2023-01-09");
    expect(getWeekNumber(date)).toBe(2);

    date = new Date("2023-12-24");
    expect(getWeekNumber(date)).toBe(51);
    date = new Date("2023-12-25");
    expect(getWeekNumber(date)).toBe(52);
    date = new Date("2023-12-26");
    expect(getWeekNumber(date)).toBe(52);
    date = new Date("2023-12-27");
    expect(getWeekNumber(date)).toBe(52);
    date = new Date("2023-12-28");
    expect(getWeekNumber(date)).toBe(52);
    date = new Date("2023-12-29");
    expect(getWeekNumber(date)).toBe(52);
    date = new Date("2023-12-30");
    expect(getWeekNumber(date)).toBe(52);
    date = new Date("2023-12-31");
    expect(getWeekNumber(date)).toBe(52);
    date = new Date("2024-01-01");
    expect(getWeekNumber(date)).toBe(1);
});