"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const BaseAppState_1 = require("../Entity/BaseAppState");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const appState = appObjects.getOrCreate("appState");
    const baseAppStateEntity = (0, BaseAppState_1.makeBaseAppState)(appState);
    const observer = jest.fn();
    appState.addObserver(observer);
    return { baseAppStateEntity, observer, appObjects };
}
describe("App State Entity", () => {
    it("Notifies when is authoring changes", () => {
        const { baseAppStateEntity, observer } = makeTestRig();
        expect(baseAppStateEntity.isAuthoring).toEqual(false);
        baseAppStateEntity.isAuthoring = true;
        baseAppStateEntity.isAuthoring = true;
        baseAppStateEntity.isAuthoring = true;
        baseAppStateEntity.isAuthoring = true;
        expect(observer).toHaveBeenCalledTimes(1);
        expect(baseAppStateEntity.isAuthoring).toEqual(true);
    });
    it("Notifies when is reviewing changes", () => {
        const { baseAppStateEntity, observer } = makeTestRig();
        expect(baseAppStateEntity.isReviewing).toEqual(false);
        baseAppStateEntity.isReviewing = true;
        baseAppStateEntity.isReviewing = true;
        baseAppStateEntity.isReviewing = true;
        baseAppStateEntity.isReviewing = true;
        expect(observer).toHaveBeenCalledTimes(1);
        expect(baseAppStateEntity.isReviewing).toEqual(true);
    });
    it("Gets the entity", () => {
        const { baseAppStateEntity, appObjects } = makeTestRig();
        expect(BaseAppState_1.BaseAppState.get(appObjects)).toEqual(baseAppStateEntity);
    });
    it("Notifies when the slide text is set", () => {
        const { baseAppStateEntity, observer } = makeTestRig();
        baseAppStateEntity.slideText = "Hello World!";
        expect(baseAppStateEntity.slideText).toEqual("Hello World!");
        expect(observer).toHaveBeenCalled();
    });
    it("Does not notify when the slide text is set but it is not changed", () => {
        const { baseAppStateEntity, observer } = makeTestRig();
        baseAppStateEntity.slideText = "Hello World!";
        observer.mockClear();
        baseAppStateEntity.slideText = "Hello World!";
        baseAppStateEntity.slideText = "Hello World!";
        baseAppStateEntity.slideText = "Hello World!";
        expect(observer).not.toHaveBeenCalled();
    });
    it("Notifies when the hasNextState is set", () => {
        const { baseAppStateEntity, observer } = makeTestRig();
        expect(baseAppStateEntity.hasNextState).toEqual(false);
        baseAppStateEntity.hasNextState = true;
        expect(baseAppStateEntity.hasNextState).toEqual(true);
        expect(observer).toHaveBeenCalled();
    });
    it("Does not notify when the hasNextState is set but it is not changed", () => {
        const { baseAppStateEntity, observer } = makeTestRig();
        baseAppStateEntity.hasNextState = true;
        baseAppStateEntity.hasNextState = true;
        baseAppStateEntity.hasNextState = true;
        expect(observer).toHaveBeenCalledTimes(1);
    });
    it("Notifies when the hasPreviousState is set", () => {
        const { baseAppStateEntity, observer } = makeTestRig();
        expect(baseAppStateEntity.hasPreviousState).toEqual(false);
        baseAppStateEntity.hasPreviousState = true;
        expect(baseAppStateEntity.hasPreviousState).toEqual(true);
        expect(observer).toHaveBeenCalled();
    });
    it("Does not notify when the hasPreviousState is set but it is not changed", () => {
        const { baseAppStateEntity, observer } = makeTestRig();
        baseAppStateEntity.hasPreviousState = true;
        baseAppStateEntity.hasPreviousState = true;
        baseAppStateEntity.hasPreviousState = true;
        expect(observer).toHaveBeenCalledTimes(1);
    });
    it("Notifies when the hideSlideNavigation is set", () => {
        const { baseAppStateEntity, observer } = makeTestRig();
        expect(baseAppStateEntity.hideSlideNavigation).toEqual(false);
        baseAppStateEntity.hideSlideNavigation = true;
        expect(baseAppStateEntity.hideSlideNavigation).toEqual(true);
        expect(observer).toHaveBeenCalled();
    });
    it("Does not notify when the hideSlideNavigation is set but it is not changed", () => {
        const { baseAppStateEntity, observer } = makeTestRig();
        baseAppStateEntity.hideSlideNavigation = true;
        baseAppStateEntity.hideSlideNavigation = true;
        baseAppStateEntity.hideSlideNavigation = true;
        expect(observer).toHaveBeenCalledTimes(1);
    });
    it("Notifies when the content size changes", () => {
        const { baseAppStateEntity, observer } = makeTestRig();
        baseAppStateEntity.slideInfoContentHeight = 10;
        expect(observer).toHaveBeenCalled();
        expect(baseAppStateEntity.slideInfoContentHeight).toEqual(10);
    });
    it("Doe not notify if the app state is set with no change", () => {
        const { baseAppStateEntity, observer } = makeTestRig();
        baseAppStateEntity.slideInfoContentHeight = 10;
        observer.mockClear();
        baseAppStateEntity.slideInfoContentHeight = 10;
        baseAppStateEntity.slideInfoContentHeight = 10;
        baseAppStateEntity.slideInfoContentHeight = 10;
        expect(observer).not.toHaveBeenCalled();
    });
});
//# sourceMappingURL=BaseAppState.test.js.map