"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const core_2 = require("@vived/core");
const Dispatcher_1 = require("../../Dispatcher");
const SceneRoot_1 = require("../../SceneRoot");
const Entities_1 = require("../Entities");
const StoreCurrentViewUC_1 = require("./StoreCurrentViewUC");
class MockDispatchStateChange extends Dispatcher_1.DispatchStateChangeUC {
    constructor() {
        super(...arguments);
        this.doDispatch = jest.fn();
        this.getStateAssets = jest.fn();
        this.validateState = jest.fn();
    }
}
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const appObj = appObjects.getOrCreate("SceneRoot");
    const sceneRoot = (0, SceneRoot_1.makeSceneRootEntity)(appObj);
    const storedView = (0, Entities_1.makeStoredView)(appObj);
    const mockDispatch = new MockDispatchStateChange(appObj, Dispatcher_1.DispatchStateChangeUC.type);
    const storeCurrentViewUC = (0, StoreCurrentViewUC_1.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(core_2.Vector3.Zero());
        expect(storedView.rotation).toEqual(core_2.Quaternion.Identity());
        expect(storedView.scale).toEqual(1);
        expect(storedView.hasStoredView).toEqual(false);
        sceneRoot.scale = 2;
        sceneRoot.position = new core_2.Vector3(1, 2, 3);
        const rotQ = core_2.Quaternion.FromAngleAxis(new core_2.Vector3(1, 2, 3), core_2.Angle.FromDegrees(25));
        sceneRoot.rotation = rotQ;
        storeCurrentViewUC.storeCurrentView();
        expect(storedView.position).toEqual(new core_2.Vector3(1, 2, 3));
        expect(core_2.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 core_2.Vector3(1, 2, 3);
        const rotQ = core_2.Quaternion.FromAngleAxis(new core_2.Vector3(1, 2, 3), core_2.Angle.FromDegrees(25));
        sceneRoot.rotation = rotQ;
        storeCurrentViewUC.storeCurrentView();
        expect(mockDispatch.doDispatch).toHaveBeenCalled();
    });
    it("Gets the UC", () => {
        const { appObjects, storeCurrentViewUC } = makeTestRig();
        expect(StoreCurrentViewUC_1.StoreCurrentViewUC.get(appObjects)).toEqual(storeCurrentViewUC);
    });
});
//# sourceMappingURL=StoreCurrentViewUC.test.js.map