import { makeAppObjectRepo } from "@vived/core";
import { Angle, Quaternion, Vector3 } from "@vived/core";
import { DispatchStateChangeUC } from "../../Dispatcher";
import { makeStoredView } from "../Entities";
import { ClearStoredViewUC, makeClearStoredViewUC } from "./ClearStoredViewUC";
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("SceneRoto");
    const storedView = makeStoredView(appObj);
    const mockDispatch = new MockDispatchStateChange(appObj, DispatchStateChangeUC.type);
    const clearStoredViewUC = makeClearStoredViewUC(appObj);
    const clearStoredView = clearStoredViewUC.clearStoredView;
    return {
        appObj,
        storedView,
        clearStoredViewUC,
        clearStoredView,
        mockDispatch,
        appObjects,
    };
}
describe("Clear Stored View UC", () => {
    it("Is added to the app object as a component", () => {
        const { appObj, clearStoredViewUC } = makeTestRig();
        expect(appObj.hasComponent(clearStoredViewUC.type)).toBeTruthy();
        expect(appObj.getComponent(clearStoredViewUC.type)).toEqual(clearStoredViewUC);
    });
    it("Clears the current view", () => {
        const { clearStoredView, storedView } = makeTestRig();
        storedView.scale = 2;
        storedView.position = new Vector3(1, 2, 3);
        const rotQ = Quaternion.FromAngleAxis(new Vector3(1, 2, 3), Angle.FromDegrees(25));
        storedView.rotation = rotQ;
        storedView.hasStoredView = true;
        clearStoredView();
        expect(storedView.position).toEqual(Vector3.Zero());
        expect(storedView.rotation).toEqual(Quaternion.Identity());
        expect(storedView.scale).toEqual(1);
        expect(storedView.hasStoredView).toEqual(false);
    });
    it("Dispatches a state change", () => {
        const { clearStoredView, storedView, mockDispatch } = makeTestRig();
        storedView.scale = 2;
        storedView.position = new Vector3(1, 2, 3);
        const rotQ = Quaternion.FromAngleAxis(new Vector3(1, 2, 3), Angle.FromDegrees(25));
        storedView.rotation = rotQ;
        storedView.hasStoredView = true;
        clearStoredView();
        expect(mockDispatch.doDispatch).toHaveBeenCalled();
    });
    it("Gets the UC", () => {
        const { appObjects, clearStoredViewUC } = makeTestRig();
        expect(ClearStoredViewUC.get(appObjects)).toEqual(clearStoredViewUC);
    });
});
//# sourceMappingURL=ClearStoredViewUC.test.js.map