diff --git a/client/post-editor/editor-discussion/Makefile b/client/post-editor/editor-discussion/Makefile deleted file mode 100644 index 5fb42bb5b03d5..0000000000000 --- a/client/post-editor/editor-discussion/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -REPORTER ?= spec -MOCHA ?= ../../../node_modules/.bin/mocha - -test: - @NODE_ENV=test NODE_PATH=test:../../ $(MOCHA) --compilers jsx:babel/register --reporter $(REPORTER) - -.PHONY: test diff --git a/client/post-editor/editor-discussion/test/index.jsx b/client/post-editor/editor-discussion/test/index.jsx index 7df44ec4a8b82..5a5402e1509cb 100644 --- a/client/post-editor/editor-discussion/test/index.jsx +++ b/client/post-editor/editor-discussion/test/index.jsx @@ -1,30 +1,25 @@ -/* eslint-disable vars-on-top */ -require( 'lib/react-test-env-setup' )(); - /** * External dependencies */ -var ReactDom = require( 'react-dom' ), - React = require( 'react' ), - TestUtils = require( 'react-addons-test-utils' ), - sinon = require( 'sinon' ), - sinonChai = require( 'sinon-chai' ), - mockery = require( 'mockery' ), - chai = require( 'chai' ), - noop = require( 'lodash/noop' ), - expect = chai.expect; - -chai.use( sinonChai ); -const MOCK_COMPONENT = React.createClass( { - render: function() { - return null; - } -} ); +import ReactDom from 'react-dom'; +import React from 'react'; +import TestUtils from 'react-addons-test-utils'; +import sinon from 'sinon'; +import mockery from 'mockery'; +import { expect } from 'chai'; +import noop from 'lodash/noop'; + +/** + * Internal dependencies + */ +import EmptyComponent from 'test/helpers/react/empty-component'; +import useMockery from 'test/helpers/use-mockery'; +import useFakeDom from 'test/helpers/use-fake-dom'; /** * Module variables */ -var DUMMY_SITE = { +const DUMMY_SITE = { options: { default_comment_status: true, default_ping_status: false @@ -34,13 +29,12 @@ var DUMMY_SITE = { describe( 'EditorDiscussion', function() { var editPost, EditorDiscussion; + useMockery(); + useFakeDom(); + before( function() { - mockery.enable( { - warnOnReplace: false, - warnOnUnregistered: false - } ); editPost = sinon.spy(); - mockery.registerMock( 'components/info-popover', MOCK_COMPONENT ); + mockery.registerMock( 'components/info-popover', EmptyComponent ); mockery.registerMock( 'lib/posts/actions', { edit: editPost } ); diff --git a/client/post-editor/editor-ground-control/Makefile b/client/post-editor/editor-ground-control/Makefile deleted file mode 100644 index 65399b3f96522..0000000000000 --- a/client/post-editor/editor-ground-control/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -REPORTER ?= spec -NODE_BIN := $(shell npm bin) -MOCHA ?= $(NODE_BIN)/mocha -BASE_DIR := $(NODE_BIN)/../.. -NODE_PATH := test:$(BASE_DIR)/client - -test: - @NODE_ENV=test NODE_PATH=$(NODE_PATH) $(MOCHA) --compilers jsx:babel/register --reporter $(REPORTER) - -.PHONY: test diff --git a/client/post-editor/editor-ground-control/test/index.jsx b/client/post-editor/editor-ground-control/test/index.jsx index b2d9202f08359..034a58cb439c9 100644 --- a/client/post-editor/editor-ground-control/test/index.jsx +++ b/client/post-editor/editor-ground-control/test/index.jsx @@ -1,98 +1,79 @@ -/* eslint-disable vars-on-top */ -require( 'lib/react-test-env-setup' )(); - /** * External dependencies */ -var chai = require( 'chai' ), - moment = require( 'moment' ), - ReactDom = require( 'react-dom' ), - React = require( 'react' ), - sinon = require( 'sinon' ), - sinonChai = require( 'sinon-chai' ), - mockery = require( 'mockery' ); +import { expect } from 'chai'; +import moment from 'moment'; +import React from 'react'; +import sinon from 'sinon'; +import mockery from 'mockery'; /** * Internal dependencies */ -var EditorGroundControl; +import EmptyComponent from 'test/helpers/react/empty-component'; +import useI18n from 'test/helpers/use-i18n'; +import useMockery from 'test/helpers/use-mockery'; +import useFakeDom from 'test/helpers/use-fake-dom'; /** * Module variables */ -var MOCK_COMPONENT = React.createClass( { - render: function() { - return null; - } -} ); - -var MOCK_SITE = { +const MOCK_SITE = { capabilities: { publish_posts: true }, options: {} }; -var expect = chai.expect; +describe( 'EditorGroundControl', function() { + let shallow, i18n, EditorGroundControl; -chai.use( sinonChai ); + useMockery(); + useI18n(); + useFakeDom(); -describe( 'EditorGroundControl', function() { - this.timeout( 10 * 1000 ); before( function() { - mockery.enable( { - warnOnReplace: false, - warnOnUnregistered: false - } ); - mockery.registerMock( 'components/card', MOCK_COMPONENT ); - mockery.registerMock( 'components/popover', MOCK_COMPONENT ); - mockery.registerMock( 'my-sites/site', MOCK_COMPONENT ); - mockery.registerMock( 'post-editor/edit-post-status', MOCK_COMPONENT ); - mockery.registerMock( 'post-editor/editor-status-label', MOCK_COMPONENT ); - mockery.registerMock( 'components/sticky-panel', MOCK_COMPONENT ); - mockery.registerMock( 'components/post-schedule', MOCK_COMPONENT ); + shallow = require( 'enzyme' ).shallow; + i18n = require( 'lib/mixins/i18n' ); + + mockery.registerMock( 'components/card', EmptyComponent ); + mockery.registerMock( 'components/popover', EmptyComponent ); + mockery.registerMock( 'my-sites/site', EmptyComponent ); + mockery.registerMock( 'post-editor/edit-post-status', EmptyComponent ); + mockery.registerMock( 'post-editor/editor-status-label', EmptyComponent ); + mockery.registerMock( 'components/sticky-panel', EmptyComponent ); + mockery.registerMock( 'components/post-schedule', EmptyComponent ); EditorGroundControl = require( '../' ).WrappedComponent; - EditorGroundControl.prototype.__reactAutoBindMap.translate = sinon.stub().returnsArg( 0 ); - EditorGroundControl.prototype.__reactAutoBindMap.moment = moment; - // TODO: REDUX - add proper tests when whole post-editor is reduxified - mockery.registerMock( 'react-redux', { - connect: () => component => component - } ); - } ); - beforeEach( function() { - ReactDom.unmountComponentAtNode( document.body ); + EditorGroundControl.prototype.__reactAutoBindMap.translate = i18n.translate; + EditorGroundControl.prototype.__reactAutoBindMap.moment = i18n.moment; } ); after( function() { delete EditorGroundControl.prototype.__reactAutoBindMap.translate; delete EditorGroundControl.prototype.__reactAutoBindMap.moment; - mockery.deregisterAll(); - mockery.disable(); } ); describe( '#getPreviewLabel()', function() { it( 'should return View if the site is a Jetpack site and the post is published', function() { - var tree = ReactDom.render( + var tree = shallow( , - document.body - ); + /> + ).instance(); expect( tree.getPreviewLabel() ).to.equal( 'View' ); } ); it( 'should return Preview if the post was not originally published', function() { - var tree = ReactDom.render( + var tree = shallow( , - document.body - ); + /> + ).instance(); expect( tree.getPreviewLabel() ).to.equal( 'Preview' ); } ); @@ -100,27 +81,25 @@ describe( 'EditorGroundControl', function() { describe( '#getPrimaryButtonLabel()', function() { it( 'should return Update if the post was originally published and is still slated to be published', function() { - var tree = ReactDom.render( + var tree = shallow( , - document.body - ); + /> + ).instance(); expect( tree.getPrimaryButtonLabel() ).to.equal( 'Update' ); } ); it( 'should return Update if the post was originally published and is currently reverted to non-published status', function() { - var tree = ReactDom.render( + var tree = shallow( , - document.body - ); + /> + ).instance(); expect( tree.getPrimaryButtonLabel() ).to.equal( 'Update' ); } ); @@ -130,14 +109,13 @@ describe( 'EditorGroundControl', function() { nextMonth = now.month( now.month() + 1 ).format(), tree; - tree = ReactDom.render( + tree = shallow( , - document.body - ); + /> + ).instance(); expect( tree.getPrimaryButtonLabel() ).to.equal( 'Schedule' ); } ); @@ -147,14 +125,13 @@ describe( 'EditorGroundControl', function() { nextMonth = now.month( now.month() + 1 ).format(), tree; - tree = ReactDom.render( + tree = shallow( , - document.body - ); + /> + ).instance(); expect( tree.getPrimaryButtonLabel() ).to.equal( 'Schedule' ); } ); @@ -164,14 +141,13 @@ describe( 'EditorGroundControl', function() { nextMonth = now.month( now.month() + 1 ).format(), tree; - tree = ReactDom.render( + tree = shallow( , - document.body - ); + /> + ).instance(); expect( tree.getPrimaryButtonLabel() ).to.equal( 'Update' ); } ); @@ -181,14 +157,13 @@ describe( 'EditorGroundControl', function() { nextMonth = now.month( now.month() + 1 ).format(), tree; - tree = ReactDom.render( + tree = shallow( , - document.body - ); + /> + ).instance(); expect( tree.getPrimaryButtonLabel() ).to.equal( 'Update' ); } ); @@ -198,32 +173,30 @@ describe( 'EditorGroundControl', function() { lastMonth = now.month( now.month() - 1 ).format(), tree; - tree = ReactDom.render( + tree = shallow( , - document.body - ); + /> + ).instance(); expect( tree.getPrimaryButtonLabel() ).to.equal( 'Publish' ); } ); it( 'should return Publish if the post is a draft', function() { - var tree = ReactDom.render( + var tree = shallow( , - document.body - ); + /> + ).instance(); expect( tree.getPrimaryButtonLabel() ).to.equal( 'Publish' ); } ); it( 'should return "Submit for Review" if the post is a draft and user can\'t publish', function() { - var tree = ReactDom.render( + var tree = shallow( , - document.body - ); + /> + ).instance(); expect( tree.getPrimaryButtonLabel() ).to.equal( 'Submit for Review' ); } ); @@ -241,37 +213,37 @@ describe( 'EditorGroundControl', function() { describe( '#isSaveEnabled()', function() { it( 'should return false if form is saving', function() { - var tree = ReactDom.render( , document.body ); + var tree = shallow( ).instance(); expect( tree.isSaveEnabled() ).to.be.false; } ); it( 'should return false if saving is blocked', function() { - var tree = ReactDom.render( , document.body ); + var tree = shallow( ).instance(); expect( tree.isSaveEnabled() ).to.be.false; } ); it( 'should return false if post does not exist', function() { - var tree = ReactDom.render( , document.body ); + var tree = shallow( ).instance(); expect( tree.isSaveEnabled() ).to.be.false; } ); it( 'should return true if dirty and post has content and post is not published', function() { - var tree = ReactDom.render( , document.body ); + var tree = shallow( ).instance(); expect( tree.isSaveEnabled() ).to.be.true; } ); it( 'should return false if dirty, but post has no content', function() { - var tree = ReactDom.render( , document.body ); + var tree = shallow( ).instance(); expect( tree.isSaveEnabled() ).to.be.false; } ); it( 'should return false if dirty and post is published', function() { - var tree = ReactDom.render( , document.body ); + var tree = shallow( ).instance(); expect( tree.isSaveEnabled() ).to.be.false; } ); @@ -279,31 +251,31 @@ describe( 'EditorGroundControl', function() { describe( '#isPreviewEnabled()', function() { it( 'should return true if post is not empty', function() { - var tree = ReactDom.render( , document.body ); + var tree = shallow( ).instance(); expect( tree.isPreviewEnabled() ).to.be.true; } ); it( 'should return false if saving is blocked', function() { - var tree = ReactDom.render( , document.body ); + var tree = shallow( ).instance(); expect( tree.isPreviewEnabled() ).to.be.false; } ); it( 'should return true even if form is publishing', function() { - var tree = ReactDom.render( , document.body ); + var tree = shallow( ).instance(); expect( tree.isPreviewEnabled() ).to.be.true; } ); it( 'should return false if not dirty', function() { - var tree = ReactDom.render( , document.body ); + var tree = shallow( ).instance(); expect( tree.isPreviewEnabled() ).to.be.false; } ); it( 'should return false if post has no content', function() { - var tree = ReactDom.render( , document.body ); + var tree = shallow( ).instance(); expect( tree.isPreviewEnabled() ).to.be.false; } ); @@ -311,37 +283,37 @@ describe( 'EditorGroundControl', function() { describe( '#isPrimaryButtonEnabled()', function() { it( 'should return true if form is not publishing and post is not empty', function() { - var tree = ReactDom.render( , document.body ); + var tree = shallow( ).instance(); expect( tree.isPrimaryButtonEnabled() ).to.be.true; } ); it( 'should return true if form is not publishind and post is new and has content, but is not dirty', function() { - var tree = ReactDom.render( , document.body ); + var tree = shallow( ).instance(); expect( tree.isPrimaryButtonEnabled() ).to.be.true; } ); it( 'should return false if form is publishing', function() { - var tree = ReactDom.render( , document.body ); + var tree = shallow( ).instance(); expect( tree.isPrimaryButtonEnabled() ).to.be.false; } ); it( 'should return false if saving is blocked', function() { - var tree = ReactDom.render( , document.body ); + var tree = shallow( ).instance(); expect( tree.isPrimaryButtonEnabled() ).to.be.false; } ); it( 'should return false if not dirty and has no content', function() { - var tree = ReactDom.render( , document.body ); + var tree = shallow( ).instance(); expect( tree.isPrimaryButtonEnabled() ).to.be.false; } ); it( 'should return false if post has no content', function() { - var tree = ReactDom.render( , document.body ); + var tree = shallow( ).instance(); expect( tree.isPrimaryButtonEnabled() ).to.be.false; } ); @@ -352,14 +324,13 @@ describe( 'EditorGroundControl', function() { var onPublish = sinon.spy(), tree; - tree = ReactDom.render( + tree = shallow( , - document.body - ); + /> + ).instance(); tree.onPrimaryButtonClick(); @@ -372,15 +343,14 @@ describe( 'EditorGroundControl', function() { onSave = sinon.spy(), tree; - tree = ReactDom.render( + tree = shallow( , - document.body - ); + /> + ).instance(); tree.onPrimaryButtonClick(); @@ -393,15 +363,14 @@ describe( 'EditorGroundControl', function() { onSave = sinon.spy(), tree; - tree = ReactDom.render( + tree = shallow( , - document.body - ); + /> + ).instance(); tree.onPrimaryButtonClick(); @@ -414,15 +383,14 @@ describe( 'EditorGroundControl', function() { onPublish = sinon.spy(), tree; - tree = ReactDom.render( + tree = shallow( , - document.body - ); + /> + ).instance(); tree.onPrimaryButtonClick(); @@ -433,15 +401,14 @@ describe( 'EditorGroundControl', function() { var onSave = sinon.spy(), tree; - tree = ReactDom.render( + tree = shallow( , - document.body - ); + /> + ).instance(); tree.onPrimaryButtonClick(); @@ -452,7 +419,7 @@ describe( 'EditorGroundControl', function() { var onSave = sinon.spy(), tree; - tree = ReactDom.render( + tree = shallow( , - document.body - ); + /> + ).instance(); tree.onPrimaryButtonClick(); diff --git a/client/post-editor/editor-sharing/Makefile b/client/post-editor/editor-sharing/Makefile deleted file mode 100644 index 75a9f3f8086a9..0000000000000 --- a/client/post-editor/editor-sharing/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -REPORTER ?= spec -MOCHA ?= ../../../node_modules/.bin/mocha -NODE_BIN := $(shell npm bin) -BASE_DIR := $(NODE_BIN)/../.. -NODE_PATH := test:$(BASE_DIR)/client - -test: - @NODE_ENV=test NODE_PATH=$(NODE_PATH) $(MOCHA) --compilers jsx:babel/register --reporter $(REPORTER) - -.PHONY: test diff --git a/client/post-editor/editor-sharing/test/index.js b/client/post-editor/editor-sharing/test/index.js deleted file mode 100644 index 29f0c60fd39d9..0000000000000 --- a/client/post-editor/editor-sharing/test/index.js +++ /dev/null @@ -1,3 +0,0 @@ -describe( 'EditorSharing', function() { - require( './specs/publicize-connection' ); -} ); diff --git a/client/post-editor/editor-sharing/test/specs/publicize-connection.jsx b/client/post-editor/editor-sharing/test/publicize-connection.jsx similarity index 72% rename from client/post-editor/editor-sharing/test/specs/publicize-connection.jsx rename to client/post-editor/editor-sharing/test/publicize-connection.jsx index d6b7b67ea0512..bffd4cf48d5de 100644 --- a/client/post-editor/editor-sharing/test/specs/publicize-connection.jsx +++ b/client/post-editor/editor-sharing/test/publicize-connection.jsx @@ -1,17 +1,14 @@ -/* eslint-disable vars-on-top */ -require( 'lib/react-test-env-setup' )(); - /** * External dependencies */ -var ReactDom = require( 'react-dom' ), - React = require( 'react' ), - expect = require( 'chai' ).expect; +import { shallow } from 'enzyme'; +import React from 'react'; +import { expect } from 'chai'; /** * Internal dependencies */ -var PublicizeConnection = require( '../../publicize-connection' ).WrappedComponent; +import useFakeDom from 'test/helpers/use-fake-dom'; /** * Module variables @@ -26,8 +23,12 @@ var CONNECTION = { }; describe( 'PublicizeConnection', function() { - beforeEach( function() { - ReactDom.unmountComponentAtNode( document.body ); + let PublicizeConnection; + + useFakeDom(); + + before( () => { + PublicizeConnection = require( '../publicize-connection' ).WrappedComponent; } ); describe( '#isConnectionSkipped()', function() { @@ -40,12 +41,11 @@ describe( 'PublicizeConnection', function() { ] }; - tree = ReactDom.render( + tree = shallow( , - document.body - ); + connection={ CONNECTION } /> + ).instance(); expect( tree.isConnectionSkipped() ).to.equal( true ); } ); @@ -60,12 +60,11 @@ describe( 'PublicizeConnection', function() { ] }; - tree = ReactDom.render( + tree = shallow( , - document.body - ); + connection={ CONNECTION } /> + ).instance(); expect( tree.isConnectionSkipped() ).to.equal( false ); } ); @@ -81,12 +80,11 @@ describe( 'PublicizeConnection', function() { ] }; - tree = ReactDom.render( + tree = shallow( , - document.body - ); + connection={ CONNECTION } /> + ).instance(); expect( tree.isConnectionDone() ).to.equal( true ); } ); @@ -101,12 +99,11 @@ describe( 'PublicizeConnection', function() { ] }; - tree = ReactDom.render( + tree = shallow( , - document.body - ); + connection={ CONNECTION } /> + ).instance(); expect( tree.isConnectionDone() ).to.equal( false ); } ); diff --git a/client/post-editor/editor-taxonomies/Makefile b/client/post-editor/editor-taxonomies/Makefile deleted file mode 100644 index 5703e5d20744f..0000000000000 --- a/client/post-editor/editor-taxonomies/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -REPORTER ?= spec -NODE_BIN := $(shell npm bin) -MOCHA ?= $(NODE_BIN)/mocha -BASE_DIR := $(NODE_BIN)/../.. -NODE_PATH := test:$(BASE_DIR)/client - -test: - @NODE_ENV=test NODE_PATH=$(NODE_PATH) $(MOCHA) --compilers jsx:babel/register --reporter $(REPORTER) - -.PHONY: test diff --git a/client/post-editor/editor-taxonomies/test/accordion.jsx b/client/post-editor/editor-taxonomies/test/accordion.jsx index 037adae15fe22..acfdae801de4d 100644 --- a/client/post-editor/editor-taxonomies/test/accordion.jsx +++ b/client/post-editor/editor-taxonomies/test/accordion.jsx @@ -1,80 +1,52 @@ -/* eslint-disable vars-on-top */ -require( 'lib/react-test-env-setup' )(); - /** * External dependencies */ -var ReactDom = require( 'react-dom' ), - React = require( 'react' ), - ReactInjection = require( 'react/lib/ReactInjection' ), - mockery = require( 'mockery' ), - expect = require( 'chai' ).expect, - noop = require( 'lodash/noop' ), - TestUtils = require( 'react-addons-test-utils' ); +import React from 'react'; +import mockery from 'mockery'; +import { expect } from 'chai'; /** * Internal dependencies */ -var common = require( 'lib/terms/test/common' ), - CategoryListData = require( 'components/data/category-list-data' ), - TagListData = require( 'components/data/tag-list-data' ), - i18n = require( 'lib/mixins/i18n' ), - TaxonomiesAccordion; - -var MOCK_COMPONENT = React.createClass( { - render: function() { - return null; - } -} ); +import EmptyComponent from 'test/helpers/react/empty-component'; +import useMockery from 'test/helpers/use-mockery'; +import useFakeDom from 'test/helpers/use-fake-dom'; +import useI18n from 'test/helpers/use-i18n'; -mockery.enable( { - warnOnReplace: false, - warnOnUnregistered: false -} ); +describe( 'EditorTaxonomiesAccordion', function() { + let shallow, common, categoryStore, tagStore, i18n, TaxonomiesAccordion, accordion; -mockery.registerMock( 'components/info-popover', MOCK_COMPONENT ); -mockery.registerMock( 'components/tooltip', MOCK_COMPONENT ); -mockery.registerMock( 'component-classes', function() { - return { add: noop, toggle: noop, remove: noop } -} ); -mockery.registerSubstitute( 'matches-selector', 'component-matches-selector' ); -mockery.registerSubstitute( 'query', 'component-query' ); -// TODO: REDUX - add proper tests when whole post-editor is reduxified -mockery.registerMock( 'react-redux', { - connect: () => component => component -} ); -i18n.initialize(); -ReactInjection.Class.injectMixin( i18n.mixin ); -TaxonomiesAccordion = require( 'post-editor/editor-taxonomies/accordion' ); -common.dispatchReceiveCategoryTerms(); + useMockery(); + useFakeDom(); + useI18n(); -describe( 'EditorTaxonomiesAccordion', function() { - var accordion, wrapper; + before( () => { + mockery.registerMock( 'post-editor/editor-categories', EmptyComponent ); + mockery.registerMock( 'post-editor/editor-tags', EmptyComponent ); + mockery.registerMock( 'components/info-popover', EmptyComponent ); - function render( postTaxonomiesProps ) { - unmount(); - wrapper = ReactDom.render( - - - - - , - document.body - ); - accordion = TestUtils.scryRenderedComponentsWithType( wrapper, TaxonomiesAccordion )[0]; - } + shallow = require( 'enzyme' ).shallow; + common = require( 'lib/terms/test/common' ); + categoryStore = require( 'lib/terms/category-store-factory' )( 'default' ); + tagStore = require( 'lib/terms/tag-store' ); + i18n = require( 'lib/mixins/i18n' ); - function unmount() { - if ( wrapper ) { - ReactDom.unmountComponentAtNode( document.body ); - wrapper = null; - } - } + TaxonomiesAccordion = require( 'post-editor/editor-taxonomies/accordion' ); + TaxonomiesAccordion.prototype.__reactAutoBindMap.translate = i18n.translate; - afterEach( unmount ); + common.dispatchReceiveCategoryTerms(); + common.dispatchReceiveTagTerms(); + } ); + + function render( postTaxonomiesProps ) { + accordion = shallow( + + ).instance(); + } describe( 'taxonomies subtitle', function() { it( 'should display one top-level category name', function() { diff --git a/client/tests.json b/client/tests.json index 0a5857cd674f2..ecbb410142b98 100644 --- a/client/tests.json +++ b/client/tests.json @@ -394,6 +394,18 @@ } }, "post-editor": { + "editor-discussion": { + "test": [ "index" ] + }, + "editor-ground-control": { + "test": [ "index" ] + }, + "editor-sharing": { + "test": [ "publicize-connection" ] + }, + "editor-taxonomies": { + "test": [ "accordion" ] + }, "media-modal": { "test": [ "index", "markup", "preload-image" ] },