Skip to content

Instantly share code, notes, and snippets.

@kumar303
Created September 3, 2015 17:43
Show Gist options
  • Save kumar303/f84f20a2d191c3e90666 to your computer and use it in GitHub Desktop.
Save kumar303/f84f20a2d191c3e90666 to your computer and use it in GitHub Desktop.
payments-ui tests without Provider
diff --git a/tests/apps/test.management-app.jsx b/tests/apps/test.management-app.jsx
index 23836ec..dcdf9ba 100644
--- a/tests/apps/test.management-app.jsx
+++ b/tests/apps/test.management-app.jsx
@@ -2,7 +2,6 @@ import React from 'react';
import TestUtils from 'react/lib/ReactTestUtils';
import * as appActions from 'actions/app';
-import { createReduxStore } from 'data-store';
import { ManagementApp } from 'apps/management/app';
@@ -10,6 +9,8 @@ import * as helpers from '../helpers';
describe('management/app', function() {
+ var fakeApp;
+ var fakeError;
var fakeDispatch;
var fakeWindow;
var FakeManagement;
@@ -17,9 +18,10 @@ describe('management/app', function() {
var FakeSignIn;
var fakeManagement;
var fakeUser;
- var store;
beforeEach(function() {
+ fakeApp = {};
+ fakeError = {};
fakeDispatch = sinon.spy();
fakeManagement = {};
fakeUser = {};
@@ -31,12 +33,12 @@ describe('management/app', function() {
FakeManagement = helpers.stubComponent();
FakeManageCards = helpers.stubComponent();
FakeSignIn = helpers.stubComponent();
- store = createReduxStore();
});
- function mountView({ window = fakeWindow, ...props } = {}) {
- return (
+ function mountView({ window=fakeWindow, app=fakeApp, ...props } = {}) {
+ return TestUtils.renderIntoDocument(
<ManagementApp
+ app={app}
dispatch={fakeDispatch}
window={window}
Management={FakeManagement}
@@ -72,17 +74,14 @@ describe('management/app', function() {
});
it('should display app errors', function() {
- var view = mountView();
-
- var appError = appActions.error('some error');
- store.dispatch(appError);
+ var appState = appActions.error('some error');
+ var view = mountView({app: appState});
var mgmt = TestUtils.findRenderedComponentWithType(
view, FakeManagement
);
var errorPane = mgmt.props.children[0];
- assert.deepEqual(errorPane.props.error, appError.error);
-
+ assert.deepEqual(errorPane.props.error, appState.error);
});
});
diff --git a/tests/apps/test.transaction-app.jsx b/tests/apps/test.transaction-app.jsx
index 5172b3a..3536551 100644
--- a/tests/apps/test.transaction-app.jsx
+++ b/tests/apps/test.transaction-app.jsx
@@ -1,14 +1,12 @@
import React from 'react';
import TestUtils from 'react/lib/ReactTestUtils';
-import { Provider } from 'react-redux';
import * as helpers from '../helpers';
-import { createReduxStore } from 'data-store';
import { initialUserState } from 'reducers/user';
import * as actionTypes from 'constants/action-types';
import * as appActions from 'actions/app';
-import { default as TransactionApp } from 'apps/transaction/app';
+import { TransactionApp } from 'apps/transaction/app';
import ErrorMessage from 'components/error';
@@ -16,15 +14,21 @@ describe('Transaction App', function() {
var accessToken = 'some-oauth-token';
var defaultProductId = 'mozilla-concrete-brick';
+ var fakeApp;
+ var fakeDispatch;
+ var fakeUser;
var FakeSignIn = helpers.stubComponent();
var FakeTransaction = helpers.stubComponent();
- var store;
beforeEach(function() {
- store = createReduxStore();
+ fakeApp = {};
+ fakeUser = {};
+ fakeDispatch = sinon.spy();
});
- function mountView({productId=defaultProductId} = {}) {
+ function mountView({productId=defaultProductId, app=fakeApp,
+ user=fakeUser,
+ ...props} = {}) {
var fakeWin = {
'location': {
'href': ('http://pay.dev/?access_token=' + accessToken +
@@ -32,18 +36,16 @@ describe('Transaction App', function() {
},
};
- var container = TestUtils.renderIntoDocument(
- <Provider store={store}>
- {() => {
- return (
- <TransactionApp
- SignIn={FakeSignIn} Transaction={FakeTransaction} win={fakeWin} />
- );
- }}
- </Provider>
- );
- return TestUtils.findRenderedComponentWithType(
- container, TransactionApp
+ return TestUtils.renderIntoDocument(
+ <TransactionApp
+ app={app}
+ dispatch={fakeDispatch}
+ SignIn={FakeSignIn}
+ Transaction={FakeTransaction}
+ user={user}
+ win={fakeWin}
+ {...props}
+ />
);
}
@@ -53,13 +55,12 @@ describe('Transaction App', function() {
});
it('should render an error', function() {
- var View = mountView();
- store.dispatch(appActions.error('this is some error'));
- var error = TestUtils.findRenderedComponentWithType(
+ var appState = appActions.error('this is some error');
+ var View = mountView({app: appState});
+ var errorPane = TestUtils.findRenderedComponentWithType(
View, ErrorMessage
);
- // Maybe expand this test later if we pass in custom properties.
- assert.ok(error);
+ assert.deepEqual(errorPane.props.error, appState.error);
});
it('should render a sign-in page', function() {
@@ -77,12 +78,7 @@ describe('Transaction App', function() {
signedIn: true,
});
- var View = mountView();
-
- store.dispatch({
- type: actionTypes.USER_SIGNED_IN,
- user: user,
- });
+ var View = mountView({user: user});
assert.ok(TestUtils.findRenderedComponentWithType(
View, FakeTransaction
diff --git a/tests/views/test.transaction.jsx b/tests/views/test.transaction.jsx
index ae5bb3b..79fbd38 100644
--- a/tests/views/test.transaction.jsx
+++ b/tests/views/test.transaction.jsx
@@ -1,68 +1,59 @@
import React from 'react';
import TestUtils from 'react/lib/ReactTestUtils';
-import { Provider } from 'react-redux';
import * as helpers from '../helpers';
import * as actionTypes from 'constants/action-types';
import * as transactionActions from 'actions/transaction';
-import { createReduxStore } from 'data-store';
+import { initialTransactionState } from 'reducers/transaction';
import { defaultState as defaultUser } from 'reducers/user';
-import { default as Transaction } from 'views/transaction';
+import { Transaction } from 'views/transaction';
describe('Transaction', function() {
+ var fakeDispatch;
+ var fakeTransaction;
var fakeUser;
var productId = 'mozilla-concrete-brick';
var FakeBraintreeToken = helpers.stubComponent();
var FakeCompletePayment = helpers.stubComponent();
var FakeProductPayChooser = helpers.stubComponent();
var FakeProductPay = helpers.stubComponent();
- var store;
beforeEach(function() {
- store = createReduxStore();
+ fakeDispatch = sinon.spy();
+ fakeTransaction = {};
fakeUser = Object.assign({}, defaultUser, {
email: '[email protected]',
});
});
- function mountView({...props} = {}) {
- var container = TestUtils.renderIntoDocument(
- <Provider store={store}>
- {() => {
- return (
- <Transaction
- BraintreeToken={FakeBraintreeToken}
- CompletePayment={FakeCompletePayment}
- ProductPay={FakeProductPay}
- ProductPayChooser={FakeProductPayChooser}
- productId={productId}
- {...props}
- />
- );
- }}
- </Provider>
- );
-
- return TestUtils.findRenderedComponentWithType(
- container, Transaction
+ function mountView({user=fakeUser, transaction=fakeTransaction,
+ ...props} = {}) {
+ return TestUtils.renderIntoDocument(
+ <Transaction
+ BraintreeToken={FakeBraintreeToken}
+ CompletePayment={FakeCompletePayment}
+ ProductPay={FakeProductPay}
+ ProductPayChooser={FakeProductPayChooser}
+ productId={productId}
+ transaction={transaction}
+ user={user}
+ {...props}
+ />
);
}
- function signInUser({payMethods}) {
- store.dispatch({
- type: actionTypes.USER_SIGNED_IN,
- user: Object.assign({}, fakeUser, {
- payMethods: payMethods,
+ function getState({payMethods}) {
+ return {
+ transaction: Object.assign(initialTransactionState, {
}),
- });
-
- store.dispatch({
- type: actionTypes.GOT_BRAINTREE_TOKEN,
- braintreeToken: 'braintree-token',
+ user: Object.assign(defaultUser, fakeUser, {
+ payMethods: payMethods,
+ braintreeToken: 'braintree-token',
+ },
});
}
@@ -128,13 +119,14 @@ describe('Transaction', function() {
it('should render new card entry on explicit request', function() {
var payMethods = [{type: 'Visa'}];
- var View = mountView();
- // When a user signs in this would normally trigger a pay chooser.
- signInUser({payMethods: payMethods});
+ // For a signed in user this would normally trigger a pay chooser.
+ var { user, transaction } = getState({payMethods: payMethods});
+
+ // Create a transaction with a specific payWithNewCard request.
+ var transState = transactionActions.payWithNewCard();
- // Dispatch a specific payWithNewCard request.
- store.dispatch(transactionActions.payWithNewCard());
+ var View = mountView({user: userState, transaction: transState});
// Instead make sure a new card entry form was rendered.
TestUtils.findRenderedComponentWithType(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment