/** @jsx jsx */
import { pipe } from '@artibox/utils/pipe';
import { createEditor } from '@artibox/slate-common';
import { expectEditorEqualOutput, jsx, withTest } from '../../../../__fixtures__/hyperscript';
import { toggleNodesType, ToggleNodesTypeOptions } from './toggleNodesType';
function testToggle(input: JSX.Element, output: JSX.Element, activeType: string, options?: ToggleNodesTypeOptions) {
const editor = pipe(createEditor(), withTest(input));
toggleNodesType(editor, activeType, options);
expectEditorEqualOutput(editor, output);
}
describe('toggleNodesType', () => {
describe('selection not in', () => {
it('collapsed', () => {
const input = (
foo
);
const output = (
foo
);
testToggle(input, output, 'foo');
});
it('expanded', () => {
const input = (
foo
f
o
o
);
const output = (
foo
f
o
o
);
testToggle(input, output, 'foo');
});
});
describe('selection in', () => {
it('collapsed', () => {
const input = (
foo
foo
fo
o
);
const output = (
foo
foo
fo
o
);
testToggle(input, output, 'foo');
});
describe('expanded', () => {
it('in single node', () => {
const input = (
foo
);
const output = (
foo
);
testToggle(input, output, 'foo');
});
it('half in node', () => {
const input = (
foo
f
oo
b
ar
);
const output = (
foo
f
oo
b
ar
);
testToggle(input, output, 'foo');
});
it('across multiple nodes', () => {
const input = (
f
oo
foo
fo
o
);
const output = (
f
oo
foo
fo
o
);
testToggle(input, output, 'foo');
});
});
});
describe('should also toggle other nodes', () => {
it('to active', () => {
const input = (
text
bar
);
const output = (
text
bar
);
testToggle(input, output, 'foo', { defaultType: 'bar' });
});
it('to inactive', () => {
const input = (
text
foo
bar
);
const output = (
text
foo
bar
);
testToggle(input, output, 'foo', { defaultType: 'bar' });
});
});
});