From c928fbccaf680e8312eddb374e30424cbf202e4a Mon Sep 17 00:00:00 2001 From: Andrey Okonetchnikov Date: Thu, 22 Sep 2016 21:52:43 +0200 Subject: [PATCH] Switched to enzyme --- package.json | 3 +- .../__tests__/MarkitupReactRenderer.spec.js | 65 +++++++++++-- .../MarkitupReactRenderer.spec.js.snap | 91 +------------------ 3 files changed, 64 insertions(+), 95 deletions(-) diff --git a/package.json b/package.json index f74fb62d..0ededa44 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "babel-preset-react": "^6.5.0", "babel-runtime": "^6.5.0", "css-loader": "^0.23.1", + "enzyme": "^2.4.1", "eslint": "^3.5.0", "eslint-plugin-react": "^5.1.1", "expect": "^1.20.2", @@ -60,6 +61,7 @@ "postcss-loader": "^0.9.1", "pre-commit": "^1.1.3", "react": "^15.1.0", + "react-addons-test-utils": "^15.3.2", "react-dom": "^15.1.0", "react-hot-loader": "^3.0.0-beta.2", "react-immutable-proptypes": "^1.6.0", @@ -68,7 +70,6 @@ "react-redux": "^4.4.0", "react-router": "^2.5.1", "react-router-redux": "^4.0.5", - "react-test-renderer": "^15.3.2", "redux": "^3.3.1", "redux-thunk": "^1.0.3", "sass-loader": "^4.0.2", diff --git a/src/components/Widgets/__tests__/MarkitupReactRenderer.spec.js b/src/components/Widgets/__tests__/MarkitupReactRenderer.spec.js index c8b0e396..4e9858d6 100644 --- a/src/components/Widgets/__tests__/MarkitupReactRenderer.spec.js +++ b/src/components/Widgets/__tests__/MarkitupReactRenderer.spec.js @@ -1,10 +1,41 @@ import React from 'react'; -import renderer from 'react-test-renderer'; +import { shallow } from 'enzyme'; import markdownSyntax from 'markup-it/syntaxes/markdown'; import htmlSyntax from 'markup-it/syntaxes/html'; import MarkitupReactRenderer from '../MarkitupReactRenderer'; describe('MarkitupReactRenderer', () => { + it('should re-render properly after a value and syntax update', () => { + const component = shallow( + + ); + const tree1 = component.html(); + component.setProps({ + value: '

Title

', + syntax: htmlSyntax + }); + const tree2 = component.html(); + expect(tree1).toEqual(tree2); + }); + + it('should not update the parser if syntax didn\'t change', () => { + const component = shallow( + + ); + const syntax1 = component.instance().props.syntax; + component.setProps({ + value: '## Title', + }); + const syntax2 = component.instance().props.syntax; + expect(syntax1).toEqual(syntax2); + }); + it('should render markdown', () => { const value = ` # H1 @@ -31,39 +62,57 @@ Text with **bold** & _em_ elements ![alt text](https://pbs.twimg.com/profile_images/678903331176214528/TQTdqGwD.jpg) ###### H6 - `; - const component = renderer.create( + const component = shallow( ); - const tree = component.toJSON(); + const tree = component.html(); + expect(tree).toMatchSnapshot(); + }); + + it('should render HTML as is using Markdown', () => { + const value = ` +# Title + +
+
Test HTML content
+
Testing HTML in Markdown
+
+`; + const component = shallow( + + ); + const tree = component.html(); expect(tree).toMatchSnapshot(); }); it('should support custom syntax', () => { const value = ''; - const component = renderer.create( + const component = shallow( ); - const tree = component.toJSON(); + const tree = component.html(); expect(tree).toMatchSnapshot(); }); it('should render HTML', () => { const value = '

Paragraph with inline element

'; - const component = renderer.create( + const component = shallow( ); - const tree = component.toJSON(); + const tree = component.html(); expect(tree).toMatchSnapshot(); }); }); diff --git a/src/components/Widgets/__tests__/__snapshots__/MarkitupReactRenderer.spec.js.snap b/src/components/Widgets/__tests__/__snapshots__/MarkitupReactRenderer.spec.js.snap index 5b582db8..e3854e2c 100644 --- a/src/components/Widgets/__tests__/__snapshots__/MarkitupReactRenderer.spec.js.snap +++ b/src/components/Widgets/__tests__/__snapshots__/MarkitupReactRenderer.spec.js.snap @@ -1,88 +1,7 @@ -exports[`MarkitupReactRenderer should render HTML 1`] = ` -
-

- Paragraph with - - inline - - element -

-
-`; +exports[`MarkitupReactRenderer should render HTML 1`] = `"

Paragraph with inline element

"`; -exports[`MarkitupReactRenderer should render markdown 1`] = ` -
-

- H1 -

-

- Text with - - bold - - & - - em - - elements -

-

- H2 -

-
    -
  • - ul item 1 -
  • -
  • - ul item 2 -
  • -
-

- H3 -

-
    -
  1. - ol item 1 -
  2. -
  3. - ol item 2 -
  4. -
  5. - ol item 3 -
  6. -
-

- H4 -

-

- - link title - -

-
- H5 -
-

- alt text -

-
- H6 -
-
-`; +exports[`MarkitupReactRenderer should render HTML as is using Markdown 1`] = `"

Title

"`; -exports[`MarkitupReactRenderer should support custom syntax 1`] = `
`; +exports[`MarkitupReactRenderer should render markdown 1`] = `"

H1

Text with bold & em elements

H2

  • ul item 1
  • ul item 2

H3

  1. ol item 1
  2. ol item 2
  3. ol item 3

H4

link title

H5

\"alt

H6
"`; + +exports[`MarkitupReactRenderer should support custom syntax 1`] = `"
"`;