"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const core_2 = require("@vived/core");
const MockSceneRayPickUC_1 = require("../../Babylon/Mocks/MockSceneRayPickUC");
const BaseApp_1 = require("../../BaseApp");
const ChallengeEntityMock_1 = require("../../Challenge/Mocks/ChallengeEntityMock");
const LabelDropRepo_1 = require("../Entities/LabelDropRepo");
const DragLabelDropUC_1 = require("./DragLabelDropUC");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const challenge = (0, ChallengeEntityMock_1.makeChallengeEntityMock)(appObjects);
    const baseApp = (0, BaseApp_1.makeBaseAppState)(appObjects.getOrCreate("BaseApp"));
    const labelDropAO = appObjects.getOrCreate("labelDrop");
    const labelDrop = (0, LabelDropRepo_1.makeLabelDropRepo)(labelDropAO);
    const changeObserver = jest.fn();
    labelDrop.addChangeObserver(changeObserver);
    const mockPick = (0, MockSceneRayPickUC_1.makeMockSceneRayPickUC)(appObjects);
    const dragLabelDropUC = (0, DragLabelDropUC_1.makeDragLabelDropUC)(labelDropAO);
    challenge.selectedChallenge = "LABEL_DROP";
    baseApp.isAuthoring = false;
    return {
        appObjects,
        labelDrop,
        dragLabelDropUC,
        changeObserver,
        baseApp,
        challenge,
        mockPick,
    };
}
describe("Drag Label Drop UC", () => {
    it("initializes id, screenMode, position, and alpha", () => {
        const { dragLabelDropUC, labelDrop } = makeTestRig();
        expect(labelDrop.draggingID).toBeUndefined();
        dragLabelDropUC.initialize("id1", new core_2.Vector2(1, 2));
        expect(labelDrop.draggingID).toEqual("id1");
        expect(labelDrop.dragMode).toEqual(LabelDropRepo_1.LabelDropDragMode.SCREEN);
        expect(labelDrop.dragAlpha).toEqual(1);
        expect(labelDrop.screenPosition).toEqual(new core_2.Vector2(1, 2));
    });
    it("Does not initialize if challenge is not label drop", () => {
        const { dragLabelDropUC, labelDrop, challenge } = makeTestRig();
        challenge.selectedChallenge = "NONE";
        dragLabelDropUC.initialize("id1", core_2.Vector2.Zero());
        expect(labelDrop.draggingID).toBeUndefined();
    });
    it("Does not initialize if authoring", () => {
        const { dragLabelDropUC, labelDrop, baseApp } = makeTestRig();
        baseApp.isAuthoring = true;
        dragLabelDropUC.initialize("id1", core_2.Vector2.Zero());
        expect(labelDrop.draggingID).toBeUndefined();
    });
    it("Can set the 2D position", () => {
        const { dragLabelDropUC, labelDrop } = makeTestRig();
        dragLabelDropUC.initialize("id", core_2.Vector2.Zero());
        dragLabelDropUC.setPosition2D(new core_2.Vector2(1, 2));
        expect(labelDrop.screenPosition).toEqual(new core_2.Vector2(1, 2));
    });
    it("Does not set the 2D position if it did not initialize", () => {
        const { dragLabelDropUC, labelDrop } = makeTestRig();
        labelDrop.screenPosition = core_2.Vector2.Zero();
        dragLabelDropUC.setPosition2D(new core_2.Vector2(1, 2));
        expect(labelDrop.screenPosition).not.toEqual(new core_2.Vector2(1, 2));
    });
    it("Submits the object hit when released", () => {
        const { dragLabelDropUC, labelDrop, mockPick } = makeTestRig();
        mockPick.sceneRayPick.mockReturnValue({
            worldPickPoint: new core_2.Vector3(1, 2, 3),
            hit: true,
            normal: new core_2.Vector3(4, 5, 6),
            objectPickMeta: {
                appObjectID: "appObj1",
            },
        });
        dragLabelDropUC.initialize("labelDrop1", core_2.Vector2.Zero());
        labelDrop.submitLabelDrop = jest.fn();
        dragLabelDropUC.release(core_2.ParametricLine.Forward());
        expect(labelDrop.submitLabelDrop).toHaveBeenCalledWith("labelDrop1", "appObj1");
    });
    it("submits a label drop answer if an app object is hit", async () => {
        jest.useFakeTimers();
        const { dragLabelDropUC, labelDrop, mockPick } = makeTestRig();
        mockPick.sceneRayPick.mockReturnValue({
            worldPickPoint: new core_2.Vector3(1, 2, 3),
            hit: true,
            normal: new core_2.Vector3(4, 5, 6),
            objectPickMeta: {
                appObjectID: "appObj1",
            },
        });
        labelDrop.submitLabelDrop = jest.fn();
        dragLabelDropUC.initialize("labelDrop1", core_2.Vector2.Zero());
        dragLabelDropUC.release(core_2.ParametricLine.Forward());
        expect(labelDrop.submitLabelDrop).toHaveBeenCalled();
    });
    it("Does not submit a label drop answer if an app object is not hit", async () => {
        const { dragLabelDropUC, labelDrop, mockPick } = makeTestRig();
        mockPick.sceneRayPick.mockReturnValue({
            worldPickPoint: new core_2.Vector3(1, 2, 3),
            hit: false,
            normal: new core_2.Vector3(4, 5, 6),
        });
        labelDrop.submitLabelDrop = jest.fn();
        dragLabelDropUC.initialize("labelDrop1", core_2.Vector2.Zero());
        dragLabelDropUC.release(core_2.ParametricLine.Forward());
        expect(labelDrop.submitLabelDrop).not.toHaveBeenCalled();
    });
    it("Does not submit if no object hit on release", () => {
        const { dragLabelDropUC, labelDrop, mockPick } = makeTestRig();
        mockPick.sceneRayPick.mockReturnValue({
            worldPickPoint: new core_2.Vector3(1, 2, 3),
            hit: false,
            normal: new core_2.Vector3(4, 5, 6),
            objectPickMeta: {},
        });
        dragLabelDropUC.initialize("labelDrop1", core_2.Vector2.Zero());
        labelDrop.submitLabelDrop = jest.fn();
        dragLabelDropUC.release(core_2.ParametricLine.Forward());
        expect(labelDrop.submitLabelDrop).not.toHaveBeenCalled();
    });
    it("Does not wait to animate if no object is hit", async () => {
        jest.useFakeTimers();
        const { dragLabelDropUC, labelDrop, mockPick } = makeTestRig();
        mockPick.sceneRayPick.mockReturnValue({
            worldPickPoint: new core_2.Vector3(1, 2, 3),
            hit: false,
            normal: new core_2.Vector3(4, 5, 6),
        });
        dragLabelDropUC.initialize("labelDrop1", core_2.Vector2.Zero());
        dragLabelDropUC.onFinishRelease();
        jest.advanceTimersByTime(1000);
        expect(labelDrop.dragAlpha).toEqual(0);
    });
});
//# sourceMappingURL=DragLabelDropUC.test.js.map