var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import React from "react";
import { render } from "@testing-library/react";
import { describe, beforeEach, it, expect, vi } from "vitest";
import { Route } from "./index";
vi.mock("react-i18next", (importOriginal) => __awaiter(void 0, void 0, void 0, function* () {
    return (Object.assign(Object.assign({}, (yield importOriginal())), { useTranslation: () => ({
            t: (key) => key,
        }) }));
}));
const useRootElementMock = vi.fn();
vi.mock("../../context", () => ({
    useRootElement: () => useRootElementMock(),
}));
describe("Route Component", () => {
    beforeEach(() => {
        vi.resetAllMocks();
    });
    it("renders without crashing", () => {
        useRootElementMock.mockReturnValue({
            isOpen: true,
            commuteData: {
                duration: 3700, // 1 hour
                distance: 5000, // 5 km
            },
            distanceUnit: "metric",
        });
        const { getByTestId } = render(React.createElement(Route, null));
        const durationElement = getByTestId("commute-duration");
        const distanceElement = getByTestId("commute-distance");
        expect(durationElement).toBeInTheDocument();
        expect(durationElement.textContent).toBe("1 common:time.hour 1 common:time.minute");
        expect(distanceElement).toBeInTheDocument();
        expect(distanceElement.textContent).toBe("5 common:distance.kilometer - commute.results.fastestRoute");
    });
    it("does not render duration or distance when commuteData is empty", () => {
        useRootElementMock.mockReturnValue({
            isOpen: true,
            commuteData: null,
            distanceUnit: "metric",
        });
        const { container } = render(React.createElement(Route, null));
        expect(container).toBeEmptyDOMElement();
    });
    it("renders distance in imperial units when distanceUnit is 'imperial'", () => {
        useRootElementMock.mockReturnValue({
            isOpen: true,
            commuteData: {
                duration: 3700,
                distance: 5000, // 5 km
            },
            distanceUnit: "imperial",
        });
        const { getByTestId } = render(React.createElement(Route, null));
        const distanceElement = getByTestId("commute-distance");
        expect(distanceElement.textContent).toBe("3.1 common:distance.mile - commute.results.fastestRoute");
    });
});
//# sourceMappingURL=index.test.js.map