Convert tests to not use rewire and update to ES6+
This commit is contained in:
Родитель
aab26f1680
Коммит
0d42279830
|
@ -1,145 +1,152 @@
|
|||
'use strict';
|
||||
|
||||
var React = require('react');
|
||||
var TestUtils = require('react/lib/ReactTestUtils');
|
||||
import React from 'react';
|
||||
import TestUtils from 'react/lib/ReactTestUtils';
|
||||
|
||||
module.exports = {
|
||||
testCards: {
|
||||
amex: '378282246310005',
|
||||
discover: '6011111111111117',
|
||||
jcb: '3530111333300000',
|
||||
maestro: '6304000000000000',
|
||||
mastercard: '5555555555554444',
|
||||
visa: '4111111111111111',
|
||||
invalidVisa: '4111111111111113',
|
||||
},
|
||||
|
||||
declinedError: {
|
||||
error_response: {
|
||||
braintree: {
|
||||
'__all__': [
|
||||
{'message': 'Do Not Honor', 'code': '2000'},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
cvvError: {
|
||||
error_response: {
|
||||
braintree: {
|
||||
'cvv': [
|
||||
{'message': 'Gateway Rejected: cvv', 'code': 'cvv'},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
findByClass: function(component, className){
|
||||
return TestUtils.findRenderedDOMComponentWithClass(component, className);
|
||||
},
|
||||
|
||||
findAllByClass: function(component, className){
|
||||
return TestUtils.scryRenderedDOMComponentsWithClass(component, className);
|
||||
},
|
||||
|
||||
findByTag: function(component, tag){
|
||||
return TestUtils.findRenderedDOMComponentWithTag(component, tag);
|
||||
},
|
||||
|
||||
findAllByTag: function(component, tag){
|
||||
return TestUtils.scryRenderedDOMComponentsWithTag(component, tag);
|
||||
},
|
||||
|
||||
getFluxContainer: function(redux) {
|
||||
//
|
||||
// Get a container component to set context stubs so you can use it
|
||||
// to wrap a component for testing.
|
||||
// You'd only need this to test a component that uses the
|
||||
// redux Connector component.
|
||||
//
|
||||
|
||||
var FluxContainer = React.createClass({
|
||||
|
||||
displayName: 'FluxContainer',
|
||||
|
||||
propTypes: {
|
||||
children: React.PropTypes.func.isRequired,
|
||||
},
|
||||
|
||||
childContextTypes: {
|
||||
redux: React.PropTypes.object.isRequired,
|
||||
},
|
||||
|
||||
getChildContext: function() {
|
||||
return {redux: redux};
|
||||
},
|
||||
|
||||
render () {
|
||||
return this.props.children();
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
return FluxContainer;
|
||||
},
|
||||
|
||||
fakeJquery: function(opt) {
|
||||
//
|
||||
// Return a context to work with a fake jquery object in a test.
|
||||
//
|
||||
var componentContext;
|
||||
opt = opt || {};
|
||||
opt.returnedData = opt.returnedData || {};
|
||||
// Must be one of 'success', 'fail'
|
||||
opt.result = opt.result || 'success';
|
||||
|
||||
var jqueryStubResponse = {
|
||||
fail: function() {
|
||||
return this;
|
||||
},
|
||||
then: function() {
|
||||
return this;
|
||||
},
|
||||
};
|
||||
|
||||
if (opt.result === 'success') {
|
||||
jqueryStubResponse.then = function(callback) {
|
||||
console.log('jquery stub: executing success');
|
||||
callback.call(componentContext, opt.returnedData);
|
||||
return this;
|
||||
};
|
||||
} else if (opt.result === 'fail') {
|
||||
jqueryStubResponse.fail = function(callback) {
|
||||
callback.call(componentContext);
|
||||
return this;
|
||||
};
|
||||
} else {
|
||||
throw new Error('unexpected jquery stub result: ' + opt.result);
|
||||
}
|
||||
|
||||
var jqueryStub = {
|
||||
ajax: function(ajaxOpt) {
|
||||
console.log('jquery stub: executing ajax()', ajaxOpt);
|
||||
componentContext = ajaxOpt.context;
|
||||
return jqueryStubResponse;
|
||||
},
|
||||
ajaxSetup: function() {},
|
||||
};
|
||||
|
||||
return {
|
||||
ajaxSpy: sinon.spy(jqueryStub, 'ajax'),
|
||||
ajaxSetupSpy: sinon.spy(jqueryStub, 'ajaxSetup'),
|
||||
stub: jqueryStub,
|
||||
};
|
||||
},
|
||||
|
||||
stubComponent: function() {
|
||||
return React.createClass({
|
||||
displayName: 'StubComponent',
|
||||
render: function() {
|
||||
return <div></div>;
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
export const testCards = {
|
||||
amex: '378282246310005',
|
||||
discover: '6011111111111117',
|
||||
jcb: '3530111333300000',
|
||||
maestro: '6304000000000000',
|
||||
mastercard: '5555555555554444',
|
||||
visa: '4111111111111111',
|
||||
invalidVisa: '4111111111111113',
|
||||
};
|
||||
|
||||
|
||||
export const declinedError = {
|
||||
error_response: {
|
||||
braintree: {
|
||||
'__all__': [
|
||||
{'message': 'Do Not Honor', 'code': '2000'},
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
export const cvvError = {
|
||||
error_response: {
|
||||
braintree: {
|
||||
'cvv': [
|
||||
{'message': 'Gateway Rejected: cvv', 'code': 'cvv'},
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
export function findByClass(component, className){
|
||||
return TestUtils.findRenderedDOMComponentWithClass(component, className);
|
||||
}
|
||||
|
||||
|
||||
export function findAllByClass (component, className){
|
||||
return TestUtils.scryRenderedDOMComponentsWithClass(component, className);
|
||||
}
|
||||
|
||||
|
||||
export function findByTag(component, tag){
|
||||
return TestUtils.findRenderedDOMComponentWithTag(component, tag);
|
||||
}
|
||||
|
||||
|
||||
export function findAllByTag(component, tag){
|
||||
return TestUtils.scryRenderedDOMComponentsWithTag(component, tag);
|
||||
}
|
||||
|
||||
|
||||
export function getFluxContainer(redux) {
|
||||
//
|
||||
// Get a container component to set context stubs so you can use it
|
||||
// to wrap a component for testing.
|
||||
// You'd only need this to test a component that uses the
|
||||
// redux Connector component.
|
||||
//
|
||||
|
||||
var FluxContainer = React.createClass({
|
||||
|
||||
displayName: 'FluxContainer',
|
||||
|
||||
propTypes: {
|
||||
children: React.PropTypes.func.isRequired,
|
||||
},
|
||||
|
||||
childContextTypes: {
|
||||
redux: React.PropTypes.object.isRequired,
|
||||
},
|
||||
|
||||
getChildContext: function() {
|
||||
return {redux: redux};
|
||||
},
|
||||
|
||||
render () {
|
||||
return this.props.children();
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
return FluxContainer;
|
||||
}
|
||||
|
||||
|
||||
export function fakeJquery(opt) {
|
||||
//
|
||||
// Return a context to work with a fake jquery object in a test.
|
||||
//
|
||||
var componentContext;
|
||||
opt = opt || {};
|
||||
opt.returnedData = opt.returnedData || {};
|
||||
// Must be one of 'success', 'fail'
|
||||
opt.result = opt.result || 'success';
|
||||
|
||||
var jqueryStubResponse = {
|
||||
fail: function() {
|
||||
return this;
|
||||
},
|
||||
then: function() {
|
||||
return this;
|
||||
},
|
||||
};
|
||||
|
||||
if (opt.result === 'success') {
|
||||
jqueryStubResponse.then = function(callback) {
|
||||
console.log('jquery stub: executing success');
|
||||
callback.call(componentContext, opt.returnedData);
|
||||
return this;
|
||||
};
|
||||
} else if (opt.result === 'fail') {
|
||||
jqueryStubResponse.fail = function(callback) {
|
||||
callback.call(componentContext);
|
||||
return this;
|
||||
};
|
||||
} else {
|
||||
throw new Error('unexpected jquery stub result: ' + opt.result);
|
||||
}
|
||||
|
||||
var jqueryStub = {
|
||||
ajax: function(ajaxOpt) {
|
||||
console.log('jquery stub: executing ajax()', ajaxOpt);
|
||||
componentContext = ajaxOpt.context;
|
||||
return jqueryStubResponse;
|
||||
},
|
||||
ajaxSetup: function() {},
|
||||
};
|
||||
|
||||
return {
|
||||
ajaxSpy: sinon.spy(jqueryStub, 'ajax'),
|
||||
ajaxSetupSpy: sinon.spy(jqueryStub, 'ajaxSetup'),
|
||||
stub: jqueryStub,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export function stubComponent() {
|
||||
return React.createClass({
|
||||
displayName: 'StubComponent',
|
||||
render: function() {
|
||||
return <div></div>;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
'use strict';
|
||||
|
||||
// Webpack tests entry point. Bundles all the test files
|
||||
// into a single file.
|
||||
// See: https://github.com/webpack/karma-webpack#alternative-usage
|
||||
|
||||
require('shims');
|
||||
import 'shims';
|
||||
|
||||
var context = require.context('.', true, /test\..*?.jsx?$/);
|
||||
context.keys().forEach(context);
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
'use strict';
|
||||
import React from 'react';
|
||||
import TestUtils from 'react/lib/ReactTestUtils';
|
||||
|
||||
var React = require('react');
|
||||
var TestUtils = require('react/lib/ReactTestUtils');
|
||||
var helpers = require('./helpers');
|
||||
import { Accordion,
|
||||
AccordionContent,
|
||||
AccordionSection } from 'components/accordion';
|
||||
|
||||
var {Accordion,
|
||||
AccordionContent,
|
||||
AccordionSection} = require('components/accordion');
|
||||
import * as helpers from './helpers';
|
||||
|
||||
|
||||
describe('Accordion', function() {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
var actionTypes = require('constants/action-types');
|
||||
var appActions = require('actions/app');
|
||||
import * as actionTypes from 'constants/action-types';
|
||||
import * as appActions from 'actions/app';
|
||||
|
||||
|
||||
describe('appActions', function() {
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
'use strict';
|
||||
import React from 'react';
|
||||
import TestUtils from 'react/lib/ReactTestUtils';
|
||||
|
||||
import CardChoice from 'components/card-choice';
|
||||
|
||||
var CardChoice = require('components/card-choice');
|
||||
import * as helpers from './helpers';
|
||||
|
||||
var helpers = require('./helpers');
|
||||
|
||||
var React;
|
||||
var TestUtils;
|
||||
|
||||
describe('Card Choice', function() {
|
||||
|
||||
|
@ -53,8 +51,6 @@ describe('Card Choice', function() {
|
|||
];
|
||||
|
||||
beforeEach(function() {
|
||||
React = require('react');
|
||||
TestUtils = require('react/lib/ReactTestUtils');
|
||||
this.CardChoice = TestUtils.renderIntoDocument(
|
||||
<CardChoice cards={cardListData} />
|
||||
);
|
||||
|
@ -129,8 +125,6 @@ describe('Single Card Choice', function() {
|
|||
];
|
||||
|
||||
beforeEach(function() {
|
||||
React = require('react');
|
||||
TestUtils = require('react/lib/ReactTestUtils');
|
||||
this.CardChoice = TestUtils.renderIntoDocument(
|
||||
<CardChoice cards={cardListData} />
|
||||
);
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
'use strict';
|
||||
import React, { findDOMNode } from 'react';
|
||||
import TestUtils from 'react/lib/ReactTestUtils';
|
||||
|
||||
import * as helpers from './helpers';
|
||||
|
||||
var CardForm = require('components/card-form');
|
||||
import CardForm from 'components/card-form';
|
||||
|
||||
var helpers = require('./helpers');
|
||||
|
||||
var React;
|
||||
var TestUtils;
|
||||
|
||||
describe('Card Details', function() {
|
||||
|
||||
|
@ -20,8 +18,6 @@ describe('Card Details', function() {
|
|||
];
|
||||
|
||||
beforeEach(function() {
|
||||
React = require('react');
|
||||
TestUtils = require('react/lib/ReactTestUtils');
|
||||
this.CardForm = TestUtils.renderIntoDocument(
|
||||
<CardForm data-token="whatever" id="something"/>
|
||||
);
|
||||
|
@ -45,12 +41,12 @@ describe('Card Details', function() {
|
|||
});
|
||||
|
||||
it('renders a token', function() {
|
||||
var formNode = this.CardForm.getDOMNode();
|
||||
var formNode = findDOMNode(this.CardForm);
|
||||
assert.equal(formNode.getAttribute('data-token'), 'whatever');
|
||||
});
|
||||
|
||||
it('renders an id', function() {
|
||||
var formNode = this.CardForm.getDOMNode();
|
||||
var formNode = findDOMNode(this.CardForm);
|
||||
assert.equal(formNode.getAttribute('id'), 'something');
|
||||
});
|
||||
|
||||
|
@ -100,7 +96,7 @@ describe('Card Details', function() {
|
|||
it('should not have a name attr on any input', function() {
|
||||
var inputs = helpers.findAllByTag(this.CardForm, 'input');
|
||||
for (var i = 0; i < inputs.length; i += 1) {
|
||||
var input = inputs[i].getDOMNode();
|
||||
var input = findDOMNode(inputs[i]);
|
||||
if (input.getAttribute('name') !== null) {
|
||||
throw new Error('A name attr should not be set on any cc form fields');
|
||||
}
|
||||
|
@ -110,7 +106,7 @@ describe('Card Details', function() {
|
|||
it('should have type=tel and autocomplete=off on all fields', function() {
|
||||
var inputs = helpers.findAllByTag(this.CardForm, 'input');
|
||||
for (var i = 0; i < inputs.length; i += 1) {
|
||||
var input = inputs[i].getDOMNode();
|
||||
var input = findDOMNode(inputs[i]);
|
||||
assert.equal(input.getAttribute('autocomplete'),
|
||||
'off', 'autocomplete attr should be "off"');
|
||||
assert.equal(input.getAttribute('type'),
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
'use strict';
|
||||
|
||||
var React;
|
||||
var TestUtils;
|
||||
|
||||
var CardIcon = require('components/card-icon');
|
||||
import React, { findDOMNode } from 'react';
|
||||
import TestUtils from 'react/lib/ReactTestUtils';
|
||||
|
||||
import CardIcon from 'components/card-icon';
|
||||
|
||||
describe('Card Icon', function() {
|
||||
|
||||
var cardIcon;
|
||||
var cards = [
|
||||
'amex',
|
||||
'discover',
|
||||
|
@ -18,18 +14,12 @@ describe('Card Icon', function() {
|
|||
'visa',
|
||||
];
|
||||
|
||||
beforeEach(function() {
|
||||
React = require('react');
|
||||
TestUtils = require('react/lib/ReactTestUtils');
|
||||
cardIcon = TestUtils.renderIntoDocument(
|
||||
<CardIcon cardType="american-express" />
|
||||
);
|
||||
});
|
||||
|
||||
function testCard(cardType) {
|
||||
return function() {
|
||||
cardIcon.setProps({'cardType': cardType});
|
||||
var cardIconNode = cardIcon.getDOMNode();
|
||||
var CardIcon_ = TestUtils.renderIntoDocument(
|
||||
<CardIcon cardType={cardType} />
|
||||
);
|
||||
var cardIconNode = findDOMNode(CardIcon_);
|
||||
assert.include(
|
||||
cardIconNode.getAttribute('class'), 'cctype-' + cardType);
|
||||
};
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
'use strict';
|
||||
import React from 'react';
|
||||
import TestUtils from 'react/lib/ReactTestUtils';
|
||||
|
||||
var React;
|
||||
var TestUtils;
|
||||
|
||||
var CardChoice = require('components/card-choice');
|
||||
var CardListing = require('views/card-listing');
|
||||
import CardChoice from 'components/card-choice';
|
||||
import CardListing from 'views/card-listing';
|
||||
|
||||
|
||||
describe('CardListingView', function() {
|
||||
|
@ -14,8 +12,6 @@ describe('CardListingView', function() {
|
|||
var savedVisa = {provider_id: '3vr3ym', type_name: 'Visa'};
|
||||
|
||||
beforeEach(function() {
|
||||
React = require('react');
|
||||
TestUtils = require('react/lib/ReactTestUtils');
|
||||
|
||||
payWithNewCardSpy = sinon.spy();
|
||||
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
'use strict';
|
||||
import React, { findDOMNode } from 'react';
|
||||
import TestUtils from 'react/lib/ReactTestUtils';
|
||||
|
||||
var React;
|
||||
var TestUtils;
|
||||
import * as helpers from './helpers';
|
||||
|
||||
var CompletePayment = require('views/complete-payment');
|
||||
|
||||
var helpers = require('./helpers');
|
||||
import CompletePayment from 'views/complete-payment';
|
||||
|
||||
|
||||
describe('CompletePayment', function() {
|
||||
|
@ -18,8 +16,6 @@ describe('CompletePayment', function() {
|
|||
postMessage: this.sandbox.stub(),
|
||||
},
|
||||
};
|
||||
React = require('react');
|
||||
TestUtils = require('react/lib/ReactTestUtils');
|
||||
this.CompletePayment = TestUtils.renderIntoDocument(
|
||||
<CompletePayment productId='mozilla-concrete-brick'
|
||||
userEmail={this.email}
|
||||
|
@ -33,7 +29,7 @@ describe('CompletePayment', function() {
|
|||
|
||||
it('should show where the receipt was emailed', function() {
|
||||
var email = helpers.findByClass(this.CompletePayment, 'email');
|
||||
assert.equal(email.getDOMNode().textContent, this.email);
|
||||
assert.equal(findDOMNode(email).textContent, this.email);
|
||||
});
|
||||
|
||||
it('should fire handleClick when OK button is clicked', function() {
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
var actionTypes = require('constants/action-types');
|
||||
var appActions = require('actions/app');
|
||||
var purchaseActions = require('actions/purchase');
|
||||
var dataStore = require('stores');
|
||||
import * as actionTypes from 'constants/action-types';
|
||||
import * as appActions from 'actions/app';
|
||||
import * as purchaseActions from 'actions/purchase';
|
||||
import * as dataStore from 'stores';
|
||||
|
||||
|
||||
describe('app', function() {
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
'use strict';
|
||||
|
||||
var ghPagesConfig = require('../tasks/gh-pages');
|
||||
import ghPagesConfig from '../tasks/gh-pages';
|
||||
|
||||
describe('grunt-gh-pages config', function() {
|
||||
it('Docker builds should be silent=true', function() {
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
'use strict';
|
||||
import React from 'react';
|
||||
import TestUtils from 'react/lib/ReactTestUtils';
|
||||
|
||||
var React;
|
||||
var TestUtils;
|
||||
|
||||
var Login = require('views/login');
|
||||
import Login from 'views/login';
|
||||
|
||||
|
||||
describe('Login', function() {
|
||||
|
@ -11,11 +9,6 @@ describe('Login', function() {
|
|||
var accessToken = 'some-oauth-access-token';
|
||||
var signInSpy = sinon.spy();
|
||||
|
||||
beforeEach(function() {
|
||||
React = require('react');
|
||||
TestUtils = require('react/lib/ReactTestUtils');
|
||||
});
|
||||
|
||||
function mountView() {
|
||||
return TestUtils.renderIntoDocument(
|
||||
<Login accessToken={accessToken} signIn={signInSpy} />
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
'use strict';
|
||||
import React, { findDOMNode } from 'react';
|
||||
import TestUtils from 'react/lib/ReactTestUtils';
|
||||
|
||||
var React = require('react');
|
||||
var TestUtils = require('react/lib/ReactTestUtils');
|
||||
import Modal from 'components/modal';
|
||||
|
||||
var Modal = require('components/modal');
|
||||
|
||||
var helpers = require('./helpers');
|
||||
import * as helpers from './helpers';
|
||||
|
||||
|
||||
describe('Modal', function() {
|
||||
|
@ -28,17 +26,17 @@ describe('Modal', function() {
|
|||
|
||||
it('should have a title', function() {
|
||||
var title = helpers.findByTag(this.Modal, 'h2');
|
||||
assert.equal(title.getDOMNode().firstChild.nodeValue, 'whatever');
|
||||
assert.equal(findDOMNode(title).firstChild.nodeValue, 'whatever');
|
||||
});
|
||||
|
||||
it('should have child content', function() {
|
||||
var content = helpers.findByClass(this.Modal, 'm-content');
|
||||
assert.equal(content.getDOMNode().nodeName.toLowerCase(), 'div');
|
||||
assert.equal(findDOMNode(content).nodeName.toLowerCase(), 'div');
|
||||
});
|
||||
|
||||
it('should have child paragraph', function() {
|
||||
var text = helpers.findByClass(this.Modal, 'm-text');
|
||||
assert.equal(text.getDOMNode().firstChild.nodeValue,
|
||||
assert.equal(findDOMNode(text).firstChild.nodeValue,
|
||||
'Just some noddy content');
|
||||
});
|
||||
|
||||
|
@ -52,7 +50,7 @@ describe('Modal', function() {
|
|||
|
||||
it('should call close func when clicking the close link', function() {
|
||||
var close = helpers.findByClass(this.Modal, 'close');
|
||||
TestUtils.Simulate.click(close.getDOMNode(), this.eventStub);
|
||||
TestUtils.Simulate.click(findDOMNode(close), this.eventStub);
|
||||
assert.ok(this.eventStub.preventDefault.called);
|
||||
assert.ok(this.eventStub.stopPropagation.called);
|
||||
assert.ok(this.closeFunc.called);
|
||||
|
@ -60,7 +58,7 @@ describe('Modal', function() {
|
|||
|
||||
it('should not call close func when clicking other content.', function() {
|
||||
var otherLink = helpers.findByClass(this.Modal, 'other-link');
|
||||
TestUtils.Simulate.click(otherLink.getDOMNode(), this.eventStub);
|
||||
TestUtils.Simulate.click(findDOMNode(otherLink), this.eventStub);
|
||||
assert.notOk(this.eventStub.preventDefault.called);
|
||||
assert.notOk(this.eventStub.stopPropagation.called);
|
||||
assert.notOk(this.closeFunc.called);
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
'use strict';
|
||||
import React from 'react';
|
||||
import TestUtils from 'react/lib/ReactTestUtils';
|
||||
|
||||
var React = require('react');
|
||||
var TestUtils;
|
||||
var rewire = require('rewire');
|
||||
import * as actionTypes from 'constants/action-types';
|
||||
import * as appActions from 'actions/app';
|
||||
import { create as reduxCreate } from 'redux-config';
|
||||
import ErrorMessage from 'components/error';
|
||||
|
||||
var actionTypes = require('constants/action-types');
|
||||
var appActions = require('actions/app');
|
||||
var reduxConfig = require('redux-config');
|
||||
var ErrorMessage = require('components/error');
|
||||
import * as helpers from './helpers';
|
||||
|
||||
var helpers = require('./helpers');
|
||||
import PaymentApp from 'apps/payment/app';
|
||||
|
||||
describe('App', function() {
|
||||
|
||||
describe('Payment App', function() {
|
||||
|
||||
var accessToken = 'some-oauth-token';
|
||||
var productId = 'mozilla-concrete-brick';
|
||||
|
@ -20,35 +20,31 @@ describe('App', function() {
|
|||
var redux;
|
||||
|
||||
beforeEach(function() {
|
||||
TestUtils = require('react/lib/ReactTestUtils');
|
||||
redux = reduxConfig.create();
|
||||
redux = reduxCreate();
|
||||
});
|
||||
|
||||
function mountView() {
|
||||
var FluxContainer = helpers.getFluxContainer(redux);
|
||||
|
||||
var app = rewire('apps/payment/app');
|
||||
app.__set__({
|
||||
'Login': FakeLogin,
|
||||
'Purchase': FakePurchase,
|
||||
'window': {
|
||||
'location': {
|
||||
'href': ('http://pay.dev/?access_token=' + accessToken +
|
||||
'&product=' + productId),
|
||||
},
|
||||
var fakeWin = {
|
||||
'location': {
|
||||
'href': ('http://pay.dev/?access_token=' + accessToken +
|
||||
'&product=' + productId),
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
var App = app.component;
|
||||
var container = TestUtils.renderIntoDocument(
|
||||
<FluxContainer>
|
||||
{function() {
|
||||
return <App />;
|
||||
return (
|
||||
<PaymentApp
|
||||
Login={FakeLogin} Purchase={FakePurchase} win={fakeWin} />
|
||||
);
|
||||
}}
|
||||
</FluxContainer>
|
||||
);
|
||||
return TestUtils.findRenderedComponentWithType(
|
||||
container, App
|
||||
container, PaymentApp
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
'use strict';
|
||||
import products from 'products';
|
||||
|
||||
|
||||
var products = require('products');
|
||||
|
||||
describe('products', function() {
|
||||
|
||||
it('should have concrete brick data', function() {
|
||||
|
|
|
@ -1,18 +1,13 @@
|
|||
'use strict';
|
||||
import React from 'react';
|
||||
import TestUtils from 'react/lib/ReactTestUtils';
|
||||
|
||||
var React;
|
||||
var TestUtils;
|
||||
|
||||
var ProductDetail = require('components/product-detail');
|
||||
|
||||
var helpers = require('./helpers');
|
||||
import ProductDetail from 'components/product-detail';
|
||||
import * as helpers from './helpers';
|
||||
|
||||
|
||||
describe('ProductDetail', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
React = require('react');
|
||||
TestUtils = require('react/lib/ReactTestUtils');
|
||||
this.ProductDetail = TestUtils.renderIntoDocument(
|
||||
<ProductDetail productId="mozilla-concrete-brick" />
|
||||
);
|
||||
|
@ -29,8 +24,6 @@ describe('ProductDetail', function() {
|
|||
describe('ProductDetail Exceptions', function() {
|
||||
|
||||
it('should throw error with invalid product', function() {
|
||||
React = require('react');
|
||||
TestUtils = require('react/lib/ReactTestUtils');
|
||||
assert.throws(function() {
|
||||
TestUtils.renderIntoDocument(
|
||||
<ProductDetail productId='not-real-product' />
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
'use strict';
|
||||
import React from 'react';
|
||||
import TestUtils from 'react/lib/ReactTestUtils';
|
||||
|
||||
var React;
|
||||
var TestUtils;
|
||||
var rewire = require('rewire');
|
||||
import * as helpers from './helpers';
|
||||
|
||||
var actionTypes = require('constants/action-types');
|
||||
var reduxConfig = require('redux-config');
|
||||
var purchaseActions = require('actions/purchase');
|
||||
import * as actionTypes from 'constants/action-types';
|
||||
import * as purchaseActions from 'actions/purchase';
|
||||
import { create as reduxCreate } from 'redux-config';
|
||||
|
||||
import Purchase from 'views/purchase';
|
||||
|
||||
var helpers = require('./helpers');
|
||||
|
||||
describe('Purchase', function() {
|
||||
|
||||
|
@ -23,26 +23,23 @@ describe('Purchase', function() {
|
|||
var redux;
|
||||
|
||||
beforeEach(function() {
|
||||
React = require('react');
|
||||
TestUtils = require('react/lib/ReactTestUtils');
|
||||
redux = reduxConfig.create();
|
||||
redux = reduxCreate();
|
||||
});
|
||||
|
||||
function mountView(userOverrides) {
|
||||
var user = Object.assign({}, defaultUser, userOverrides);
|
||||
var FluxContainer = helpers.getFluxContainer(redux);
|
||||
|
||||
var Purchase = rewire('views/purchase');
|
||||
Purchase.__set__({
|
||||
'CompletePayment': FakeCompletePayment,
|
||||
'CardListing': FakeCardListing,
|
||||
'CardDetails': FakeCardDetails,
|
||||
});
|
||||
|
||||
var container = TestUtils.renderIntoDocument(
|
||||
<FluxContainer>
|
||||
{function() {
|
||||
return <Purchase user={user} productId={productId} />;
|
||||
return (
|
||||
<Purchase
|
||||
CardDetails={FakeCardDetails}
|
||||
CardListing={FakeCardListing}
|
||||
CompletePayment={FakeCompletePayment}
|
||||
user={user} productId={productId} />
|
||||
);
|
||||
}}
|
||||
</FluxContainer>
|
||||
);
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
'use strict';
|
||||
import React, { findDOMNode } from 'react';
|
||||
import TestUtils from 'react/lib/ReactTestUtils';
|
||||
|
||||
var React = require('react');
|
||||
var TestUtils = require('react/lib/ReactTestUtils');
|
||||
var helpers = require('./helpers');
|
||||
import * as helpers from './helpers';
|
||||
|
||||
var Spinner = require('components/spinner');
|
||||
import Spinner from 'components/spinner';
|
||||
|
||||
|
||||
describe('Spinner', function() {
|
||||
|
@ -12,13 +11,13 @@ describe('Spinner', function() {
|
|||
it('Uses loading as the default text', function() {
|
||||
var Spinner_ = TestUtils.renderIntoDocument(<Spinner />);
|
||||
var textNode = helpers.findByClass(Spinner_, 'text');
|
||||
assert.equal(textNode.getDOMNode().firstChild.nodeValue, 'Loading');
|
||||
assert.equal(findDOMNode(textNode).firstChild.nodeValue, 'Loading');
|
||||
});
|
||||
|
||||
it('Uses custom text as supplied', function() {
|
||||
var Spinner_ = TestUtils.renderIntoDocument(<Spinner text="whatever" />);
|
||||
var textNode = helpers.findByClass(Spinner_, 'text');
|
||||
assert.equal(textNode.getDOMNode().firstChild.nodeValue, 'whatever');
|
||||
assert.equal(findDOMNode(textNode).firstChild.nodeValue, 'whatever');
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -1,11 +1,4 @@
|
|||
'use strict';
|
||||
|
||||
var rewire = require('rewire');
|
||||
var tracking = rewire('tracking');
|
||||
|
||||
// Get at the top level var in the tracking module
|
||||
// using rewire.
|
||||
var Tracking = tracking.__get__('Tracking');
|
||||
import { Tracking } from 'tracking';
|
||||
|
||||
|
||||
describe('Tracking uninitialized', function() {
|
||||
|
@ -42,9 +35,9 @@ describe('Tracking functions', function() {
|
|||
});
|
||||
|
||||
it('should throw if page not set', function() {
|
||||
assert.throws(function() {
|
||||
assert.throws(() => {
|
||||
this.t.setPage();
|
||||
}.bind(this), Error, /page is required/);
|
||||
}, Error, /page is required/);
|
||||
});
|
||||
|
||||
it('should call ga', function() {
|
||||
|
@ -53,17 +46,17 @@ describe('Tracking functions', function() {
|
|||
});
|
||||
|
||||
it('should throw if category not set', function() {
|
||||
assert.throws(function() {
|
||||
assert.throws(() => {
|
||||
this.t.sendEvent({});
|
||||
}.bind(this), Error, /opts\.category is required/);
|
||||
}, Error, /opts\.category is required/);
|
||||
});
|
||||
|
||||
it('should throw if action not set', function() {
|
||||
assert.throws(function() {
|
||||
assert.throws(() => {
|
||||
this.t.sendEvent({
|
||||
category: 'whatever',
|
||||
});
|
||||
}.bind(this), Error, /opts\.action is required/);
|
||||
}, Error, /opts\.action is required/);
|
||||
});
|
||||
|
||||
it('should call _ga', function() {
|
||||
|
|
|
@ -1,25 +1,16 @@
|
|||
'use strict';
|
||||
import * as actionTypes from 'constants/action-types';
|
||||
import * as appActions from 'actions/app';
|
||||
import * as userActions from 'actions/user';
|
||||
|
||||
var rewire = require('rewire');
|
||||
|
||||
var actionTypes = require('constants/action-types');
|
||||
var appActions = require('actions/app');
|
||||
|
||||
var helpers = require('./helpers');
|
||||
import * as helpers from './helpers';
|
||||
|
||||
|
||||
describe('userActions', function() {
|
||||
|
||||
var dispatchSpy;
|
||||
var userActions;
|
||||
|
||||
beforeEach(function() {
|
||||
dispatchSpy = sinon.spy();
|
||||
userActions = rewire('actions/user');
|
||||
userActions.__set__({
|
||||
// Replace with a non-functioning stub by default until overidden.
|
||||
'$': {},
|
||||
});
|
||||
});
|
||||
|
||||
function fakeSignInResult() {
|
||||
|
@ -38,45 +29,47 @@ describe('userActions', function() {
|
|||
opt.jqueryOpt.returnedData = opt.data;
|
||||
|
||||
var jquery = helpers.fakeJquery(opt.jqueryOpt);
|
||||
userActions.__set__('$', jquery.stub);
|
||||
|
||||
return opt.data;
|
||||
return {
|
||||
data: opt.data,
|
||||
jquery: jquery.stub,
|
||||
};
|
||||
}
|
||||
|
||||
it('should dispatch sign-in action', function() {
|
||||
setApiSignInResult();
|
||||
var setup = setApiSignInResult();
|
||||
|
||||
userActions.signIn('access-token')(dispatchSpy);
|
||||
userActions.signIn('access-token', setup.jquery)(dispatchSpy);
|
||||
|
||||
var action = dispatchSpy.firstCall.args[0];
|
||||
assert.equal(action.type, actionTypes.USER_SIGNED_IN);
|
||||
});
|
||||
|
||||
it('should set email from sign-in', function() {
|
||||
var data = setApiSignInResult();
|
||||
var setup = setApiSignInResult();
|
||||
|
||||
userActions.signIn('access-token')(dispatchSpy);
|
||||
userActions.signIn('access-token', setup.jquery)(dispatchSpy);
|
||||
|
||||
var action = dispatchSpy.firstCall.args[0];
|
||||
assert.equal(action.user.email, data.buyer_email);
|
||||
assert.equal(action.user.email, setup.data.buyer_email);
|
||||
});
|
||||
|
||||
it('should set saved payment methods from sign-in', function() {
|
||||
var data = fakeSignInResult();
|
||||
var payMethods = [{'provider_id': '3vr3ym'}];
|
||||
data.payment_methods = payMethods;
|
||||
setApiSignInResult({data: data});
|
||||
var setup = setApiSignInResult({data: data});
|
||||
|
||||
userActions.signIn('access-token')(dispatchSpy);
|
||||
userActions.signIn('access-token', setup.jquery)(dispatchSpy);
|
||||
|
||||
var action = dispatchSpy.firstCall.args[0];
|
||||
assert.equal(action.user.payment_methods, payMethods);
|
||||
});
|
||||
|
||||
it('should set empty payment methods', function() {
|
||||
setApiSignInResult();
|
||||
var setup = setApiSignInResult();
|
||||
|
||||
userActions.signIn('access-token')(dispatchSpy);
|
||||
userActions.signIn('access-token', setup.jquery)(dispatchSpy);
|
||||
|
||||
var action = dispatchSpy.firstCall.args[0];
|
||||
assert.deepEqual(action.user.payment_methods, []);
|
||||
|
@ -84,8 +77,7 @@ describe('userActions', function() {
|
|||
|
||||
it('should sign-in with access token', function() {
|
||||
var jquery = helpers.fakeJquery({returnedData: fakeSignInResult()});
|
||||
userActions.__set__('$', jquery.stub);
|
||||
userActions.signIn('access-token')(dispatchSpy);
|
||||
userActions.signIn('access-token', jquery.stub)(dispatchSpy);
|
||||
|
||||
assert.equal(jquery.ajaxSpy.firstCall.args[0].data.access_token,
|
||||
'access-token');
|
||||
|
@ -94,17 +86,16 @@ describe('userActions', function() {
|
|||
it('should configure CSRF headers on sign-in', function() {
|
||||
var data = fakeSignInResult();
|
||||
var jquery = helpers.fakeJquery({returnedData: data});
|
||||
userActions.__set__('$', jquery.stub);
|
||||
userActions.signIn('access-token')(dispatchSpy);
|
||||
userActions.signIn('access-token', jquery.stub)(dispatchSpy);
|
||||
|
||||
assert.deepEqual(jquery.ajaxSetupSpy.firstCall.args[0].headers,
|
||||
{'X-CSRFToken': data.csrf_token});
|
||||
});
|
||||
|
||||
it('should set app error on failure', function() {
|
||||
setApiSignInResult({jqueryOpt: {result: 'fail'}});
|
||||
var setup = setApiSignInResult({jqueryOpt: {result: 'fail'}});
|
||||
|
||||
userActions.signIn('access-token')(dispatchSpy);
|
||||
userActions.signIn('access-token', setup.jquery)(dispatchSpy);
|
||||
|
||||
var action = dispatchSpy.firstCall.args[0];
|
||||
assert.deepEqual(action, appActions.error('user login failed'));
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
'use strict';
|
||||
|
||||
var utils = require('utils');
|
||||
import * as utils from 'utils';
|
||||
|
||||
|
||||
describe('utils.parseQuery', function() {
|
||||
|
|
Загрузка…
Ссылка в новой задаче