import { screen, render, fireEvent, waitFor } from "@testing-library/react";
import { TimeStamp } from "..";
const date = new Date("2023-02-05T15:08:46.180456");
describe("TimeStamp component", () => {
    test("Rendering Time Stamp", () => {
        render(<TimeStamp {...{date: "2023-02-05T15:08:46.180456", timeZone: "America/Los_Angeles", timeFormat: "MM/DD/YYYY HH:mm:ss"}} />)
    })
    test("Render PST timezone", () => {
        const wrapper = render(<TimeStamp {...{date: "2023-02-05T15:08:46.180456", timeZone: "America/Los_Angeles", timeFormat: "MM/DD/YYYY HH:mm:ss"}} />)
        const timestamp = wrapper.getByTestId("timestamp");
        expect(timestamp.textContent).toBe("02/05/2023 01:38:46");
    })
    test("Rendering Europe timezone", () => {
        const wrapper = render(<TimeStamp {...{date: "2023-02-05T15:08:46.180456", timeZone: "Europe/Berlin", timeFormat: "MM/DD/YYYY HH:mm:ss"}} />)
        const timestamp = wrapper.getByTestId("timestamp");
        expect(timestamp.textContent).toBe("02/05/2023 10:38:46");
    })
    test("Rendering America/Toronto timezone", () => {
        const wrapper = render(<TimeStamp {...{date: "2023-02-05T15:08:46.180456", timeZone: "America/Toronto", timeFormat: "MM/DD/YYYY HH:mm:ss"}} />)
        const timestamp = wrapper.getByTestId("timestamp");
        expect(timestamp.textContent).toBe("02/05/2023 04:38:46");
    })
    test("Rendering America/New_York timezone", () => {
        const wrapper = render(<TimeStamp {...{date: "2023-02-05T15:08:46.180456", timeZone: "America/New_York", timeFormat: "MM/DD/YYYY HH:mm:ss"}} />)
        const timestamp = wrapper.getByTestId("timestamp");
        expect(timestamp.textContent).toBe("02/05/2023 04:38:46");
    })
    test("Rendering Asia/Tokyo timezone", () => {
        const wrapper = render(<TimeStamp {...{date: "2023-02-05T15:08:46.180456", timeZone: "Asia/Tokyo", timeFormat: "MM/DD/YYYY HH:mm:ss"}} />)
        const timestamp = wrapper.getByTestId("timestamp");
        expect(timestamp.textContent).toBe("02/05/2023 18:38:46");
    })
    test("Rendering Asia/Kolkata timezone", () => {
        const wrapper = render(<TimeStamp {...{date: "2023-02-05T15:08:46.180456", timeZone: "Asia/Kolkata", timeFormat: "MM/DD/YYYY HH:mm:ss"}} />)
        const timestamp = wrapper.getByTestId("timestamp");
        expect(timestamp.textContent).toBe("02/05/2023 15:08:46");
    })
    test("Testing timeformat mm-dd-yyyy", () => {
        const wrapper = render(<TimeStamp {...{date: "2023-02-05T15:08:46.180456", timeZone: "America/Los_Angeles", timeFormat: "mm-dd-yyyy"}} />)
        const timestamp = wrapper.getByTestId("timestamp");
        expect(timestamp.textContent).toBe("38-Su-yyyy");
    })
    test("Testing Date only format", () => {
        const wrapper = render(<TimeStamp {...{date: "2023-02-05T15:08:46.180456", timeZone: "America/Los_Angeles", timeFormat: "YYYY-MM-DD"}} />)
        const timestamp = wrapper.getByTestId("timestamp");
        expect(timestamp.textContent).toBe("2023-02-05");
    })
    test("Testing Time only format", () => {
        const wrapper = render(<TimeStamp {...{date: "2023-02-05T15:08:46.180456", timeZone: "America/Los_Angeles", timeFormat: "HH:mm:ss"}} />)
        const timestamp = wrapper.getByTestId("timestamp");
        expect(timestamp.textContent).toBe("01:38:46");
    })
    test("Testing Date and time format", () => {
        const wrapper = render(<TimeStamp {...{date: "2023-02-05T15:08:46.180456", timeZone: "America/Los_Angeles", timeFormat: "YYYY-MM-DD HH:mm:ss"}} />)
        const timestamp = wrapper.getByTestId("timestamp");
        expect(timestamp.textContent).toBe("2023-02-05 01:38:46");
    })
    test("Testing Date and time with timezone format", () => {
        const wrapper = render(<TimeStamp {...{date: "2023-02-05T15:08:46.180456", timeZone: "America/Los_Angeles", timeFormat: "YYYY-MM-DD HH:mm:ss Z"}} />)
        const timestamp = wrapper.getByTestId("timestamp");
        expect(timestamp.textContent).toBe("2023-02-05 01:38:46 -08:00");
    })
    test("Testing Date and time with abbreviated timezone format", () => {
        const wrapper = render(<TimeStamp {...{date: "2023-02-05T15:08:46.180456", timeZone: "America/Los_Angeles", timeFormat: "YYYY-MM-DD HH:mm:ss A z"}} />)
        const timestamp = wrapper.getByTestId("timestamp");
        expect(timestamp.textContent).toBe("2023-02-05 01:38:46 AM z");
    })
    test("Empty field date", () => {
        const wrapper = render(<TimeStamp {...{date: "", timeZone: "America/Los_Angeles", timeFormat: "MM/DD/YYYY HH:mm:ss"}} />)
        const timestamp = wrapper.getByTestId("timestamp");
        expect(timestamp.textContent).toBe("");
    })
    test("Input time is always should be in the UTC", () => {
        const isoString = date.toISOString();
        const isUtc = isoString.endsWith('Z'); 
        expect(isUtc).toBe(true)
    })
})