"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const Dispatcher_1 = require("../../Dispatcher");
const SceneRoot_1 = require("../../SceneRoot");
const Entities_1 = require("../Entities");
const SelectChannelModelUC_1 = require("./SelectChannelModelUC");
const LoadChannelModelMock_1 = require("../Mocks/LoadChannelModelMock");
const core_2 = require("@vived/core");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const sceneRoot = (0, SceneRoot_1.makeSceneRootEntity)(appObjects.getOrCreate("SceneRoot"));
    const repo = (0, Entities_1.makeChannelModelRepo)(appObjects.getOrCreate("Repo"));
    const otherModel = repo.createChannelModel("otherModel");
    otherModel.enabled = true;
    const mockDispatchShow = (0, Dispatcher_1.makeShowSelectModelUCMock)(appObjects);
    mockDispatchShow.doDispatch.mockResolvedValue({
        modelId: "someModel",
    });
    const mockModel = (0, Entities_1.makeChannelModelEntity)(appObjects.getOrCreate("someModel"));
    const mockLoad = (0, LoadChannelModelMock_1.makeLoadChannelModelUCMock)(appObjects);
    mockLoad.loadChannelModel.mockResolvedValue(mockModel);
    const uc = (0, SelectChannelModelUC_1.makeSelectChannelModelUC)(appObjects.getOrCreate("AO"));
    const mockDispatchStateChange = (0, Dispatcher_1.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_1.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 core_2.Vector3(1, 2, 3);
        mockModel.defaultRotation = core_2.Quaternion.FromAngleAxis(new core_2.Vector3(4, 5, 6), core_2.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