import { renderHook } from "@testing-library/react-hooks";
import { Image } from "react-native";

import { useGetImageDimensions } from "../useGetImageDimensions";
import { getDimension } from "../utils";

const WIDTH = 100;
const HEIGTH = 50;

jest.spyOn(Image, "getSize").mockImplementation((_uri, success) => {
  success(WIDTH, HEIGTH);
});

describe("useGetImageDimensions", () => {
  it("should return aspect ration initially when known dimensions", async () => {
    const { result, waitForNextUpdate } = renderHook(() =>
      useGetImageDimensions("https://some_url.com", WIDTH, undefined)
    );

    expect(result.current).toBeUndefined();
    await waitForNextUpdate();

    expect(result.current).toEqual(
      getDimension({ width: WIDTH, height: HEIGTH })
    );
  });
});
