Skip to content

Commit

Permalink
Update tests to use Draft.js 0.10 API
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaudcolas committed Apr 26, 2017
1 parent 5e40560 commit d12c859
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
12 changes: 9 additions & 3 deletions wagtaildraftail/client/decorators/Document.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { shallow } from 'enzyme';
import { Entity } from 'draft-js';
import { convertFromHTML, ContentState } from 'draft-js';
import Document from './Document';

describe('Document', () => {
Expand All @@ -9,9 +9,15 @@ describe('Document', () => {
});

it('renders', () => {
const entityKey = Entity.create('DOCUMENT', 'MUTABLE', { title: 'Test title' });
const contentBlocks = convertFromHTML('<h1>aaaaaaaaaa</h1>');
const contentState = ContentState.createFromBlockArray(contentBlocks);
const contentStateWithEntity = contentState.createEntity('DOCUMENT', 'MUTABLE', { title: 'Test title' });
const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
expect(shallow((
<Document entityKey={entityKey}>
<Document
entityKey={entityKey}
contentState={contentStateWithEntity}
>
<span>Test children</span>
</Document>
))).toMatchSnapshot();
Expand Down
22 changes: 17 additions & 5 deletions wagtaildraftail/client/decorators/Link.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { shallow } from 'enzyme';
import { Entity } from 'draft-js';
import { convertFromHTML, ContentState } from 'draft-js';
import Link from './Link';

describe('Link', () => {
Expand All @@ -9,18 +9,30 @@ describe('Link', () => {
});

it('renders', () => {
const entityKey = Entity.create('LINK', 'MUTABLE', { url: 'http://example.com/' });
const contentBlocks = convertFromHTML('<h1>aaaaaaaaaa</h1>');
const contentState = ContentState.createFromBlockArray(contentBlocks);
const contentStateWithEntity = contentState.createEntity('LINK', 'MUTABLE', { url: 'http://example.com/' });
const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
expect(shallow((
<Link entityKey={entityKey}>
<Link
entityKey={entityKey}
contentState={contentStateWithEntity}
>
<span>Test children</span>
</Link>
))).toMatchSnapshot();
});

it('renders email', () => {
const entityKey = Entity.create('LINK', 'MUTABLE', { url: 'mailto:[email protected]' });
const contentBlocks = convertFromHTML('<h1>aaaaaaaaaa</h1>');
const contentState = ContentState.createFromBlockArray(contentBlocks);
const contentStateWithEntity = contentState.createEntity('LINK', 'MUTABLE', { url: 'mailto:[email protected]' });
const entityKey = contentStateWithEntity.getLastCreatedEntityKey();
expect(shallow((
<Link entityKey={entityKey}>
<Link
entityKey={entityKey}
contentState={contentStateWithEntity}
>
<span>Test children</span>
</Link>
))).toMatchSnapshot();
Expand Down
5 changes: 3 additions & 2 deletions wagtaildraftail/client/sources/ModalSource.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PropTypes from 'prop-types';
import React from 'react';
import { EditorState, AtomicBlockUtils, RichUtils } from 'draft-js';
import { AtomicBlockUtils, RichUtils } from 'draft-js';

const $ = global.jQuery;

Expand Down Expand Up @@ -49,8 +49,9 @@ class ModalSource extends React.Component {
}

ModalSource.propTypes = {
editorState: PropTypes.instanceOf(EditorState).isRequired,
editorState: PropTypes.object.isRequired,
options: PropTypes.object.isRequired,
// eslint-disable-next-line
entity: PropTypes.object,
onUpdate: PropTypes.func.isRequired,
onClose: PropTypes.func.isRequired,
Expand Down
1 change: 0 additions & 1 deletion wagtaildraftail/client/wagtaildraftail.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Entity } from 'draft-js';
import DraftailEditor from 'draftail';

import 'draftail/dist/draftail.css';
Expand Down

0 comments on commit d12c859

Please sign in to comment.