"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const FramedScreenContainer_1 = require("./FramedScreenContainer");
const FramedScreenEntity_1 = require("./FramedScreenEntity");
function makeTestRig() {
    const appObjectRepo = (0, core_1.makeAppObjectRepo)();
    const ao = appObjectRepo.getOrCreate("App");
    const screen = (0, FramedScreenEntity_1.makeFramedScreen)(ao);
    const observer = jest.fn();
    screen.addChangeObserver(observer);
    const containerAO = appObjectRepo.getOrCreate("container1");
    const container = (0, FramedScreenContainer_1.makeFramedScreenContainer)(containerAO);
    return { screen, observer, appObjectRepo, container };
}
describe("Framed Screen Entity", () => {
    it("Starts as an empty repository", () => {
        const { screen, observer } = makeTestRig();
        expect(screen.containers.length).toEqual(0);
        expect(observer).not.toHaveBeenCalled();
    });
    it("Can add container", () => {
        const { screen, observer, container } = makeTestRig();
        observer.mockClear();
        screen.addContainer(container);
        expect(observer).toHaveBeenCalled();
        expect(screen.containers.length).toEqual(1);
        expect(screen.containers[0].id).toEqual("container1");
    });
    it("Can remove a container by id and notifies if there's a change", () => {
        const { screen, observer, container } = makeTestRig();
        screen.addContainer(container);
        observer.mockClear();
        screen.removeContainer("container1");
        expect(observer).toHaveBeenCalled();
        expect(screen.containers.length).toEqual(0);
    });
    it("Does not remove and notify if id does not exist", () => {
        const { screen, observer } = makeTestRig();
        screen.removeContainer("id1");
        expect(observer).not.toHaveBeenCalled();
    });
    it("Checks to see if a container exists", () => {
        const { screen, container } = makeTestRig();
        screen.addContainer(container);
        expect(screen.hasContainer("container1")).toEqual(true);
        expect(screen.hasContainer("something else")).toEqual(false);
    });
    it("Can return an container by id", () => {
        const { screen, container } = makeTestRig();
        screen.addContainer(container);
        const returnedContainer = screen.getContainerByID("container1");
        expect(returnedContainer?.id).toEqual("container1");
    });
    it("Returns undefined if the container cannot be found", () => {
        const { screen } = makeTestRig();
        const returnedContainer = screen.getContainerByID("someID");
        expect(returnedContainer).toBeUndefined();
    });
    it("Allows an observer to be removed", () => {
        const { screen, observer, container } = makeTestRig();
        screen.removeChangeObserver(observer);
        screen.addContainer(container);
        screen.removeContainer("container1");
        expect(observer).not.toHaveBeenCalled();
    });
    it("Notifies when the width changes", () => {
        const { screen, observer } = makeTestRig();
        expect(screen.screenWidth).toEqual(0);
        screen.screenWidth = 100;
        expect(screen.screenWidth).toEqual(100);
        expect(observer).toHaveBeenCalled();
    });
    it("Does not notify if there is no change in the width", () => {
        const { screen, observer } = makeTestRig();
        expect(screen.screenWidth).toEqual(0);
        screen.screenWidth = 0;
        screen.screenWidth = 0;
        screen.screenWidth = 0;
        expect(observer).not.toHaveBeenCalled();
    });
    it("Notifies when the height changes", () => {
        const { screen, observer } = makeTestRig();
        expect(screen.screenHeight).toEqual(0);
        screen.screenHeight = 100;
        expect(screen.screenHeight).toEqual(100);
        expect(observer).toHaveBeenCalled();
    });
    it("Does not notify if there is no change in the height", () => {
        const { screen, observer } = makeTestRig();
        expect(screen.screenHeight).toEqual(0);
        screen.screenHeight = 0;
        screen.screenHeight = 0;
        screen.screenHeight = 0;
        expect(observer).not.toHaveBeenCalled();
    });
    it("Gets the entity", () => {
        const { screen, appObjectRepo } = makeTestRig();
        expect(FramedScreenEntity_1.FramedScreenEntity.get(appObjectRepo)).toEqual(screen);
    });
});
//# sourceMappingURL=FramedScreenEntity.test.js.map