Skip to content

Commit

Permalink
Write failing test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brent Farese committed Jul 21, 2023
1 parent 69f3e0e commit 22ed98e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/core/src/utils/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ export function yTextToSlateElement(yText: Y.XmlText): Element {
const children =
// eslint-disable-next-line @typescript-eslint/no-use-before-define
delta.length > 0 ? delta.map(deltaInsertToSlateNode) : [{ text: '' }];
const attributes = yText.getAttributes();

return { ...yText.getAttributes(), children };
return { ...attributes, children };
}

export function deltaInsertToSlateNode(insert: DeltaInsert): Node {
Expand Down
10 changes: 9 additions & 1 deletion packages/core/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type FixtureModule = {
module: {
input: Editor;
expected: Editor;
run: (e: Editor) => void;
run: (e: Editor) => any;

Check warning on line 13 in packages/core/test/index.test.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
};
};

Expand Down Expand Up @@ -60,6 +60,14 @@ async function runCollaborationTest({ module }: FixtureModule) {
expect(editor.children).toEqual(expectedEditor.children);
}

async function runUnitTest({ module }: FixtureModule) {
const { input, run, expected } = module;
const editor = await withTestingElements(input);
const runOutput = run(editor);
expect(runOutput).toEqual(expected);
}

describe('adapter', () => {
fixtures(__dirname, 'unit', runUnitTest);
fixtures(__dirname, 'collaboration', runCollaborationTest);
});
27 changes: 27 additions & 0 deletions packages/core/test/unit/yTextToSlate.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/** @jsx jsx */
import { Editor } from 'slate';
import { jsx } from '../../../../support/jsx';
import { YjsEditor, yTextToSlateElement } from '../../src';

export const input = (
<editor>
<unstyled>
<text bold />
</unstyled>
</editor>
);

export const expected = {
children: [
<unstyled>
<text bold />
</unstyled>,
],
};

export function run(editor: Editor) {
const isYJSEditor = YjsEditor.isYjsEditor(editor);
if (!isYJSEditor) return;

return yTextToSlateElement(editor.sharedRoot);
}

0 comments on commit 22ed98e

Please sign in to comment.