Skip to content

Commit

Permalink
test: use core manager creators
Browse files Browse the repository at this point in the history
  • Loading branch information
ifiokjr committed Jul 13, 2020
1 parent e88fca5 commit 27b033c
Show file tree
Hide file tree
Showing 23 changed files with 102 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import { omit, pick } from '@remirror/core-helpers';
import { Schema } from '@remirror/pm/model';
import { NodeSelection, Selection, TextSelection } from '@remirror/pm/state';
import { BoldExtension, createBaseManager } from '@remirror/testing';
import { BoldExtension, createCoreManager } from '@remirror/testing';

import {
cloneTransaction,
Expand Down Expand Up @@ -525,7 +525,7 @@ describe('findNodeAt...', () => {
});

test('schemaToJSON', () => {
const { nodes, marks } = createBaseManager({ extensions: [new BoldExtension()] });
const { nodes, marks } = createCoreManager([new BoldExtension()]);

const testSchema = new Schema({
nodes: pick(nodes, ['doc', 'paragraph', 'text']),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { pmBuild } from 'jest-prosemirror';
import { ExtensionPriority, NodeGroup } from '@remirror/core-constants';
import { ApplySchemaAttributes, NodeExtensionSpec } from '@remirror/core-types';
import { fromHtml } from '@remirror/core-utils';
import { createBaseManager } from '@remirror/testing';
import { createCoreManager } from '@remirror/testing';

import { NodeExtension } from '..';

Expand Down Expand Up @@ -45,7 +45,7 @@ describe('extraAttributes', () => {
},
});

const { schema } = createBaseManager({ extensions: [customExtension], presets: [] });
const { schema } = createCoreManager([customExtension]);
const { doc, custom, other } = pmBuild(schema, {
custom: { nodeType: 'custom', run, title, crazy: 'yo' },
other: { nodeType: 'custom', run, title, crazy: 'believe me' },
Expand Down Expand Up @@ -81,12 +81,9 @@ describe('extraAttributes', () => {
});

it('can `disableExtraAttributes`', () => {
const { schema } = createBaseManager({
extensions: [customExtension],
presets: [],
settings: { disableExtraAttributes: true },
const { schema } = createCoreManager([customExtension], {
managerSettings: { disableExtraAttributes: true },
});

expect(schema.nodes.custom.spec.attrs).toEqual({});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
ProsemirrorAttributes,
} from '@remirror/core-types';
import { EditorView } from '@remirror/pm/view';
import { CorePreset, createBaseManager } from '@remirror/testing';
import { CorePreset, createCoreManager } from '@remirror/testing';

import { CreateLifecycleMethod, PlainExtension } from '../../extension';
import { isRemirrorManager, RemirrorManager } from '../remirror-manager';
Expand Down Expand Up @@ -114,7 +114,7 @@ describe('Manager', () => {
});

it('should provide the schema at instantiation', () => {
expect(createBaseManager().schema).toBeTruthy();
expect(createCoreManager([]).schema).toBeTruthy();
});

it('should provide access to `attributes`', () => {
Expand Down Expand Up @@ -238,6 +238,5 @@ test('lifecycle', () => {
}

const extension = new LifecycleExtension();

createBaseManager({ extensions: [extension], presets: [] });
createCoreManager([extension]);
});
8 changes: 4 additions & 4 deletions packages/@remirror/dev/src/__tests__/dev.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';

import { RemirrorProvider } from '@remirror/react';
import { createBaseManager } from '@remirror/testing';
import { createCoreManager } from '@remirror/testing';
import { render } from '@remirror/testing/react';

import { ProsemirrorDevTools } from '../dev';
Expand All @@ -12,7 +12,7 @@ beforeEach(() => {

test('it supports <ProsemirrorDevTools />', () => {
const { baseElement } = render(
<RemirrorProvider manager={createBaseManager()}>
<RemirrorProvider manager={createCoreManager([])}>
<ProsemirrorDevTools />
</RemirrorProvider>,
);
Expand All @@ -25,13 +25,13 @@ test('it unmounts <ProsemirrorDevTools />', () => {
const Component = ({ dev }: { dev: boolean }) => (dev ? <ProsemirrorDevTools /> : <div />);

const { baseElement, rerender } = render(
<RemirrorProvider manager={createBaseManager()}>
<RemirrorProvider manager={createCoreManager([])}>
<Component dev={true} />
</RemirrorProvider>,
);

rerender(
<RemirrorProvider manager={createBaseManager()}>
<RemirrorProvider manager={createCoreManager([])}>
<Component dev={false} />
</RemirrorProvider>,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { pmBuild } from 'jest-prosemirror';
import { renderEditor } from 'jest-remirror';

import { fromHtml, toHtml } from '@remirror/core';
import { createBaseManager, isExtensionValid } from '@remirror/testing';
import { createCoreManager, isExtensionValid } from '@remirror/testing';

import { BlockquoteExtension } from '..';

Expand All @@ -11,10 +11,7 @@ test('is blockquote extension valid', () => {
});

describe('schema', () => {
const { schema } = createBaseManager({
extensions: [new BlockquoteExtension()],
presets: [],
});
const { schema } = createCoreManager([new BlockquoteExtension()]);

const { blockquote, doc, p } = pmBuild(schema, {});

Expand All @@ -37,11 +34,9 @@ describe('schema', () => {
});

test('supports extra attributes', () => {
const { schema } = createBaseManager({
extensions: [new BlockquoteExtension({ extraAttributes: { 'data-custom': 'hello-world' } })],
presets: [],
});

const { schema } = createCoreManager([
new BlockquoteExtension({ extraAttributes: { 'data-custom': 'hello-world' } }),
]);
const { blockquote, p } = pmBuild(schema, {});

expect(toHtml({ node: blockquote(p('friend!')), schema })).toMatchInlineSnapshot(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { pmBuild } from 'jest-prosemirror';
import { renderEditor } from 'jest-remirror';

import { fromHtml, toHtml } from '@remirror/core';
import { createBaseManager, isExtensionValid } from '@remirror/testing';
import { createCoreManager, isExtensionValid } from '@remirror/testing';

import { BoldExtension, BoldOptions } from '../..';

Expand All @@ -11,11 +11,7 @@ test('is bold extension valid', () => {
});

describe('schema', () => {
const { schema } = createBaseManager({
extensions: [new BoldExtension()],
presets: [],
});

const { schema } = createCoreManager([new BoldExtension()]);
const { bold, p, doc } = pmBuild(schema, {
bold: { markType: 'bold' },
});
Expand Down Expand Up @@ -54,11 +50,9 @@ describe('schema', () => {
});

test('supports extra attributes', () => {
const { schema } = createBaseManager({
extensions: [new BoldExtension({ extraAttributes: { 'data-custom': 'hello-world' } })],
presets: [],
});

const { schema } = createCoreManager([
new BoldExtension({ extraAttributes: { 'data-custom': 'hello-world' } }),
]);
const { bold, p } = pmBuild(schema, {
bold: { markType: 'bold' },
});
Expand All @@ -74,8 +68,7 @@ test('supports extra attributes', () => {
});

function create(options?: BoldOptions) {
const boldExtension = new BoldExtension(options);
return renderEditor([boldExtension]);
return renderEditor([new BoldExtension(options)]);
}

test('inputRules', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import typescript from 'refractor/lang/typescript';
import yaml from 'refractor/lang/yaml';

import { ExtensionPriority, fromHtml, object, toHtml } from '@remirror/core';
import { createBaseManager, isExtensionValid } from '@remirror/testing';
import { createCoreManager, isExtensionValid } from '@remirror/testing';

import { CodeBlockExtension, CodeBlockOptions, FormatterParameter } from '..';
import { getLanguage } from '../code-block-utils';
Expand All @@ -21,12 +21,11 @@ test('is code block extension valid', () => {
});

describe('schema', () => {
const { schema } = createBaseManager({
extensions: [new CodeBlockExtension({ priority: ExtensionPriority.High })],
});
const { schema } = createCoreManager([
new CodeBlockExtension({ priority: ExtensionPriority.High }),
]);
const attributes = { language: 'typescript' };
const content = 'unchanged without decorations';

const { codeBlock, doc } = pmBuild(schema, {
codeBlock: { nodeType: 'codeBlock', ...attributes },
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { pmBuild } from 'jest-prosemirror';

import { fromHtml, toHtml } from '@remirror/core';
import { createBaseManager, isExtensionValid } from '@remirror/testing';
import { createCoreManager, isExtensionValid } from '@remirror/testing';

import { CodeExtension } from '..';

Expand All @@ -11,7 +11,7 @@ test('is valid', () => {

describe('schema', () => {
const codeTester = () => {
const { schema } = createBaseManager({ extensions: [new CodeExtension()] });
const { schema } = createCoreManager([new CodeExtension()]);
const { code, doc, p } = pmBuild(schema, {
code: { markType: 'code' },
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { pmBuild } from 'jest-prosemirror';
import { renderEditor } from 'jest-remirror';

import { fromHtml, toHtml } from '@remirror/core';
import { BoldExtension, createBaseManager, isExtensionValid } from '@remirror/testing';
import { BoldExtension, createCoreManager, isExtensionValid } from '@remirror/testing';

import { HeadingExtension, HeadingOptions } from '../heading-extension';

Expand All @@ -11,7 +11,7 @@ test('is valid', () => {
});

describe('schema', () => {
const { schema } = createBaseManager({ extensions: [new HeadingExtension()] });
const { schema } = createCoreManager([new HeadingExtension()]);
const { h1, h2, h3, doc } = pmBuild(schema, {
h1: { nodeType: 'heading' },
h2: { nodeType: 'heading', level: 2 },
Expand All @@ -35,16 +35,14 @@ describe('schema', () => {
});

describe('extraAttributes', () => {
const { schema } = createBaseManager({
extensions: [
new HeadingExtension({
extraAttributes: {
title: { default: null },
custom: { default: 'failure', parseDOM: 'data-custom' },
},
}),
],
});
const { schema } = createCoreManager([
new HeadingExtension({
extraAttributes: {
title: { default: null },
custom: { default: 'failure', parseDOM: 'data-custom' },
},
}),
]);

it('sets the extra attributes', () => {
expect(schema.nodes.heading.spec.attrs).toEqual({
Expand All @@ -55,11 +53,9 @@ describe('schema', () => {
});

it('does not override the built in attributes', () => {
const { schema } = createBaseManager({
extensions: [
new HeadingExtension({ extraAttributes: { level: { default: 'should not appear' } } }),
],
});
const { schema } = createCoreManager([
new HeadingExtension({ extraAttributes: { level: { default: 'should not appear' } } }),
]);

expect(schema.nodes.heading.spec.attrs).toEqual({
level: { default: 1 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { pmBuild } from 'jest-prosemirror';
import { renderEditor } from 'jest-remirror';

import { fromHtml, GetHandler, toHtml } from '@remirror/core';
import { createBaseManager, isExtensionValid } from '@remirror/testing';
import { createCoreManager, isExtensionValid } from '@remirror/testing';

import { LinkExtension, LinkOptions } from '..';

Expand All @@ -13,13 +13,13 @@ test('is valid', () => {
const href = 'https://test.com';

describe('schema', () => {
let { schema } = createBaseManager({ extensions: [new LinkExtension()] });
let { schema } = createCoreManager([new LinkExtension()]);
let { a, doc, p } = pmBuild(schema, {
a: { markType: 'link', href },
});

beforeEach(() => {
({ schema } = createBaseManager({ extensions: [new LinkExtension()] }));
({ schema } = createCoreManager([new LinkExtension()] );
({ a, doc, p } = pmBuild(schema, {
a: { markType: 'link', href },
}));
Expand All @@ -45,16 +45,15 @@ describe('schema', () => {
const custom = 'true';
const title = 'awesome';

const { schema } = createBaseManager({
extensions: [
const { schema } = createCoreManager([
new LinkExtension({
extraAttributes: {
title: { default: null },
custom: { default: 'failure', parseDOM: 'data-custom' },
},
}),
],
});
);

it('sets the extra attributes', () => {
expect(schema.marks.link.spec.attrs).toEqual({
Expand All @@ -65,16 +64,15 @@ describe('schema', () => {
});

it('does not override the href', () => {
const { schema } = createBaseManager({
extensions: [
const { schema } = createCoreManager([
new LinkExtension({
extraAttributes: {
title: { default: null },
custom: { default: 'failure', parseDOM: 'data-custom' },
},
}),
],
});
);

expect(schema.marks.link.spec.attrs).toEqual({
custom: { default: 'failure' },
Expand Down
24 changes: 10 additions & 14 deletions packages/@remirror/extension-mention/src/__tests__/mention.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ import { renderEditor } from 'jest-remirror';

import { entries, fromHtml, GetHandler, toHtml } from '@remirror/core';
import { SuggestExitHandlerParameter } from '@remirror/pm/suggest';
import { createBaseManager } from '@remirror/testing';
import { createCoreManager } from '@remirror/testing';

import { MentionExtension, MentionExtensionSuggestCommand, MentionOptions } from '..';

describe('schema', () => {
const { schema } = createBaseManager({
extensions: [new MentionExtension({ matchers: [{ char: '@', name: 'at' }] })],
presets: [],
});
const { schema } = createCoreManager([
new MentionExtension({ matchers: [{ char: '@', name: 'at' }] }),
]);
const attributes = { id: 'test', label: '@test', name: 'testing' };

const { mention, p, doc } = pmBuild(schema, {
Expand Down Expand Up @@ -43,15 +42,12 @@ describe('schema', () => {

describe('extraAttributes', () => {
const custom = 'test';
const { schema } = createBaseManager({
extensions: [
new MentionExtension({
matchers: [],
extraAttributes: { 'data-custom': { default: null } },
}),
],
presets: [],
});
const { schema } = createCoreManager([
new MentionExtension({
matchers: [],
extraAttributes: { 'data-custom': { default: null } },
}),
]);

const { doc, p, mention } = pmBuild(schema, {
mention: { markType: 'mention', ['data-custom']: custom, ...attributes },
Expand Down

0 comments on commit 27b033c

Please sign in to comment.