Skip to content

Commit

Permalink
some improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
zakishaheen committed Jun 30, 2022
1 parent 48af095 commit 4b43c4b
Showing 1 changed file with 178 additions and 20 deletions.
198 changes: 178 additions & 20 deletions packages/nodes/list/src/onkeyDownList.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,26 @@ import * as isHotkey from 'is-hotkey';
import { onKeyDownList } from './onKeyDownList';

jsx;
/*
input:
1. E1
2. |E2

it('should indent single list item', () => {
output:
1. E1
1. |E2
*/
it('should indent single list item (start of item)', () => {
const input = (
<editor>
<hul>
<hli>
<hlic>some text</hlic>
<hlic>E1</hlic>
</hli>
<hli>
<hlic>
<cursor />
some text
E2
</hlic>
</hli>
</hul>
Expand All @@ -30,12 +38,12 @@ it('should indent single list item', () => {
<editor>
<hul>
<hli>
<hlic>some text</hlic>
<hlic>E1</hlic>
<hul>
<hli>
<hlic>
<cursor />
some text
E2
</hlic>
</hli>
</hul>
Expand All @@ -54,22 +62,88 @@ it('should indent single list item', () => {
expect(editor.children).toEqual(output.children);
});

it('should indent multiple list items', () => {
/*
input:
1. E1
2. E2|

output:
1. E1
1. E2|
*/
it('should indent single list item (end of item)', () => {
const input = (
<editor>
<hul>
<hli>
<hlic>E1</hlic>
</hli>
<hli>
<hlic>
E2
<cursor />
</hlic>
</hli>
</hul>
</editor>
) as any;

const output = (
<editor>
<hul>
<hli>
<hlic>E1</hlic>
<hul>
<hli>
<hlic>
E2
<cursor />
</hlic>
</hli>
</hul>
</hli>
</hul>
</editor>
) as any;

const event = new KeyboardEvent('keydown', { key: 'Tab' }) as any;
const editor = createPlateUIEditor({
editor: input,
plugins: [createListPlugin()],
});

onKeyDownList(editor, getPlugin<HotkeyPlugin>(editor, 'ul'))(event as any);
expect(editor.children).toEqual(output.children);
});

/*
input:
1. E1
2. |E2
3. E3|

output:
1. E1
1. |E2
2. E3|
*/
it('should indent multiple list items (start/end)', () => {
const input = (
<editor>
<hul>
<hli>
<hlic>first element</hlic>
<hlic>E1</hlic>
</hli>
<hli>
<hlic>
<focus />
second element
E2
</hlic>
</hli>
<hli>
<hlic>
third element <anchor />
E3
<anchor />
</hlic>
</hli>
</hul>
Expand All @@ -80,17 +154,17 @@ it('should indent multiple list items', () => {
<editor>
<hul>
<hli>
<hlic>first element</hlic>
<hlic>E1</hlic>
<hul>
<hli>
<hlic>
<focus />
second element
E2
</hlic>
</hli>
<hli>
<hlic>
third element <anchor />
E3<anchor />
</hlic>
</hli>
</hul>
Expand All @@ -109,22 +183,34 @@ it('should indent multiple list items', () => {
expect(editor.children).toEqual(output.children);
});

it('should un-indent multiple list items', () => {
/*
input:
1. E1
1. |E2
2. E3|

output:
1. E1
2. |E2
3. E3|
*/
it('should un-indent multiple list items (start/end)', () => {
const input = (
<editor>
<hul>
<hli>
<hlic>first element</hlic>
<hlic>E1</hlic>
<hul>
<hli>
<hlic>
<focus />
second element
E2
</hlic>
</hli>
<hli>
<hlic>
third element <anchor />
E3
<anchor />
</hlic>
</hli>
</hul>
Expand All @@ -137,17 +223,18 @@ it('should un-indent multiple list items', () => {
<editor>
<hul>
<hli>
<hlic>first element</hlic>
<hlic>E1</hlic>
</hli>
<hli>
<hlic>
<focus />
second element
E2
</hlic>
</hli>
<hli>
<hlic>
third element <anchor />
E3
<anchor />
</hlic>
</hli>
</hul>
Expand All @@ -163,6 +250,77 @@ it('should un-indent multiple list items', () => {
plugins: [createListPlugin()],
});

onKeyDownList(editor, getPlugin<HotkeyPlugin>(editor, 'ul'))(event as any);
onKeyDownList(editor, getPlugin<HotkeyPlugin>(editor, 'list'))(event as any);
expect(editor.children).toEqual(output.children);
});

/*
input:
1. E1
1. |E2
2. E3
|

output:
1. E1
2. |E2
3. E3
|
*/
it('should un-indent multiple list items (start/out)', () => {
const input = (
<editor>
<hul>
<hli>
<hlic>E1</hlic>
<hul>
<hli>
<hlic>
<focus />
E2
</hlic>
</hli>
<hli>
<hlic>E3</hlic>
</hli>
<anchor />
</hul>
</hli>
</hul>
</editor>
) as any;

const output = (
<editor>
<hul>
<hli>
<hlic>E1</hlic>
</hli>
<hli>
<hlic>
<focus />
E2
</hlic>
</hli>
<hli>
<hlic>
E3
<anchor />
</hlic>
</hli>
</hul>
</editor>
) as any;

const event = new KeyboardEvent('keydown', {
shiftKey: true,
key: 'Tab',
}) as any;
const editor = createPlateUIEditor({
editor: input,
plugins: [createListPlugin()],
});

onKeyDownList(editor, getPlugin<HotkeyPlugin>(editor, 'list'))(event as any);
expect(editor.children).toEqual(output.children);
});

0 comments on commit 4b43c4b

Please sign in to comment.