import "@cmmn/core";
import { expect, suite, test } from "@cmmn/tools/test";
import { SyncStore } from "../store/sync.store.js";
import { BroadcastSync } from "../store/broadcast-sync.js";
import { Fn } from "@cmmn/core";
let StoreSpec = class StoreSpec {
    constructor() {
        this.mainStore = new SyncStore('main');
        this.testStore = new SyncStore('test');
        const bcMain = new BroadcastSync('bc');
        const bcTest = new BroadcastSync('bc');
        this.mainStore.addSync(bcMain);
        this.testStore.addSync(bcTest);
        // this.mainStore.adapter.connect(new ChannelMock());
        // this.testStore.adapter.connect(new ChannelMock());
    }
    async setAdd() {
        const mainSet = this.mainStore.getSet("value");
        const testSet = this.testStore.getSet("value");
        // need to activate sets, because they are lazy by default
        mainSet.on('change', () => { });
        testSet.on('change', () => { });
        mainSet.add(1);
        await Fn.asyncDelay(10);
        expect(Array.from(testSet)).toEqual([1]);
        testSet.add(3);
        mainSet.add(2);
        await Fn.asyncDelay(10);
        expect(Array.from(testSet).sort()).toEqual([1, 2, 3]);
        expect(Array.from(mainSet).sort()).toEqual([1, 2, 3]);
    }
    async objectSet() {
        const main = this.mainStore.getObjectCell("value");
        const test = this.testStore.getObjectCell("value");
        // need to activate sets, because they are lazy by default
        main.on('change', () => { });
        test.on('change', () => { });
        main.Diff({ a: 1 });
        await Fn.asyncDelay(10);
        expect(test.Value).toEqual({ a: 1 });
        test.Diff({ b: 3, a: 2 });
        main.Diff({ a: 4 });
        await Fn.asyncDelay(10);
        expect(main.Value).toEqual(test.Value);
        expect(main.Value.b).toEqual(3);
    }
};
__decorate([
    test,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], StoreSpec.prototype, "setAdd", null);
__decorate([
    test,
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], StoreSpec.prototype, "objectSet", null);
StoreSpec = __decorate([
    suite,
    __metadata("design:paramtypes", [])
], StoreSpec);
export { StoreSpec };
class Entity {
}
