You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2016/08/01 14:30:53 UTC
[1/2] fauxton commit: updated refs/heads/master to 0e8ae52
Repository: couchdb-fauxton
Updated Branches:
refs/heads/master 7308368d0 -> 0e8ae5230
Add Enzyme
Enzyme simplifies testing with React
Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/7bec26f7
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/7bec26f7
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/7bec26f7
Branch: refs/heads/master
Commit: 7bec26f7373f5210cca4c9f24fee599918faa44e
Parents: 8bb5be3
Author: Garren Smith <ga...@gmail.com>
Authored: Mon Aug 1 12:20:44 2016 +0200
Committer: Garren Smith <ga...@gmail.com>
Committed: Mon Aug 1 12:20:44 2016 +0200
----------------------------------------------------------------------
.../auth/test/auth.componentsSpec.react.jsx | 109 ++++++++-----------
package.json | 3 +-
webpack.config.test.js | 7 ++
3 files changed, 54 insertions(+), 65 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/7bec26f7/app/addons/auth/test/auth.componentsSpec.react.jsx
----------------------------------------------------------------------
diff --git a/app/addons/auth/test/auth.componentsSpec.react.jsx b/app/addons/auth/test/auth.componentsSpec.react.jsx
index 81eebfe..b577388 100644
--- a/app/addons/auth/test/auth.componentsSpec.react.jsx
+++ b/app/addons/auth/test/auth.componentsSpec.react.jsx
@@ -17,44 +17,43 @@ import Components from "../components.react";
import Stores from "../stores";
import Actions from "../actions";
import TestUtils from "react-addons-test-utils";
+import { mount } from 'enzyme';
import sinon from "sinon";
var assert = utils.assert;
var createAdminSidebarStore = Stores.createAdminSidebarStore;
-describe('Auth -- Components', function () {
+describe('Auth -- Components', () => {
- describe('LoginForm', function () {
- var container, loginForm, stub;
+ describe('LoginForm', () => {
+ let stub;
- beforeEach(function () {
+ beforeEach(() => {
stub = sinon.stub(Actions, 'login');
- container = document.createElement('div');
});
- afterEach(function () {
- ReactDOM.unmountComponentAtNode(container);
+ afterEach(() => {
createAdminSidebarStore.reset();
Actions.login.restore();
});
- it('should trigger login event when form submitted', function () {
- loginForm = TestUtils.renderIntoDocument(<Components.LoginForm />, container);
- TestUtils.Simulate.submit($(ReactDOM.findDOMNode(loginForm)).find('#login')[0]);
+ it('should trigger login event when form submitted', () => {
+ const loginForm = mount(<Components.LoginForm/>);
+ loginForm.find('#login').simulate('submit');
assert.ok(stub.calledOnce);
});
- it('in case of nothing in state, should pass actual values to Actions.login()', function () {
- var username = 'bob';
- var password = 'smith';
+ it('in case of nothing in state, should pass actual values to Actions.login()', () => {
+ const username = 'bob';
+ const password = 'smith';
- loginForm = TestUtils.renderIntoDocument(
+ const loginForm = mount(
<Components.LoginForm
testBlankUsername={username}
testBlankPassword={password}
- />, container);
+ />);
- TestUtils.Simulate.submit($(ReactDOM.findDOMNode(loginForm)).find('#login')[0]);
+ loginForm.find('#login').simulate('submit');
assert.ok(stub.calledOnce);
// confirm Actions.login() received the values that weren't in the DOM
@@ -64,83 +63,65 @@ describe('Auth -- Components', function () {
});
- describe('ChangePasswordForm', function () {
+ describe('ChangePasswordForm', () => {
var container, changePasswordForm;
- beforeEach(function () {
- container = document.createElement('div');
- changePasswordForm = TestUtils.renderIntoDocument(<Components.ChangePasswordForm />, container);
+ beforeEach(() => {
utils.restore(Actions.changePassword);
});
- afterEach(function () {
- ReactDOM.unmountComponentAtNode(container);
- });
-
- it('should call action to update password on field change', function () {
- var spy = sinon.spy(Actions, 'updateChangePasswordField');
- TestUtils.Simulate.change($(ReactDOM.findDOMNode(changePasswordForm)).find('#password')[0], { target: { value: 'bobsyouruncle' }});
+ it('should call action to update password on field change', () => {
+ const changePasswordForm = mount(<Components.ChangePasswordForm />);
+ const spy = sinon.spy(Actions, 'updateChangePasswordField');
+ changePasswordForm.find('#password').simulate('change', { target: { value: 'bobsyouruncle' }});
assert.ok(spy.calledOnce);
});
- it('should call action to update password confirm on field change', function () {
- var spy = sinon.spy(Actions, 'updateChangePasswordConfirmField');
- TestUtils.Simulate.change($(ReactDOM.findDOMNode(changePasswordForm)).find('#password-confirm')[0], { target: { value: 'hotdiggity' }});
+ it('should call action to update password confirm on field change', () => {
+ const changePasswordForm = mount(<Components.ChangePasswordForm />);
+ const spy = sinon.spy(Actions, 'updateChangePasswordConfirmField');
+ changePasswordForm.find('#password-confirm').simulate('change', { target: { value: 'hotdiggity' }});
assert.ok(spy.calledOnce);
});
- it('should call action to submit form', function () {
- var stub = sinon.stub(Actions, 'changePassword', function () {});
- TestUtils.Simulate.submit($(ReactDOM.findDOMNode(changePasswordForm)).find('#change-password')[0]);
+ it('should call action to submit form', () => {
+ const changePasswordForm = mount(<Components.ChangePasswordForm />);
+ var stub = sinon.stub(Actions, 'changePassword', () => {});
+ changePasswordForm.find('#change-password').simulate('submit');
assert.ok(stub.calledOnce);
});
});
- describe('CreateAdminForm', function () {
- var container, createAdminForm;
-
- beforeEach(function () {
- container = document.createElement('div');
- createAdminForm = TestUtils.renderIntoDocument(<Components.CreateAdminForm loginAfter={false} />, container);
- });
-
- afterEach(function () {
- ReactDOM.unmountComponentAtNode(container);
- });
-
- it('should call action to update username on field change', function () {
+ describe('CreateAdminForm', () => {
+ it('should call action to update username on field change', () => {
+ const createAdminForm = mount(<Components.CreateAdminForm loginAfter={false} />);
var spy = sinon.spy(Actions, 'updateCreateAdminUsername');
- TestUtils.Simulate.change($(ReactDOM.findDOMNode(createAdminForm)).find('#username')[0], { target: { value: 'catsmeow' }});
+ createAdminForm.find('#username').simulate('change', { target: { value: 'catsmeow' }});
assert.ok(spy.calledOnce);
});
- it('should call action to update password confirm on field change', function () {
+ it('should call action to update password confirm on field change', () => {
+ const createAdminForm = mount(<Components.CreateAdminForm loginAfter={false} />);
var spy = sinon.spy(Actions, 'updateCreateAdminPassword');
- TestUtils.Simulate.change($(ReactDOM.findDOMNode(createAdminForm)).find('#password')[0], { target: { value: 'topnotch' }});
+ createAdminForm.find('#password').simulate('change', { target: { value: 'topnotch' }});
assert.ok(spy.calledOnce);
});
});
- describe('CreateAdminSidebar', function () {
- var container, createAdminSidebar;
-
- beforeEach(function () {
+ describe('CreateAdminSidebar', () => {
+ beforeEach(() => {
createAdminSidebarStore.reset();
- container = document.createElement('div');
- createAdminSidebar = TestUtils.renderIntoDocument(<Components.CreateAdminSidebar />, container);
- });
-
- afterEach(function () {
- ReactDOM.unmountComponentAtNode(container);
});
- it('confirm the default selected nav item is the change pwd page', function () {
- assert.equal($(ReactDOM.findDOMNode(createAdminSidebar)).find('.active').find('a').attr('href'), '#changePassword');
+ it('confirm the default selected nav item is the change pwd page', () => {
+ const wrapper = mount(<Components.CreateAdminSidebar />)
+ assert.equal(wrapper.find('.active a').props().href, '#changePassword');
});
- it('confirm clicking a sidebar nav item selects it in the DOM', function () {
- TestUtils.Simulate.click($(ReactDOM.findDOMNode(createAdminSidebar)).find('li[data-page="addAdmin"]').find('a')[0]);
- assert.equal($(ReactDOM.findDOMNode(createAdminSidebar)).find('.active').find('a').attr('href'), '#addAdmin');
+ it('confirm clicking a sidebar nav item selects it in the DOM', () => {
+ const wrapper = mount(<Components.CreateAdminSidebar />)
+ wrapper.find('li[data-page="addAdmin"]').find('a').simulate('click');
+ assert.equal(wrapper.find('.active a').props().href, '#addAdmin');
});
});
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/7bec26f7/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 0441ed7..c698c3d 100644
--- a/package.json
+++ b/package.json
@@ -16,6 +16,7 @@
]
},
"devDependencies": {
+ "enzyme": "^2.4.1",
"es5-shim": "4.5.4",
"mocha": "^2.4.5",
"mocha-phantomjs": "git+https://github.com/garrensmith/mocha-phantomjs.git",
@@ -110,7 +111,7 @@
"start": "node ./bin/fauxton",
"start-debug": "DIST=./dist/debug node ./bin/fauxton",
"preversion": "node version-check.js && grunt release",
- "test-before-publish":"npm run preversion && npm install . -g",
+ "test-before-publish": "npm run preversion && npm install . -g",
"create:animaldb": "./bin/create-animal-db",
"docker:couchdb-up": "docker-compose -f ./docker/dc.selenium.yml up -d couchdb",
"docker:selenium-up": "docker-compose -f ./docker/dc.selenium.yml up -d selenium",
http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/7bec26f7/webpack.config.test.js
----------------------------------------------------------------------
diff --git a/webpack.config.test.js b/webpack.config.test.js
index be053c6..eae1b2b 100644
--- a/webpack.config.test.js
+++ b/webpack.config.test.js
@@ -77,6 +77,13 @@ module.exports = {
path: __dirname + '/test',
filename: 'bundle.js' //All our code is compiled into a single file called bundle.js
},
+ externals: { //for webpack to play nice with enzyme
+ "jsdom": "window",
+ "cheerio": "window",
+ 'react/lib/ExecutionEnvironment': true,
+ 'react/lib/ReactContext': 'window',
+ 'react/addons': true
+ },
plugins: [
new webpack.optimize.LimitChunkCountPlugin({maxChunks: 1})
]
[2/2] fauxton commit: updated refs/heads/master to 0e8ae52
Posted by ga...@apache.org.
Merge branch 'add-enzyme'
Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/0e8ae523
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/0e8ae523
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/0e8ae523
Branch: refs/heads/master
Commit: 0e8ae5230d3ef3daa1e04e29ee049ad5976ef814
Parents: 7308368 7bec26f
Author: Garren Smith <ga...@gmail.com>
Authored: Mon Aug 1 16:30:33 2016 +0200
Committer: Garren Smith <ga...@gmail.com>
Committed: Mon Aug 1 16:30:33 2016 +0200
----------------------------------------------------------------------
.../auth/test/auth.componentsSpec.react.jsx | 109 ++++++++-----------
package.json | 3 +-
webpack.config.test.js | 7 ++
3 files changed, 54 insertions(+), 65 deletions(-)
----------------------------------------------------------------------