import type ymaps from "yandex-maps"; import assert from "node:assert"; import { describe, test, } from "node:test"; import { getWithBalloon } from "./index"; type TPlacemarkStub = ymaps.Placemark; const getPlacemarkStub = (): { instance: TPlacemarkStub; stats: { getIsOpen: () => boolean; openCalls: number; closeCalls: number; }; } => { let isOpen = false; let openCalls = 0; let closeCalls = 0; const instance = { balloon: { isOpen: () => isOpen, open: async () => { openCalls += 1; isOpen = true; }, close: async () => { closeCalls += 1; isOpen = false; }, getOverlay: async () => ({ getElement: () => null, }), }, } as unknown as TPlacemarkStub; return { instance, stats: { getIsOpen: () => isOpen, get openCalls() { return openCalls; }, get closeCalls() { return closeCalls; }, }, }; }; describe("getWithBalloon", () => { test("opens balloon when requested and currently closed", async () => { const { instance, stats } = getPlacemarkStub(); await getWithBalloon(instance, true); assert.strictEqual(stats.openCalls, 1); assert.strictEqual(stats.closeCalls, 0); assert.strictEqual(stats.getIsOpen(), true); }); test("closes balloon when requested and currently open", async () => { const { instance, stats } = getPlacemarkStub(); await getWithBalloon(instance, true); await getWithBalloon(instance, false); assert.strictEqual(stats.openCalls, 1); assert.strictEqual(stats.closeCalls, 1); assert.strictEqual(stats.getIsOpen(), false); }); test("does not open balloon again when it is already open", async () => { const { instance, stats } = getPlacemarkStub(); await getWithBalloon(instance, true); await getWithBalloon(instance, true); assert.strictEqual(stats.openCalls, 1); assert.strictEqual(stats.getIsOpen(), true); }); });