import { makeAppObjectRepo } from "@vived/core";
import { EnvironmentEntity, Environments, makeEnvironmentEntity, } from "./Environment";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const environment = makeEnvironmentEntity(appObjects.getOrCreate("Environment"));
    const observer = jest.fn();
    environment.addChangeObserver(observer);
    return { environment, observer, appObjects, registerSpy };
}
describe("Environment Entity", () => {
    it("Gets current environment", () => {
        const { environment } = makeTestRig();
        expect(environment.currentEnvironment).toEqual("Studio");
    });
    it("Sets current environment", () => {
        const { environment } = makeTestRig();
        environment.currentEnvironment = Environments.ROOM;
        expect(environment.currentEnvironment).toEqual("Room");
    });
    it("Notifies when current environment is changed", () => {
        const { environment, observer } = makeTestRig();
        environment.currentEnvironment = Environments.FOREST;
        expect(observer).toHaveBeenCalled();
    });
    it("Does not notify when current environment is not changed", () => {
        const { environment, observer } = makeTestRig();
        environment.currentEnvironment = Environments.STUDIO;
        observer.mockClear();
        environment.currentEnvironment = Environments.STUDIO;
        environment.currentEnvironment = Environments.STUDIO;
        environment.currentEnvironment = Environments.STUDIO;
        expect(observer).not.toHaveBeenCalled();
    });
    it("Sets current environment to default environment", () => {
        const { environment } = makeTestRig();
        environment.currentEnvironment = Environments.FOREST;
        environment.setToDefault();
        expect(environment.currentEnvironment).toEqual("Studio");
    });
    it("Notifies when set current environment to default environment", () => {
        const { environment, observer } = makeTestRig();
        environment.currentEnvironment = Environments.ROOM;
        environment.setToDefault();
        expect(observer).toHaveBeenCalled();
    });
    it("Does not notify when setting current environment to default if it is already default", () => {
        const { environment, observer } = makeTestRig();
        environment.setToDefault();
        expect(observer).not.toHaveBeenCalled();
    });
    it("Notifies when setting different environments back and forth", () => {
        const { environment, observer } = makeTestRig();
        environment.currentEnvironment = Environments.FOREST;
        expect(observer).toHaveBeenCalled();
        observer.mockClear();
        environment.currentEnvironment = Environments.NIGHT;
        expect(observer).toHaveBeenCalled();
        observer.mockClear();
        environment.currentEnvironment = Environments.FOREST;
        expect(observer).toHaveBeenCalled();
        observer.mockClear();
        environment.currentEnvironment = Environments.STUDIO;
        expect(observer).toHaveBeenCalled();
    });
    it("Gets the singleton", () => {
        const { appObjects, environment } = makeTestRig();
        expect(EnvironmentEntity.get(appObjects)).toEqual(environment);
    });
    it("Registers as the singleton", () => {
        const { registerSpy, environment } = makeTestRig();
        expect(registerSpy).toHaveBeenCalledWith(environment);
    });
    it("Notifies when the intensity change", () => {
        const { environment, observer } = makeTestRig();
        expect(environment.intensity).toEqual(0.75);
        environment.intensity = 0.666;
        environment.intensity = 0.666;
        environment.intensity = 0.666;
        environment.intensity = 0.666;
        expect(observer).toHaveBeenCalledTimes(1);
    });
});
//# sourceMappingURL=Environment.test.js.map