Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
Started work on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
silviubogan committed May 27, 2020
1 parent 9e4bcc5 commit 625af88
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
84 changes: 84 additions & 0 deletions src/TextBlock/TextBlockEdit.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/** @jsx jsx */

import { jsx } from '../__test-utils__/jsx';

import React from 'react';
import renderer from 'react-test-renderer';
import configureStore from 'redux-mock-store';
import { Provider } from 'react-intl-redux';
import { wait } from '@testing-library/react';
import ReactDOM from 'react-dom';

import { Editor } from 'slate';
import { withReact } from 'slate-react';
// import TextBlockEdit from './TextBlockEdit';
import { withHandleBreak } from './decorators';

// const mockStore = configureStore();

// ReactDOM.createPortal = (node) => node;

// window.getSelection = () => null;

describe('TextBlockEdit', () => {
// it('renders w/o errors', async () => {
// const store = mockStore({
// intl: {
// locale: 'en',
// messages: {},
// },
// });

// let root;

// renderer.act(() => {
// root = renderer.create(
// <Provider store={store}>
// <TextBlockEdit
// data={{ value: [{ type: 'paragraph', children: [{ text: '' }] }] }}
// selected={true}
// />
// </Provider>,
// );
// });
// await wait(() => {
// expect(root.toJSON()).toMatchSnapshot();
// });
// });

it('withHandleBreak decorator', async () => {
// const editor = withHandleBreak(
// 5,
// () => {},
// () => {},
// () => {},
// )(withReact(input));

const input = (
<editor>
<block>
test
<cursor />
</block>
</editor>
);

const text = 'http://localhost:3000';

const output = (
<editor>
<block>testhttp://localhost:3000</block>
</editor>
);

console.log('etc', [output]);

const editor = withReact(input);
editor.insertText(text);

// TODO: debug, get into the source, to understand where is __source added and why
output.children[0]['__source'] = editor.children[0]['__source'];

expect(output.children).toEqual(editor.children);
});
});
24 changes: 24 additions & 0 deletions src/__test-utils__/jsx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// import assert from 'assert';
// import { Editor } from 'slate';
import { createHyperscript } from 'slate-hyperscript';

// const withTest = (editor) => {
// const { isInline, isVoid } = editor;

// editor.isInline = (element) => {
// return element.inline === true ? true : isInline(element);
// };

// editor.isVoid = (element) => {
// return element.void === true ? true : isVoid(element);
// };

// return editor;
// };

export const jsx = createHyperscript({
elements: {
block: {},
inline: { inline: true },
},
});

0 comments on commit 625af88

Please sign in to comment.