import { makeAppObjectRepo } from "@vived/core";
import { Angle, Quaternion, Vector3 } from "@vived/core";
import { DispatchStateChangeUC } from "../../Dispatcher";
import { makeSceneRootEntity } from "../../SceneRoot";
import { makeStoredView } from "../Entities";
import { makeStoreCurrentViewUC, StoreCurrentViewUC, } from "./StoreCurrentViewUC";
class MockDispatchStateChange extends DispatchStateChangeUC {
    constructor() {
        super(...arguments);
        this.doDispatch = jest.fn();
        this.getStateAssets = jest.fn();
        this.validateState = jest.fn();
    }
}
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const appObj = appObjects.getOrCreate("SceneRoot");
    const sceneRoot = makeSceneRootEntity(appObj);
    const storedView = makeStoredView(appObj);
    const mockDispatch = new MockDispatchStateChange(appObj, DispatchStateChangeUC.type);
    const storeCurrentViewUC = makeStoreCurrentViewUC(appObj);
    return {
        appObj,
        sceneRoot,
        storedView,
        storeCurrentViewUC,
        mockDispatch,
        appObjects,
    };
}
describe("Store Current View UC", () => {
    it("Is added to the app object as a component", () => {
        const { appObj, storeCurrentViewUC } = makeTestRig();
        expect(appObj.hasComponent(storeCurrentViewUC.type)).toBeTruthy();
        expect(appObj.getComponent(storeCurrentViewUC.type)).toEqual(storeCurrentViewUC);
    });
    it("Stores the current view", () => {
        const { storeCurrentViewUC, storedView, sceneRoot } = makeTestRig();
        expect(storedView.position).toEqual(Vector3.Zero());
        expect(storedView.rotation).toEqual(Quaternion.Identity());
        expect(storedView.scale).toEqual(1);
        expect(storedView.hasStoredView).toEqual(false);
        sceneRoot.scale = 2;
        sceneRoot.position = new Vector3(1, 2, 3);
        const rotQ = Quaternion.FromAngleAxis(new Vector3(1, 2, 3), Angle.FromDegrees(25));
        sceneRoot.rotation = rotQ;
        storeCurrentViewUC.storeCurrentView();
        expect(storedView.position).toEqual(new Vector3(1, 2, 3));
        expect(Quaternion.Close(storedView.rotation, sceneRoot.rotation)).toEqual(true);
        expect(storedView.scale).toEqual(2);
        expect(storedView.hasStoredView).toEqual(true);
    });
    it("Dispatches a state change", () => {
        const { storeCurrentViewUC, mockDispatch, sceneRoot } = makeTestRig();
        sceneRoot.scale = 2;
        sceneRoot.position = new Vector3(1, 2, 3);
        const rotQ = Quaternion.FromAngleAxis(new Vector3(1, 2, 3), Angle.FromDegrees(25));
        sceneRoot.rotation = rotQ;
        storeCurrentViewUC.storeCurrentView();
        expect(mockDispatch.doDispatch).toHaveBeenCalled();
    });
    it("Gets the UC", () => {
        const { appObjects, storeCurrentViewUC } = makeTestRig();
        expect(StoreCurrentViewUC.get(appObjects)).toEqual(storeCurrentViewUC);
    });
});
//# sourceMappingURL=StoreCurrentViewUC.test.js.map