/** @jsx jsx */
import { Editor } from 'slate';
import { pipe } from '@artibox/utils/pipe';
import { createEditor } from '@artibox/slate-common';
import { expectEditorEqualOutput, jsx, withTest } from '../../../../__fixtures__/hyperscript';
import { BLOCKQUOTE_TYPE, createBlockquote } from '.';
const Blockquote = createBlockquote();
function testSelectionInAndToggle(expectedSelectionIn: boolean, input: JSX.Element, output: JSX.Element) {
const editor = pipe(createEditor(), Blockquote.with, withTest(input));
it(`isSelectionIn should be ${expectedSelectionIn ? 'active' : 'inactive'}`, () => {
expect(Blockquote.isSelectionInBlockquote(editor)).toBe(expectedSelectionIn);
});
it('after toggle', () => {
Blockquote.toggleBlockquote(editor);
expectEditorEqualOutput(editor, output);
expect(Blockquote.isSelectionInBlockquote(editor)).toBe(!expectedSelectionIn);
});
}
describe('controller', () => {
it('should has type', () => {
expect(Blockquote.type).toBe(BLOCKQUOTE_TYPE);
});
describe('selection not in blockquote', () => {
describe('collapsed', () => {
const input = (
foo
);
const output = (
foo
);
testSelectionInAndToggle(false, input, output);
});
describe('expanded', () => {
const input = (
foo
f
o
o
);
const output = (
foo
f
o
o
);
testSelectionInAndToggle(false, input, output);
});
});
describe('selection in blockquote', () => {
describe('collapsed', () => {
const input = (
foo
foo
fo
o
);
const output = (
foo
foo
fo
o
);
testSelectionInAndToggle(true, input, output);
});
});
describe('expanded', () => {
describe('in single blockquote', () => {
const input = (
foo
);
const output = (
foo
);
testSelectionInAndToggle(true, input, output);
});
describe('half in blockquote', () => {
const input = (
foo
f
oo
b
ar
);
const output = (
foo
f
oo
b
ar
);
testSelectionInAndToggle(true, input, output);
});
describe('across multiple blockquotes', () => {
const input = (
f
oo
foo
fo
o
);
const output = (
f
oo
foo
fo
o
);
testSelectionInAndToggle(true, input, output);
});
});
});
describe('with', () => {
it('shoulde be block element', () => {
const input = (
) as any;
const editor = pipe(createEditor(), Blockquote.with);
expect(Editor.isBlock(editor, input)).toBe(true);
});
it('should only accept inlines and texts', () => {
const input = (
abc
def
ghi
jkl
) as any;
const output = (
abcdef
ghi
jkl
);
const editor = pipe(createEditor(), Blockquote.with, withTest());
editor.insertNode(input);
expect(editor.children[0]).toEqual(output);
});
});