import { calcAutoZoom, calcDefaultResolution } from "@ax/components/Browser/utils";

const resolutionOptions = [
	{ value: "1920px" },
	{ value: "1440px" },
	{ value: "1280px" },
	{ value: "1024px" },
	{ value: "768px" },
	{ value: "360px" },
];

describe("calcAutoZoom", () => {
	it("should return '100' when containerWidth is 0", () => {
		expect(calcAutoZoom(0, "1280px")).toBe("100");
	});

	it("should return '100' when resolution is not parseable", () => {
		expect(calcAutoZoom(1000, "")).toBe("100");
	});

	it("should return '100' when container exactly matches resolution", () => {
		expect(calcAutoZoom(1280, "1280px")).toBe("100");
	});

	it("should cap at '100' when container is wider than resolution", () => {
		expect(calcAutoZoom(1920, "1280px")).toBe("100");
	});

	it("should return the floored percentage when container is narrower than resolution", () => {
		expect(calcAutoZoom(640, "1280px")).toBe("50");
	});

	it("should floor fractional zoom values", () => {
		// 700 / 1280 = 54.6875% -> floors to 54
		expect(calcAutoZoom(700, "1280px")).toBe("54");
	});
});

describe("calcDefaultResolution", () => {
	it("should return the smallest option >= containerWidth", () => {
		expect(calcDefaultResolution(500, resolutionOptions)).toBe("768px");
	});

	it("should return the exact match when containerWidth equals a resolution value", () => {
		expect(calcDefaultResolution(1280, resolutionOptions)).toBe("1280px");
	});

	it("should return the largest option when containerWidth exceeds all options", () => {
		expect(calcDefaultResolution(2560, resolutionOptions)).toBe("1920px");
	});

	it("should return the smallest option for a very small containerWidth", () => {
		expect(calcDefaultResolution(100, resolutionOptions)).toBe("360px");
	});
});
