Skip to content

Commit 22ed98e

Browse files
author
Brent Farese
committed
Write failing test case.
1 parent 69f3e0e commit 22ed98e

3 files changed

Lines changed: 38 additions & 2 deletions

File tree

packages/core/src/utils/convert.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ export function yTextToSlateElement(yText: Y.XmlText): Element {
1010
const children =
1111
// eslint-disable-next-line @typescript-eslint/no-use-before-define
1212
delta.length > 0 ? delta.map(deltaInsertToSlateNode) : [{ text: '' }];
13+
const attributes = yText.getAttributes();
1314

14-
return { ...yText.getAttributes(), children };
15+
return { ...attributes, children };
1516
}
1617

1718
export function deltaInsertToSlateNode(insert: DeltaInsert): Node {

packages/core/test/index.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export type FixtureModule = {
1010
module: {
1111
input: Editor;
1212
expected: Editor;
13-
run: (e: Editor) => void;
13+
run: (e: Editor) => any;
1414
};
1515
};
1616

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

63+
async function runUnitTest({ module }: FixtureModule) {
64+
const { input, run, expected } = module;
65+
const editor = await withTestingElements(input);
66+
const runOutput = run(editor);
67+
expect(runOutput).toEqual(expected);
68+
}
69+
6370
describe('adapter', () => {
71+
fixtures(__dirname, 'unit', runUnitTest);
6472
fixtures(__dirname, 'collaboration', runCollaborationTest);
6573
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/** @jsx jsx */
2+
import { Editor } from 'slate';
3+
import { jsx } from '../../../../support/jsx';
4+
import { YjsEditor, yTextToSlateElement } from '../../src';
5+
6+
export const input = (
7+
<editor>
8+
<unstyled>
9+
<text bold />
10+
</unstyled>
11+
</editor>
12+
);
13+
14+
export const expected = {
15+
children: [
16+
<unstyled>
17+
<text bold />
18+
</unstyled>,
19+
],
20+
};
21+
22+
export function run(editor: Editor) {
23+
const isYJSEditor = YjsEditor.isYjsEditor(editor);
24+
if (!isYJSEditor) return;
25+
26+
return yTextToSlateElement(editor.sharedRoot);
27+
}

0 commit comments

Comments
 (0)