-
Notifications
You must be signed in to change notification settings - Fork 806
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6424db9
commit 4b876da
Showing
2 changed files
with
177 additions
and
9 deletions.
There are no files selected for viewing
166 changes: 166 additions & 0 deletions
166
packages/basic-marks/src/lib/BaseSkipMarkPlugin.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
/** @jsx jsxt */ | ||
|
||
import type { SlateEditor } from '@udecode/plate'; | ||
|
||
import { BaseParagraphPlugin, createSlateEditor } from '@udecode/plate'; | ||
import { jsxt } from '@udecode/plate-test-utils'; | ||
|
||
import { BaseBoldPlugin } from './BaseBoldPlugin'; | ||
import { BaseCodePlugin } from './BaseCodePlugin'; | ||
import { BaseItalicPlugin } from './BaseItalicPlugin'; | ||
import { BaseSkipMarkPlugin } from './BaseSkipMarkPlugin'; | ||
|
||
jsxt; | ||
|
||
const skipMarkPlugin = BaseSkipMarkPlugin.configure({ | ||
options: { | ||
allow: [BaseCodePlugin.key], | ||
}, | ||
}); | ||
const plugins = [ | ||
BaseParagraphPlugin, | ||
BaseBoldPlugin, | ||
BaseCodePlugin, | ||
BaseItalicPlugin, | ||
skipMarkPlugin, | ||
]; | ||
|
||
describe('BaseSkipMarkPlugin', () => { | ||
describe('insertText', () => { | ||
describe('when cursor is not in a mark', () => { | ||
it('should insert text normally', () => { | ||
const input = ( | ||
<editor> | ||
<hp> | ||
test | ||
<cursor /> | ||
</hp> | ||
</editor> | ||
) as any as SlateEditor; | ||
|
||
const output = ( | ||
<editor> | ||
<hp> | ||
testinserted | ||
<cursor /> | ||
</hp> | ||
</editor> | ||
) as any as SlateEditor; | ||
|
||
const editor = createSlateEditor({ | ||
plugins, | ||
selection: input.selection, | ||
value: input.children, | ||
}); | ||
|
||
editor.tf.insertText('inserted'); | ||
|
||
expect(editor.children).toEqual(output.children); | ||
}); | ||
}); | ||
|
||
describe('when cursor is at the end of a mark', () => { | ||
it('should remove marks when inserting text', () => { | ||
const input = ( | ||
<editor> | ||
<hp> | ||
<htext code>test</htext> | ||
<cursor /> | ||
</hp> | ||
</editor> | ||
) as any as SlateEditor; | ||
|
||
const output = ( | ||
<editor> | ||
<hp> | ||
<htext code>test</htext> | ||
<htext>inserted</htext> | ||
<cursor /> | ||
</hp> | ||
</editor> | ||
) as any as SlateEditor; | ||
|
||
const editor = createSlateEditor({ | ||
plugins, | ||
selection: input.selection, | ||
value: input.children, | ||
}); | ||
|
||
editor.tf.insertText('inserted'); | ||
|
||
expect(editor.children).toEqual(output.children); | ||
}); | ||
|
||
it('should not remove marks when between same marks', () => { | ||
const input = ( | ||
<editor> | ||
<hp> | ||
<htext code>test</htext> | ||
<cursor /> | ||
<htext bold code> | ||
more | ||
</htext> | ||
</hp> | ||
</editor> | ||
) as any as SlateEditor; | ||
|
||
const output = ( | ||
<editor> | ||
<hp> | ||
<htext code>testinserted</htext> | ||
<cursor /> | ||
<htext bold code> | ||
more | ||
</htext> | ||
</hp> | ||
</editor> | ||
) as any as SlateEditor; | ||
|
||
const editor = createSlateEditor({ | ||
plugins, | ||
selection: input.selection, | ||
value: input.children, | ||
}); | ||
|
||
editor.tf.insertText('inserted'); | ||
|
||
expect(editor.children).toEqual(output.children); | ||
}); | ||
}); | ||
|
||
describe('when different mark types are adjacent', () => { | ||
it('should remove marks when inserting text', () => { | ||
const input = ( | ||
<editor> | ||
<hp> | ||
<htext code>test</htext> | ||
<cursor /> | ||
<htext italic>more</htext> | ||
</hp> | ||
</editor> | ||
) as any as SlateEditor; | ||
|
||
const output = ( | ||
<editor> | ||
<hp> | ||
<htext code>test</htext> | ||
<htext>inserted</htext> | ||
<cursor /> | ||
<htext italic>more</htext> | ||
</hp> | ||
</editor> | ||
) as any as SlateEditor; | ||
|
||
const editor = createSlateEditor({ | ||
plugins, | ||
selection: input.selection, | ||
value: input.children, | ||
}); | ||
|
||
editor.tf.insertText('inserted'); | ||
|
||
expect(editor.children).toEqual(output.children); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters