"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const Selectable_1 = require("./Selectable");
const Selection_1 = require("./Selection");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const appObject = appObjects.getOrCreate("appObj1");
    const selectable = (0, Selectable_1.makeSelectable)(appObject);
    const observer = jest.fn();
    selectable.addChangeObserver(observer);
    return { selectable, observer, appObject, appObjects };
}
describe("Selectable App Object Entity Component", () => {
    it("Notifies when the hovered state changes", () => {
        const { observer, selectable } = makeTestRig();
        expect(selectable.hovered).toEqual(false);
        selectable.hovered = true;
        selectable.hovered = true;
        selectable.hovered = true;
        selectable.hovered = true;
        expect(observer).toHaveBeenCalledTimes(1);
        expect(selectable.hovered).toEqual(true);
        observer.mockClear();
        selectable.hovered = false;
        expect(observer).toHaveBeenCalledTimes(1);
        expect(selectable.hovered).toEqual(false);
    });
    it("Notifies when the pressed state changes", () => {
        const { observer, selectable } = makeTestRig();
        expect(selectable.pressed).toEqual(false);
        selectable.pressed = true;
        selectable.pressed = true;
        selectable.pressed = true;
        selectable.pressed = true;
        expect(observer).toHaveBeenCalledTimes(1);
        expect(selectable.pressed).toEqual(true);
        observer.mockClear();
        selectable.pressed = false;
        expect(observer).toHaveBeenCalledTimes(1);
        expect(selectable.pressed).toEqual(false);
    });
    it("Notifies when the selected state changes", () => {
        const { observer, selectable } = makeTestRig();
        expect(selectable.selected).toEqual(false);
        selectable.selected = true;
        selectable.selected = true;
        selectable.selected = true;
        selectable.selected = true;
        expect(observer).toHaveBeenCalledTimes(1);
        expect(selectable.selected).toEqual(true);
        observer.mockClear();
        selectable.selected = false;
        expect(observer).toHaveBeenCalledTimes(1);
        expect(selectable.selected).toEqual(false);
    });
    it("Gets the entity from an AO", () => {
        const { selectable, appObject } = makeTestRig();
        expect(Selectable_1.Selectable.get(appObject)).toEqual(selectable);
    });
    it("Removes itself if it is in a Selection", () => {
        const { selectable, appObjects } = makeTestRig();
        const selection = (0, Selection_1.makeSelection)(appObjects.getOrCreate("selection"));
        selection.addSelectable(selectable);
        expect(selection.hasSelectable(selectable.appObject.id)).toEqual(true);
        selectable.dispose();
        expect(selection.hasSelectable(selectable.appObject.id)).toEqual(false);
    });
});
//# sourceMappingURL=Selectable.test.js.map