2015-07-24 16:40:34 +03:00
|
|
|
import React from 'react';
|
|
|
|
import TestUtils from 'react/lib/ReactTestUtils';
|
2015-06-20 02:06:26 +03:00
|
|
|
|
2015-07-24 16:40:34 +03:00
|
|
|
import * as actionTypes from 'constants/action-types';
|
|
|
|
import * as appActions from 'actions/app';
|
2015-07-27 19:41:56 +03:00
|
|
|
import { createReduxStore } from 'data-store';
|
2015-07-24 16:40:34 +03:00
|
|
|
import ErrorMessage from 'components/error';
|
2015-06-20 02:06:26 +03:00
|
|
|
|
2015-07-24 16:40:34 +03:00
|
|
|
import * as helpers from './helpers';
|
2015-06-20 02:06:26 +03:00
|
|
|
|
2015-07-24 16:40:34 +03:00
|
|
|
import PaymentApp from 'apps/payment/app';
|
2015-06-20 02:06:26 +03:00
|
|
|
|
2015-07-24 16:40:34 +03:00
|
|
|
|
|
|
|
describe('Payment App', function() {
|
2015-06-20 02:06:26 +03:00
|
|
|
|
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;
|
2015-06-20 02:06:26 +03:00
|
|
|
|
|
|
|
beforeEach(function() {
|
2015-07-27 15:47:30 +03:00
|
|
|
store = createReduxStore();
|
2015-06-20 02:06:26 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
function mountView() {
|
2015-07-27 15:47:30 +03:00
|
|
|
var FluxContainer = helpers.getFluxContainer(store);
|
2015-06-27 23:54:19 +03:00
|
|
|
|
2015-07-24 16:40:34 +03:00
|
|
|
var fakeWin = {
|
|
|
|
'location': {
|
|
|
|
'href': ('http://pay.dev/?access_token=' + accessToken +
|
|
|
|
'&product=' + productId),
|
2015-06-20 02:06:26 +03:00
|
|
|
},
|
2015-07-24 16:40:34 +03:00
|
|
|
};
|
2015-06-20 02:06:26 +03:00
|
|
|
|
2015-06-25 23:49:13 +03:00
|
|
|
var container = TestUtils.renderIntoDocument(
|
|
|
|
<FluxContainer>
|
|
|
|
{function() {
|
2015-07-24 16:40:34 +03:00
|
|
|
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(
|
2015-07-24 16:40:34 +03:00
|
|
|
container, PaymentApp
|
2015-06-25 23:49:13 +03:00
|
|
|
);
|
|
|
|
}
|
2015-06-20 02:06:26 +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'));
|
2015-06-20 02:06:26 +03:00
|
|
|
var error = TestUtils.findRenderedComponentWithType(
|
2015-06-27 23:54:19 +03:00
|
|
|
View, ErrorMessage
|
2015-06-20 02:06:26 +03:00
|
|
|
);
|
|
|
|
// 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);
|
|
|
|
});
|
|
|
|
|
2015-06-20 02:06:26 +03:00
|
|
|
});
|