2023-09-11 13:45:15 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import { render, screen } from "@testing-library/react";
|
|
|
|
|
import { renderWithSetup } from "test/test-utils";
|
|
|
|
|
|
2023-10-16 15:43:47 +00:00
|
|
|
import {
|
|
|
|
|
HumanTimeDiffWithDateTip,
|
|
|
|
|
HumanTimeDiffWithFleetLaunchCutoff,
|
|
|
|
|
} from "./HumanTimeDiffWithDateTip";
|
2023-09-11 13:45:15 +00:00
|
|
|
|
|
|
|
|
const EMPTY_STRING = "Unavailable";
|
|
|
|
|
const INVALID_STRING = "Invalid date";
|
|
|
|
|
|
|
|
|
|
describe("HumanTimeDiffWithDateTip - component", () => {
|
|
|
|
|
it("renders tooltip on hover", async () => {
|
|
|
|
|
const { user } = renderWithSetup(
|
|
|
|
|
<HumanTimeDiffWithDateTip timeString="2015-12-06T10:30:00Z" />
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Note: number of years varies over time
|
|
|
|
|
await user.hover(screen.getByText(/years ago/i));
|
|
|
|
|
|
|
|
|
|
// Note: hour of day varies for timezones
|
|
|
|
|
expect(screen.getByText(/12\/6\/2015/i)).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("handles empty string error", async () => {
|
|
|
|
|
render(<HumanTimeDiffWithDateTip timeString="" />);
|
|
|
|
|
|
|
|
|
|
const emptyStringText = screen.getByText(EMPTY_STRING);
|
|
|
|
|
expect(emptyStringText).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("handles invalid string error", async () => {
|
|
|
|
|
render(<HumanTimeDiffWithDateTip timeString="foobar" />);
|
|
|
|
|
|
|
|
|
|
const invalidStringText = screen.getByText(INVALID_STRING);
|
|
|
|
|
expect(invalidStringText).toBeInTheDocument();
|
|
|
|
|
});
|
2023-10-16 15:43:47 +00:00
|
|
|
|
|
|
|
|
it("returns never if configured to cutoff dates before Fleet was created", async () => {
|
|
|
|
|
render(
|
|
|
|
|
<HumanTimeDiffWithFleetLaunchCutoff timeString="1970-01-02T00:00:00Z" />
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(screen.getByText(/never/i)).toBeInTheDocument();
|
|
|
|
|
});
|
2023-09-11 13:45:15 +00:00
|
|
|
});
|