packages/doc holds the editor's model (ImportedProject) losslessly in a Yjs document (schema 1): ports with their settings, each node's settings as maps per field, programs, files as a flat path map in creation order (text as Y.Text), own Java applications, links, documentation items, archive entries. The core's snapshot and the .fls export go through the project. The janitor repairs dangling links, two links at one port and files without their folder, deterministically and idempotently. All 23 corpus files come back through a Yjs update with the same snapshot and export. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
43 lines
1.7 KiB
TypeScript
43 lines
1.7 KiB
TypeScript
// The small parts of the document: plain values in Yjs and back, and the
|
|
// order of entries two people placed at once.
|
|
|
|
import { describe, expect, it } from 'vitest';
|
|
import * as Y from 'yjs';
|
|
import { fromY, inOrder, toY } from '../src/index.js';
|
|
|
|
/** A value as the document holds it, inside a document (a Yjs type outside one cannot be read). */
|
|
function held(value: Parameters<typeof toY>[0]): unknown {
|
|
const doc = new Y.Doc();
|
|
doc.getMap('root').set('value', toY(value));
|
|
return doc.getMap('root').get('value');
|
|
}
|
|
|
|
describe('plain values in the document', () => {
|
|
it('leaves out a field that is undefined', () => {
|
|
const map = held({ a: 1, b: undefined, c: null }) as Y.Map<unknown>;
|
|
expect([...map.keys()].sort()).toEqual(['a', 'c']);
|
|
expect(fromY(map)).toStrictEqual({ a: 1, c: null });
|
|
});
|
|
|
|
it('keeps lists, nested objects, bytes and the values of JSON', () => {
|
|
const value = { rows: [{ name: 'x', ttl: 3600 }, { name: 'y', ttl: 0 }], on: true, off: false, text: 'ä', none: null, bytes: new Uint8Array([1, 2]) };
|
|
const map = held(value) as Y.Map<unknown>;
|
|
expect(map.get('rows')).toBeInstanceOf(Y.Array);
|
|
expect((map.get('rows') as Y.Array<unknown>).get(0)).toBeInstanceOf(Y.Map);
|
|
expect(fromY(map)).toStrictEqual(value);
|
|
});
|
|
});
|
|
|
|
describe('the order of entries', () => {
|
|
it('orders by place, and two entries given one place by their keys', () => {
|
|
const doc = new Y.Doc();
|
|
const map = doc.getMap<Y.Map<unknown>>('entries');
|
|
for (const [key, order] of [['c', 1], ['b', 0], ['a', 1], ['d', -1]] as const) {
|
|
const entry = new Y.Map<unknown>();
|
|
entry.set('order', order);
|
|
map.set(key, entry);
|
|
}
|
|
expect(inOrder(map).map(([key]) => key)).toEqual(['d', 'b', 'a', 'c']);
|
|
});
|
|
});
|