payments-ui/tests/test.payment-app.jsx

89 строки
2.2 KiB
React
Исходник Обычный вид История

import React from 'react';
import TestUtils from 'react/lib/ReactTestUtils';
import * as actionTypes from 'constants/action-types';
import * as appActions from 'actions/app';
import { createReduxStore } from 'data-store';
import ErrorMessage from 'components/error';
import * as helpers from './helpers';
import PaymentApp from 'apps/payment/app';
describe('Payment App', function() {
2015-06-27 23:54:19 +03:00
var accessToken = 'some-oauth-token';
var productId = 'mozilla-concrete-brick';
var FakeLogin = helpers.stubComponent();
var FakePurchase = helpers.stubComponent();
2015-07-27 15:47:30 +03:00
var store;
beforeEach(function() {
2015-07-27 15:47:30 +03:00
store = createReduxStore();
});
function mountView() {
2015-07-27 15:47:30 +03:00
var FluxContainer = helpers.getFluxContainer(store);
2015-06-27 23:54:19 +03:00
var fakeWin = {
'location': {
'href': ('http://pay.dev/?access_token=' + accessToken +
'&product=' + productId),
},
};
2015-06-25 23:49:13 +03:00
var container = TestUtils.renderIntoDocument(
<FluxContainer>
{function() {
return (
<PaymentApp
Login={FakeLogin} Purchase={FakePurchase} win={fakeWin} />
);
2015-06-25 23:49:13 +03:00
}}
</FluxContainer>
);
2015-06-27 23:54:19 +03:00
return TestUtils.findRenderedComponentWithType(
container, PaymentApp
2015-06-25 23:49:13 +03:00
);
}
it('should render an error', function() {
2015-06-27 23:54:19 +03:00
var View = mountView();
2015-07-27 15:47:30 +03:00
store.dispatch(appActions.error('this is some error'));
var error = TestUtils.findRenderedComponentWithType(
2015-06-27 23:54:19 +03:00
View, ErrorMessage
);
// Maybe expand this test later if we pass in custom properties.
assert.ok(error);
});
2015-06-27 23:54:19 +03:00
it('should render a sign-in page', function() {
var View = mountView();
var login = TestUtils.findRenderedComponentWithType(
View, FakeLogin
);
assert.equal(login.props.accessToken, accessToken);
});
it('should render a purchase page', function() {
var user = {
email: 'f@f.com',
payment_methods: [],
signedIn: true,
};
var View = mountView();
2015-07-27 15:47:30 +03:00
store.dispatch({
2015-06-27 23:54:19 +03:00
type: actionTypes.USER_SIGNED_IN,
user: user,
});
var purchase = TestUtils.findRenderedComponentWithType(
View, FakePurchase
);
assert.deepEqual(purchase.props.user, user);
});
});