"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const core_2 = require("@vived/core");
const Babylon_1 = require("../../Babylon");
const MockDispatchStateChange_1 = require("../../Dispatcher/Mocks/MockDispatchStateChange");
const Entities_1 = require("../Entities");
const RayPanScaleTransform_1 = require("./RayPanScaleTransform");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const ao = appObjects.getOrCreate("ao");
    const transform = (0, Entities_1.makeTransform3D)(ao);
    const mockDispatch = (0, MockDispatchStateChange_1.makeMockDispatchStateChange)(appObjects);
    const uc = (0, RayPanScaleTransform_1.makeRayPanScaleTransformUC)(ao);
    const mockPick = (0, Babylon_1.makeMockSceneRayPickUC)(appObjects);
    return {
        uc,
        appObjects,
        mockDispatch,
        mockPick,
        transform,
    };
}
describe("Drag Scale Scene Root UC", () => {
    it("Decreases the scale with forward movement", () => {
        const { uc, transform } = makeTestRig();
        transform.worldScale = core_2.Vector3.One();
        uc.initialize(core_2.ParametricLine.FromPointDirection(new core_2.Vector3(0, 0, -5), core_2.Vector3.Forward()));
        uc.update(core_2.ParametricLine.FromPointDirection(new core_2.Vector3(0, 0, -4), core_2.Vector3.Forward()));
        expect(transform.worldScale.x).toBeLessThan(1);
    });
    it("Increases the scale with backwards movement", () => {
        const { uc, transform } = makeTestRig();
        transform.worldScale = core_2.Vector3.One();
        uc.initialize(core_2.ParametricLine.FromPointDirection(new core_2.Vector3(0, 0, -4), core_2.Vector3.Forward()));
        uc.update(core_2.ParametricLine.FromPointDirection(new core_2.Vector3(0, 0, -5), core_2.Vector3.Forward()));
        expect(transform.worldScale.x).toBeGreaterThan(1);
    });
    it("Dispatches state change", () => {
        const { uc, mockDispatch } = makeTestRig();
        uc.initialize(core_2.ParametricLine.FromPointDirection(new core_2.Vector3(0, 0, 5), core_2.Vector3.Forward()));
        uc.update(core_2.ParametricLine.FromPointDirection(new core_2.Vector3(0, 0, 4.5), core_2.Vector3.Forward()));
        uc.finish();
        expect(mockDispatch.doDispatch).toHaveBeenCalled();
    });
    it("Does not dispatches state change if the scale does not change", () => {
        const { uc, mockDispatch } = makeTestRig();
        uc.initialize(core_2.ParametricLine.FromPointDirection(new core_2.Vector3(0, 0, 5), core_2.Vector3.Forward()));
        uc.finish();
        expect(mockDispatch.doDispatch).not.toHaveBeenCalled();
    });
    it("Does not dispatches state change if it was not initialized", () => {
        const { uc, mockDispatch } = makeTestRig();
        uc.finish();
        expect(mockDispatch.doDispatch).not.toHaveBeenCalled();
    });
    it("Does not scale if it is not initialized", () => {
        const { uc, transform } = makeTestRig();
        transform.worldScale = core_2.Vector3.One();
        uc.update(core_2.ParametricLine.FromPointDirection(new core_2.Vector3(0, 0, 4.5), core_2.Vector3.Forward()));
        expect(transform.worldScale.x).toEqual(1);
    });
    it("Limits the minimum scale", () => {
        const { uc, transform } = makeTestRig();
        uc.minScale = 0.5;
        transform.worldScale = core_2.Vector3.One();
        uc.initialize(core_2.ParametricLine.FromPointDirection(new core_2.Vector3(0, 0, -5), core_2.Vector3.Forward()));
        uc.update(core_2.ParametricLine.FromPointDirection(new core_2.Vector3(0, 0, -4), core_2.Vector3.Forward()));
        expect(transform.worldScale).toEqual(new core_2.Vector3(0.5, 0.5, 0.5));
    });
    it("Limits the maximum scale", () => {
        const { uc, transform } = makeTestRig();
        uc.maxScale = 1.5;
        transform.worldScale = core_2.Vector3.One();
        uc.initialize(core_2.ParametricLine.FromPointDirection(new core_2.Vector3(0, 0, -4), core_2.Vector3.Forward()));
        uc.update(core_2.ParametricLine.FromPointDirection(new core_2.Vector3(0, 0, -5), core_2.Vector3.Forward()));
        expect(transform.worldScale).toEqual(new core_2.Vector3(1.5, 1.5, 1.5));
    });
    it("Moves the transform", () => {
        const { transform, uc } = makeTestRig();
        uc.initialize(core_2.ParametricLine.FromPointDirection(new core_2.Vector3(0, 0, -4), core_2.Vector3.Forward()));
        uc.update(core_2.ParametricLine.FromPointDirection(new core_2.Vector3(1, 2, -4), core_2.Vector3.Forward()));
        expect(transform.worldPosition).toEqual(new core_2.Vector3(1, 2, 0));
    });
    it("Moves the transform relative to the initial position", () => {
        const { transform, uc } = makeTestRig();
        transform.worldPosition = new core_2.Vector3(10, 10, 10);
        uc.initialize(core_2.ParametricLine.FromPointDirection(new core_2.Vector3(0, 0, -4), core_2.Vector3.Forward()));
        uc.update(core_2.ParametricLine.FromPointDirection(new core_2.Vector3(1, 2, -4), core_2.Vector3.Forward()));
        expect(transform.worldPosition).toEqual(new core_2.Vector3(11, 12, 10));
    });
    it("Limits the minimum X", () => {
        const { transform, uc } = makeTestRig();
        uc.minX = 0;
        uc.initialize(core_2.ParametricLine.FromPointDirection(new core_2.Vector3(0, 0, -4), core_2.Vector3.Forward()));
        uc.update(core_2.ParametricLine.FromPointDirection(new core_2.Vector3(-1, 2, -4), core_2.Vector3.Forward()));
        expect(transform.worldPosition).toEqual(new core_2.Vector3(0, 2, 0));
    });
    it("Limits the maximum X", () => {
        const { transform, uc } = makeTestRig();
        uc.maxX = 0;
        uc.initialize(core_2.ParametricLine.FromPointDirection(new core_2.Vector3(0, 0, -4), core_2.Vector3.Forward()));
        uc.update(core_2.ParametricLine.FromPointDirection(new core_2.Vector3(1, 2, -4), core_2.Vector3.Forward()));
        expect(transform.worldPosition).toEqual(new core_2.Vector3(0, 2, 0));
    });
    it("Limits the minimum Y", () => {
        const { transform, uc } = makeTestRig();
        uc.minY = 0;
        uc.initialize(core_2.ParametricLine.FromPointDirection(new core_2.Vector3(0, 0, -4), core_2.Vector3.Forward()));
        uc.update(core_2.ParametricLine.FromPointDirection(new core_2.Vector3(-1, -2, -4), core_2.Vector3.Forward()));
        expect(transform.worldPosition).toEqual(new core_2.Vector3(-1, 0, 0));
    });
    it("Limits the maximum Y", () => {
        const { transform, uc } = makeTestRig();
        uc.maxY = 0;
        uc.initialize(core_2.ParametricLine.FromPointDirection(new core_2.Vector3(0, 0, -4), core_2.Vector3.Forward()));
        uc.update(core_2.ParametricLine.FromPointDirection(new core_2.Vector3(1, 2, -4), core_2.Vector3.Forward()));
        expect(transform.worldPosition).toEqual(new core_2.Vector3(1, 0, 0));
    });
    it("Does not update when disabled", () => {
        const { uc, transform } = makeTestRig();
        uc.enabled = false;
        transform.worldScale = core_2.Vector3.One();
        transform.worldPosition = core_2.Vector3.Zero();
        uc.initialize(core_2.ParametricLine.FromPointDirection(new core_2.Vector3(0, 0, -5), core_2.Vector3.Forward()));
        uc.update(core_2.ParametricLine.FromPointDirection(new core_2.Vector3(3, 4, -4), core_2.Vector3.Forward()));
        expect(transform.worldScale).toEqual(core_2.Vector3.One());
        expect(transform.worldPosition).toEqual(core_2.Vector3.Zero());
    });
});
//# sourceMappingURL=RayPanScaleTransform.test.js.map