Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React unit testing example #2170

Merged
merged 56 commits into from
May 31, 2017
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
af9fc5e
component snapshot
joykare Apr 25, 2017
6fa0cc6
babel additions
joykare Apr 25, 2017
49c3335
remove dependancies not used
joykare Apr 26, 2017
e1472f7
Use mocks to mock input props for component
joykare Apr 26, 2017
baad7fe
Merge branch 'development' into joykare-testing-2066
joykare Apr 26, 2017
6c5b725
Change stored snapshot to match new look after merge with development
joykare Apr 26, 2017
65fb97b
replace babel-latest with babel-es2015
joykare May 2, 2017
c96c7a2
Take care of warning
joykare May 2, 2017
5255cb0
babelrc to es2015
joykare May 2, 2017
a3cef62
Merge branch 'development' into joykare-testing-2066
brent-hoover May 4, 2017
4caa827
Add back in missing babel package
brent-hoover May 4, 2017
433b1e7
no more globals!
jshimko May 10, 2017
b8bbb23
Declare variable before assigning
brent-hoover May 11, 2017
0092774
Declare variable before assigning
brent-hoover May 11, 2017
76942d3
Declare variable before assigning. Remove unused variables
brent-hoover May 11, 2017
5ce8d55
Remove unused variable, check
brent-hoover May 11, 2017
0de146c
Merge branch 'development' into joykare-testing-2066
brent-hoover May 12, 2017
789dfc9
Declare variable before using it
brent-hoover May 12, 2017
06e0bb1
Declare variable before using it
brent-hoover May 12, 2017
6221221
Can't use `this` in an arrow function
brent-hoover May 12, 2017
882fd7d
Correct function declarations
brent-hoover May 12, 2017
1d38e3f
Eliminate implied global `Alerts` + no undeclared
brent-hoover May 12, 2017
5b947a5
Remove commented out code
brent-hoover May 12, 2017
e305df1
Declare explicit globals
brent-hoover May 12, 2017
da994a7
move default userCurrency deeper in the object (#2259)
kieckhafer May 13, 2017
1d3b551
Merge branch 'development' into joykare-testing-2066
brent-hoover May 19, 2017
24b36b7
Use Collection explicit functions
brent-hoover May 19, 2017
2779dfd
Don't log doing nothing
brent-hoover May 19, 2017
a5dbd5d
Make Alert a global because it's a mess
brent-hoover May 19, 2017
3c7daf7
Ok actually, don't do that
brent-hoover May 19, 2017
63cb3b3
Don't allow implicit globals
brent-hoover May 19, 2017
a557e37
Bug fixes
brent-hoover May 19, 2017
adaaf3f
Fixing lack of declaration
brent-hoover May 19, 2017
3e0a5c1
Pass error to logger
brent-hoover May 19, 2017
0963556
Merge branch 'development' into joykare-testing-2066
May 23, 2017
952be34
Fix import order
brent-hoover May 23, 2017
b841ead
Fix changed reference
brent-hoover May 23, 2017
4d6f0c6
Add jest testing to Circle CI
brent-hoover May 23, 2017
8a9e765
Update NPM packages
brent-hoover May 23, 2017
826e596
Added npm test command
mikemurray May 23, 2017
0fa6639
Use an NPM script rather than global Jest
brent-hoover May 23, 2017
18579f9
Merge branch 'development' into joykare-testing-2066
brent-hoover May 23, 2017
6a6c2af
Merge development
May 23, 2017
a230696
remove circle.yml
May 23, 2017
f54f155
Make changes to new CI config
brent-hoover May 24, 2017
c7b1873
Change to proper step configuration
brent-hoover May 24, 2017
fc38b24
For clarity, `test-react`
May 24, 2017
f8eaa7f
Revert "For clarity, `test-react`"
May 24, 2017
7c312de
Merge branch 'development' into joykare-testing-2066
May 24, 2017
8eaaa19
Update Jest to current version
brent-hoover May 25, 2017
7a3824a
Merge branch 'development' into joykare-testing-2066
brent-hoover May 25, 2017
07f82eb
Just testing to see if this fixes it
brent-hoover May 25, 2017
19b7528
Remove npm install of desperation
brent-hoover May 25, 2017
43d0f61
Remove node cache
brent-hoover May 25, 2017
eb1bdca
Merge branch 'development' into joykare-testing-2066
May 26, 2017
9fb1797
Merge branch 'development' into joykare-testing-2066
mikemurray May 30, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"plugins": ["lodash"],
"presets": ["stage-2"]
"presets": ["es2015", "react", "stage-2"]
}
11 changes: 2 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,18 @@ jobs:
- ~/.meteor

