import { makeAppObjectRepo } from "@vived/core";
import { HideUCMock } from "../Mocks/HideUCMock";
import { makeTryHideWithPickUC, TryHideWithPickUC } from "./TryHideWithPickUC";
import { makeMockSceneRayPickUC } from "../../Babylon/Mocks/MockSceneRayPickUC";
import { ParametricLine, Vector2, Vector3 } from "@vived/core";
import { makeMockScenePixelPickUC } from "../../Babylon";
import { makeToolRepo, ToolState } from "../../Tools";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const registerSingleton = jest.spyOn(appObjects, "registerSingleton");
    const ao = appObjects.getOrCreate("AO");
    const uc = makeTryHideWithPickUC(ao);
    const hideableObj = appObjects.getOrCreate("hideableObj");
    const mockHideUC = new HideUCMock(hideableObj);
    const mockRayPick = makeMockSceneRayPickUC(appObjects);
    const mockPick = jest.fn().mockReturnValue({ appObjectID: "hideableObj" });
    mockRayPick.sceneRayPick = mockPick;
    const mockPixelPick = makeMockScenePixelPickUC(appObjects);
    mockPixelPick.scenePixelPick.mockReturnValue({ appObjectID: "hideableObj" });
    const toolRepo = makeToolRepo(appObjects.getOrCreate("ToolRepo"));
    const hideTool = toolRepo.makeTool("HIDE");
    hideTool.state = ToolState.ACTIVE;
    return {
        appObjects,
        ao,
        mockHideUC,
        uc,
        registerSingleton,
        mockPick,
        mockPixelPick,
        hideTool,
    };
}
describe("Hide UC", () => {
    it("Gets the singleton", () => {
        const { appObjects, uc } = makeTestRig();
        expect(TryHideWithPickUC.get(appObjects)).toEqual(uc);
    });
    it("Registers as the singleton", () => {
        const { registerSingleton, uc } = makeTestRig();
        expect(registerSingleton).toHaveBeenCalledWith(uc);
    });
    it("Picks with the ray", () => {
        const { uc, mockPick } = makeTestRig();
        const pickRay = ParametricLine.FromPointDirection(new Vector3(1, 2, 3), new Vector3(4, 5, 6));
        uc.tryRayPick(pickRay);
        expect(mockPick).toHaveBeenCalledWith(pickRay);
    });
    it("Calls the UC", () => {
        const { uc, mockHideUC } = makeTestRig();
        uc.tryRayPick(ParametricLine.Forward());
        expect(mockHideUC.hide).toHaveBeenCalled();
    });
    it("Doesn't warn if the picked object does not have the UC", () => {
        const { uc, mockPick, appObjects } = makeTestRig();
        appObjects.submitWarning = jest.fn();
        appObjects.getOrCreate("SomeOtherObject");
        mockPick.mockReturnValue({
            appObjectID: "SomeOtherObject",
        });
        uc.tryRayPick(ParametricLine.Forward());
        expect(appObjects.submitWarning).not.toHaveBeenCalled();
    });
    it("Picks with a pixel", () => {
        const { uc, mockPixelPick } = makeTestRig();
        const pickPixel = new Vector2(1, 2);
        uc.tryPixelPick(pickPixel);
        expect(mockPixelPick.scenePixelPick).toHaveBeenCalledWith(pickPixel);
    });
    it("Calls the UC", () => {
        const { uc, mockHideUC } = makeTestRig();
        uc.tryPixelPick(Vector2.One());
        expect(mockHideUC.hide).toHaveBeenCalled();
    });
    it("Returns true if the hide tool is active", () => {
        const { uc, hideTool } = makeTestRig();
        hideTool.state = ToolState.ACTIVE;
        expect(uc.allow()).toEqual(true);
    });
    it("Returns false if the hide tool is not active", () => {
        const { uc, hideTool } = makeTestRig();
        hideTool.state = ToolState.ENABLED;
        expect(uc.allow()).toEqual(false);
    });
});
//# sourceMappingURL=TryHideWithPickUC.test.js.map