"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const Environment_1 = require("./Environment");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const registerSpy = jest.spyOn(appObjects, "registerSingleton");
    const environment = (0, Environment_1.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 = Environment_1.Environments.ROOM;
        expect(environment.currentEnvironment).toEqual("Room");
    });
    it("Notifies when current environment is changed", () => {
        const { environment, observer } = makeTestRig();
        environment.currentEnvironment = Environment_1.Environments.FOREST;
        expect(observer).toHaveBeenCalled();
    });
    it("Does not notify when current environment is not changed", () => {
        const { environment, observer } = makeTestRig();
        environment.currentEnvironment = Environment_1.Environments.STUDIO;
        observer.mockClear();
        environment.currentEnvironment = Environment_1.Environments.STUDIO;
        environment.currentEnvironment = Environment_1.Environments.STUDIO;
        environment.currentEnvironment = Environment_1.Environments.STUDIO;
        expect(observer).not.toHaveBeenCalled();
    });
    it("Sets current environment to default environment", () => {
        const { environment } = makeTestRig();
        environment.currentEnvironment = Environment_1.Environments.FOREST;
        environment.setToDefault();
        expect(environment.currentEnvironment).toEqual("Studio");
    });
    it("Notifies when set current environment to default environment", () => {
        const { environment, observer } = makeTestRig();
        environment.currentEnvironment = Environment_1.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 = Environment_1.Environments.FOREST;
        expect(observer).toHaveBeenCalled();
        observer.mockClear();
        environment.currentEnvironment = Environment_1.Environments.NIGHT;
        expect(observer).toHaveBeenCalled();
        observer.mockClear();
        environment.currentEnvironment = Environment_1.Environments.FOREST;
        expect(observer).toHaveBeenCalled();
        observer.mockClear();
        environment.currentEnvironment = Environment_1.Environments.STUDIO;
        expect(observer).toHaveBeenCalled();
    });
    it("Gets the singleton", () => {
        const { appObjects, environment } = makeTestRig();
        expect(Environment_1.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