# install app dependencies
- restore_cache:
name: Restoring node_modules cache
key: node_modules

- run: meteor npm install

- save_cache:
name: Saving node_modules to cache
key: node_modules
paths:
- /home/reaction/node_modules

# run tests
- restore_cache:
name: Restoring Meteor dev_bundle cache
key: dev_bundle

- run: npm test
- run: reaction test


- save_cache:
name: Saving Meteor dev_bundle to cache
key: dev_bundle
Expand Down
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"args": "after-used"
}],
"no-use-before-define": [2, "nofunc"], // http://eslint.org/docs/rules/no-use-before-define
"no-implicit-globals": 2, // http://eslint.org/docs/rules/no-implicit-globals

/**
* Possible errors
Expand Down
6 changes: 2 additions & 4 deletions client/api/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Reaction } from "/client/modules/core";
import { Router } from "/client/modules/router";

// Legacy globals
// TODO: add deprecation warnings
ReactionCore = Reaction;
ReactionRouter = Router;
window.ReactionCore = Reaction;
window.ReactionRouter = Router;

export {
Reaction,
Expand Down
2 changes: 1 addition & 1 deletion client/modules/accounts/templates/addressBook/form/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Template.addressBookForm.helpers({
if ((shop !== null ? shop.locales.countries[selectedCountry].states : void 0) === null) {
return false;
}
options = [];
const options = [];
const ref = shop !== null ? shop.locales.countries[selectedCountry].states : void 0;
for (const state in ref) {
if ({}.hasOwnProperty.call(ref, state)) {
Expand Down
1 change: 1 addition & 0 deletions client/modules/accounts/templates/forgot/forgot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Meteor } from "meteor/meteor";
import { Template } from "meteor/templating";
import { i18next } from "/client/api";
import { LoginFormSharedHelpers } from "/client/modules/accounts/helpers";
import { LoginFormValidation } from "/lib/api";

Template.loginFormResetPasswordView.events({

Expand Down
1 change: 1 addition & 0 deletions client/modules/accounts/templates/signIn/signIn.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { LoginFormSharedHelpers } from "/client/modules/accounts/helpers";
import { Meteor } from "meteor/meteor";
import { Template } from "meteor/templating";
import { LoginFormValidation } from "/lib/api";

/**
* onCreated: Login form sign in view
Expand Down
1 change: 1 addition & 0 deletions client/modules/accounts/templates/signUp/signUp.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { LoginFormSharedHelpers } from "/client/modules/accounts/helpers";
import { Template } from "meteor/templating";
import { LoginFormValidation } from "/lib/api";

/**
* onCreated: Login form sign up view
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Accounts } from "meteor/accounts-base";
import { Template } from "meteor/templating";
import { i18next } from "/client/api";
import { LoginFormSharedHelpers } from "/client/modules/accounts/helpers";
import { LoginFormValidation } from "/lib/api";

/**
* Accounts Event: onResetPasswordLink When a user uses a password reset link
Expand Down
5 changes: 3 additions & 2 deletions client/modules/i18n/startup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import i18nextLocalStorageCache from "i18next-localstorage-cache";
import i18nextSprintfPostProcessor from "i18next-sprintf-postprocessor";
import i18nextJquery from "jquery-i18next";
import { Meteor } from "meteor/meteor";
import { $ } from "meteor/jquery";
import { Tracker } from "meteor/tracker";
import { Reaction } from "/client/api";
import { Shops, Translations } from "/lib/collections";
Expand Down Expand Up @@ -97,7 +98,7 @@ Meteor.startup(() => {

// global first time init event finds and replaces
// data-i18n attributes in html/template source.
$elements = $("[data-i18n]").localize();
$("[data-i18n]").localize();

// apply language direction to html
if (i18next.dir(language) === "rtl") {
Expand Down Expand Up @@ -144,7 +145,7 @@ Meteor.startup(() => {
this.autorun((function () {
return function () {
i18nextDep.depend();
$elements = $("[data-i18n]").localize();
$("[data-i18n]").localize();
};
})(this));
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { Meteor } from "meteor/meteor";
import Alerts from "./inlineAlerts";

/**
* inlineAlert helpers
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Mongo } from "meteor/mongo";
/*
* Forked and modifed from https://github.com/asktomsk/bootstrap-alerts/
*/
Alerts = {
const Alerts = {

/*
Default options. Can be overridden for application
Expand Down Expand Up @@ -144,4 +144,5 @@ Alerts = {
collection_: new Mongo.Collection(null)
};

window.Alerts = Alerts;
export default Alerts;
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import _ from "lodash";
import { Meteor } from "meteor/meteor";
import swal from "sweetalert2";
import { Meteor } from "meteor/meteor";
import "sweetalert2/dist/sweetalert2.css";
import Alerts from "./inlineAlerts";

// Extends Bootstaps alerts and add more alert types
Meteor.startup(function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`OrderSummary snapshot test 1`] = `
<div>
<div
className="order-summary-form-group bg-info"
style={
Object {
"lineHeight": 3,
"marginLeft": -15,
"marginRight": -15,
"marginTop": -15,
}
}
>
<strong
style={
Object {
"marginLeft": 15,
}
}
/>
,
<div
className="invoice-details"
style={
Object {
"marginRight": 15,
}
}
>
<strong>
ID
</strong>
</div>
</div>
<div
className="roll-up-invoice-list"
>
<div
className="roll-up-content"
>
<div
style={
Object {
"marginBottom": 4,
}
}
>
<span
className="badge badge-undefined"
/>
</div>
<div
className="order-summary-form-group"
>
<strong
data-i18n="order.created"
>
Created
</strong>
<div
className="invoice-details"
/>
</div>
<div
className="order-summary-form-group"
>
<strong
data-i18n="order.processor"
>
Processor
</strong>
<div
className="invoice-details"
/>
</div>
<div
className="order-summary-form-group"
>
<strong
data-i18n="order.payment"
>
Payment
</strong>
<div
className="invoice-details"
>
(
)
</div>
</div>
<div
className="order-summary-form-group"
>
<strong
data-i18n="order.transaction"
>
Transaction
</strong>
<div
className="invoice-details"
/>
</div>
<div
className="order-summary-form-group"
>
<strong
data-i18n="orderShipping.carrier"
>
Carrier
</strong>
<div
className="invoice-details"
>
-
</div>
</div>
<div
className="order-summary-form-group"
>
<strong
data-i18n="orderShipping.tracking"
>
Tracking
</strong>
<div
className="invoice-details"
/>
</div>
<div
className="order-summary-form-group"
>
<strong
data-i18n="orderShipping.printLabels"
>
Labels
</strong>
<a
className="invoice-details"
target="_blank"
>
<span
data-i18n="orderShipping.printCustomsLabel"
>
Print Customs
</span>
</a>
</div>
</div>
</div>
<br />
<div
className="order-summary-form-group"
>
<strong
data-i18n="orderShipping.shipTo"
>
Ship to
</strong>
<div
className="invoice-details"
>
<strong>
Phone:
</strong>
</div>
</div>
<div
style={
Object {
"marginTop": 4,
}
}
>
<span />
<br />
<span />
<br />
<span>
,
,

</span>
</div>
</div>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from "react";
import OrderSummary from "../../components/orderSummary";
import { shallow } from "enzyme";
import shallowToJSON from "enzyme-to-json";

/**
* Order Summary is a display only component
* It receives props and displays them accordingly
*/

afterEach(() => {
jest.clearAllMocks();
});

/**
* Snapshots make sure your UI does not change unexpectedly
*/

test("OrderSummary snapshot test", () => {
// Initializing all the props passed into order summary component
const dateFormat = jest.fn();
const tracking = jest.fn();
const shipmentStatus = jest.fn(()=>({}));
const printableLabels = jest.fn(()=>({}));
const profileShippingAddress = {};
const order = {
shipping: [{ shipmentMethod: {} }],
billing: [
{ paymentMethod: {},
invoice: {}
}
]
};

const component = shallow(
<OrderSummary
dateFormat={dateFormat}
tracking={tracking}
profileShippingAddress={profileShippingAddress}
shipmentStatus={shipmentStatus}
printableLabels={printableLabels}
order={order}
/>
);
const tree = shallowToJSON(component);
expect(tree).toMatchSnapshot();
});
Loading