import { makeAppObjectRepo } from "@vived/core";
import { makeMockDispatchStateChange, makeShowSelectModelUCMock, } from "../../Dispatcher";
import { makeSceneRootEntity } from "../../SceneRoot";
import { makeChannelModelEntity, makeChannelModelRepo } from "../Entities";
import { makeSelectChannelModelUC, SelectChannelModelUC, } from "./SelectChannelModelUC";
import { makeLoadChannelModelUCMock } from "../Mocks/LoadChannelModelMock";
import { Angle, Quaternion, Vector3 } from "@vived/core";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const sceneRoot = makeSceneRootEntity(appObjects.getOrCreate("SceneRoot"));
    const repo = makeChannelModelRepo(appObjects.getOrCreate("Repo"));
    const otherModel = repo.createChannelModel("otherModel");
    otherModel.enabled = true;
    const mockDispatchShow = makeShowSelectModelUCMock(appObjects);
    mockDispatchShow.doDispatch.mockResolvedValue({
        modelId: "someModel",
    });
    const mockModel = makeChannelModelEntity(appObjects.getOrCreate("someModel"));
    const mockLoad = makeLoadChannelModelUCMock(appObjects);
    mockLoad.loadChannelModel.mockResolvedValue(mockModel);
    const uc = makeSelectChannelModelUC(appObjects.getOrCreate("AO"));
    const mockDispatchStateChange = makeMockDispatchStateChange(appObjects);
    const doDispatchMock = jest.fn();
    mockDispatchStateChange.doDispatch = doDispatchMock;
    return {
        appObjects,
        mockDispatchShow,
        mockLoad,
        uc,
        sceneRoot,
        registerSpy,
        mockModel,
        repo,
        otherModel,
        mockDispatchStateChange,
        doDispatchMock,
    };
}
describe("Select Channel Model UC", () => {
    it("Gets the singleton", () => {
        const { appObjects, uc } = makeTestRig();
        expect(SelectChannelModelUC.get(appObjects)).toEqual(uc);
    });
    it("Registers the singleton", () => {
        const { registerSpy, uc } = makeTestRig();
        expect(registerSpy).toHaveBeenCalledWith(uc);
    });
    it("Dispatches show model to the host", async () => {
        const { uc, mockDispatchShow } = makeTestRig();
        await uc.selectChannelModel();
        expect(mockDispatchShow.doDispatch).toHaveBeenCalled();
    });
    it("Loads the model", async () => {
        const { uc, mockLoad } = makeTestRig();
        await uc.selectChannelModel();
        expect(mockLoad.loadChannelModel).toHaveBeenCalledWith("someModel");
    });
    it("Sets the scene root position, rotation and scale to the channel model default", async () => {
        const { uc, sceneRoot, mockModel } = makeTestRig();
        mockModel.defaultPosition = new Vector3(1, 2, 3);
        mockModel.defaultRotation = Quaternion.FromAngleAxis(new Vector3(4, 5, 6), Angle.FromDegrees(7));
        mockModel.defaultScale = 8;
        await uc.selectChannelModel();
        expect(sceneRoot.position).toEqual(mockModel.defaultPosition);
        expect(sceneRoot.rotation).toEqual(mockModel.defaultRotation);
        expect(sceneRoot.scale).toEqual(mockModel.defaultScale);
    });
    it("Resolves with the picked model ID", async () => {
        const { uc } = makeTestRig();
        const pickedModel = await uc.selectChannelModel();
        expect(pickedModel).toEqual("someModel");
    });
    it("Set the model as active", async () => {
        const { uc, repo } = makeTestRig();
        await uc.selectChannelModel();
        expect(repo.activeModel).toEqual("someModel");
    });
    it("Set the model as enabled", async () => {
        const { uc, mockModel } = makeTestRig();
        await uc.selectChannelModel();
        expect(mockModel.enabled).toEqual(true);
    });
    it("Set the other models as disabled", async () => {
        const { uc, otherModel } = makeTestRig();
        otherModel.enabled = true;
        await uc.selectChannelModel();
        expect(otherModel.enabled).toEqual(false);
    });
    it("Dispatches a state change", async () => {
        const { uc, doDispatchMock } = makeTestRig();
        await uc.selectChannelModel();
        expect(doDispatchMock).toHaveBeenCalled();
    });
});
//# sourceMappingURL=SelectChannelModelUC.test.js.map