Skip to content

Commit

Permalink
style(lint): apply jest format lint rule
Browse files Browse the repository at this point in the history
  • Loading branch information
ifiokjr committed Mar 13, 2020
1 parent ea0ad21 commit ba61706
Show file tree
Hide file tree
Showing 61 changed files with 495 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { baseExtensions } from '../core-extensions';

test('baseExtensions', () => {
const names = baseExtensions.map(obj => (isExtension(obj) ? obj.name : obj.extension.name));

expect(names).toContainValues([
'doc',
'text',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ import { HistoryExtension } from '../history-extension';

describe('commands', () => {
const create = () => renderEditor({ others: [new HistoryExtension()] });

it('can undo', () => {
const { p, doc, add } = create();
add(doc(p('<cursor>')))
.insertText('Text goes here')
.actionsCallback(actions => {
expect(actions.undo.isActive()).toBeFalse();
expect(actions.undo.isEnabled()).toBeTrue();

actions.undo();

expect(actions.undo.isEnabled()).toBeFalse();
})
.callback(content => {
Expand All @@ -27,9 +30,13 @@ describe('commands', () => {
.actionsCallback(actions => {
expect(actions.redo.isActive()).toBeFalse();
expect(actions.redo.isEnabled()).toBeFalse();

actions.undo();

expect(actions.redo.isEnabled()).toBeTrue();

actions.redo();

expect(actions.redo.isEnabled()).toBeFalse();
})
.callback(content => {
Expand Down Expand Up @@ -62,6 +69,7 @@ describe('`getState` and `getDispatch`', () => {
})
.actionsCallback(actions => {
actions.undo();

expect(mocks.getState).toHaveBeenCalledTimes(1);
expect(dispatcher).toHaveBeenCalledTimes(1);
});
Expand All @@ -77,6 +85,7 @@ describe('`getState` and `getDispatch`', () => {
actions.undo();
jest.clearAllMocks();
actions.redo();

expect(mocks.getState).toHaveBeenCalled();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const create = (params: Partial<TrailingNodeExtensionOptions> = Object.create(nu
plainNodes: [headingNode, blockquoteNode],
others: [new TrailingNodeExtension(params)],
});

describe('plugin', () => {
let {
add,
Expand All @@ -24,16 +25,19 @@ describe('plugin', () => {

it('adds a new paragraph by default', () => {
const { state } = add(doc(h('Yo')));

expect(state.doc).toEqualRemirrorDocument(doc(h('Yo'), p()));
});

it('does not add multiple paragraphs', () => {
const { state } = add(doc(p('Yo')));

expect(state.doc).toEqualRemirrorDocument(doc(p('Yo')));
});

it('dynamically appends paragraphs', () => {
const { state } = add(doc(p('Yo'), p('<cursor>'))).insertText('# Greatness');

expect(state.doc).toEqualRemirrorDocument(doc(p('Yo'), h('Greatness'), p()));
});

Expand All @@ -44,6 +48,7 @@ describe('plugin', () => {
} = create({ nodeName: 'heading' }));

const { state } = add(doc(p('Yo'), p('<cursor>'))).insertText('> Epic quote');

expect(state.doc).toEqualRemirrorDocument(doc(p('Yo'), blockquote(p('Epic quote')), h()));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('schema', () => {
schema,
});
const expected = doc(p(a('link')));

expect(node).toEqualProsemirrorNode(expected);
});

Expand Down Expand Up @@ -78,6 +79,7 @@ describe('schema', () => {
});

const expected = doc(p(a('link')));

expect(node).toEqualProsemirrorNode(expected);
});
});
Expand Down Expand Up @@ -114,20 +116,23 @@ describe('actions', () => {
const testLink = link({ href });
add(doc(p('Paragraph ', testLink('<start>A link<end>'))));
actions.removeLink();

expect(getState()).toContainRemirrorDocument(p('Paragraph A link'));
});

it('removes the link cursor is within', () => {
const testLink = link({ href });
add(doc(p('Paragraph ', testLink('A <cursor>link'))));
actions.removeLink();

expect(getState()).toContainRemirrorDocument(p('Paragraph A link'));
});

it('removes all links when selection contains multiples', () => {
const testLink = link({ href });
add(doc(p('<all>', testLink('1'), ' ', testLink('2'), ' ', testLink('3'))));
actions.removeLink();

expect(getState()).toContainRemirrorDocument(p('1 2 3'));
});
});
Expand All @@ -136,24 +141,28 @@ describe('actions', () => {
it('is not enabled when not selected', () => {
const testLink = link({ href });
add(doc(p('Paragraph<cursor> ', testLink('A link'))));

expect(actions.removeLink.isEnabled()).toBeFalse();
});

it('is enabled with selection wrapped', () => {
const testLink = link({ href });
add(doc(p('Paragraph ', testLink('<start>A link<end>'))));

expect(actions.removeLink.isEnabled()).toBeTrue();
});

it('is enabled with cursor within link', () => {
const testLink = link({ href });
add(doc(p('Paragraph ', testLink('A <cursor>link'))));

expect(actions.removeLink.isEnabled()).toBeTrue();
});

it('is enabled with selection of multiple nodes', () => {
const testLink = link({ href });
add(doc(p('<all>Paragraph ', testLink('A link'))));

expect(actions.removeLink.isEnabled()).toBeTrue();
});
});
Expand All @@ -165,12 +174,14 @@ describe('actions', () => {
const testLink = link({ href });
add(doc(p('Paragraph <start>A link<end>')));
actions.updateLink({ href });

expect(getState()).toContainRemirrorDocument(p('Paragraph ', testLink('<start>A link<end>')));
});

it('does nothing for an empty selection', () => {
add(doc(p('Paragraph <cursor>A link')));
actions.updateLink({ href });

expect(getState()).toContainRemirrorDocument(p('Paragraph A link'));
});

Expand All @@ -180,13 +191,15 @@ describe('actions', () => {
const altLink = link(attrs);
add(doc(p('Paragraph ', testLink('<start>A link<end>'))));
actions.updateLink(attrs);

expect(getState()).toContainRemirrorDocument(p('Paragraph ', altLink('<start>A link<end>')));
});

it('overwrites multiple existing links', () => {
const testLink = link({ href });
add(doc(p('<all>', testLink('1'), ' ', testLink('2'), ' ', testLink('3'))));
actions.updateLink({ href });

expect(getState()).toContainRemirrorDocument(p(testLink('1 2 3')));
});
});
Expand All @@ -195,41 +208,48 @@ describe('actions', () => {
it('is not active when not selected', () => {
const testLink = link({ href });
add(doc(p('Paragraph<cursor> ', testLink('A link'))));

expect(actions.updateLink.isActive()).toBeFalse();
});

it('is active with selection wrapped', () => {
const testLink = link({ href });
add(doc(p('Paragraph ', testLink('<start>A link<end>'))));

expect(actions.updateLink.isActive()).toBeTrue();
});

it('is active with cursor within link', () => {
const testLink = link({ href });
add(doc(p('Paragraph ', testLink('A <cursor>link'))));

expect(actions.updateLink.isActive()).toBeTrue();
});

it('is active with selection of multiple nodes', () => {
const testLink = link({ href });
add(doc(p('<all>Paragraph ', testLink('A link'))));

expect(actions.updateLink.isActive()).toBeTrue();
});
});

describe('.isEnabled()', () => {
it('is enabled when text is selected', () => {
add(doc(p('Paragraph <start>A<end> link')));

expect(actions.updateLink.isEnabled()).toBeTrue();
});

it('is not enabled for empty selections', () => {
add(doc(p('Paragraph <cursor>A link')));

expect(actions.updateLink.isEnabled()).toBeFalse();
});

it('is not enabled for node selections', () => {
add(doc(p('Paragraph <node>A link')));

expect(actions.updateLink.isEnabled()).toBeFalse();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('schema', () => {
it('it can parse content', () => {
const node = fromHTML({ content: '<h2>Hello</h2>', schema });
const expected = doc(h2('Hello'));

expect(node).toEqualProsemirrorNode(expected);
});

Expand Down Expand Up @@ -103,6 +104,7 @@ describe('plugins', () => {
const h1 = heading({ level: 1 });
const h3 = heading({ level: 3 });
const text = 'Welcome to the jungle';

expect(add(doc(p(`<cursor>${text}`))).shortcut('Shift-Ctrl-1').state).toContainRemirrorDocument(h1(text));
expect(add(doc(p(`<cursor>${text}`))).shortcut('Shift-Ctrl-3').state).toContainRemirrorDocument(h3(text));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('schema', () => {
schema,
});
const expected = doc(p('hello'));

expect(node).toEqualProsemirrorNode(expected);
});

Expand All @@ -30,6 +31,7 @@ describe('schema', () => {
node: p('hello'),
schema,
});

expect(html).toBe(`<p style="text-align: right;line-height: 100%;" data-indent="1" id="never">hello</p>`);
});
});

1 comment on commit ba61706

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.