Skip to content
This repository has been archived by the owner on Jun 24, 2021. It is now read-only.

Commit

Permalink
Added the first real test
Browse files Browse the repository at this point in the history
  • Loading branch information
eedrummer committed Sep 6, 2016
1 parent ab2afd4 commit 3b0f99c
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 9 deletions.
17 changes: 17 additions & 0 deletions .babelrc
@@ -0,0 +1,17 @@
{
"presets": ["react", "es2015", "stage-1"],
"env": {
"development": {
"plugins": [
[
"react-transform",
{
"transforms": [
{ "transform": "react-transform-hmr", "imports": [ "react" ], "locals": [ "module" ] }
]
}
]
]
}
}
}
1 change: 1 addition & 0 deletions .eslintignore
@@ -1 +1,2 @@
dist/**/*
test/test_helper.js
9 changes: 7 additions & 2 deletions package.json
Expand Up @@ -4,8 +4,7 @@
"description": "Web application to provide an interface for clinical quality measure calculation",
"main": "gulpfile.bable.js",
"scripts": {
"test": "mocha --compilers js:babel-core/register --recursive",
"test:watch": "npm test -- --watch",
"test": "NODE_ENV=test mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test",
"start": "gulp",
"lint": "gulp lint"
},
Expand All @@ -22,12 +21,16 @@
"devDependencies": {
"babel-core": "^6.4.5",
"babel-eslint": "^6.1.2",
"babel-plugin-react-transform": "^2.0.2",
"babel-polyfill": "^6.5.0",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-1": "^6.13.0",
"babelify": "^7.2.0",
"bootstrap-sass": "^3.3.6",
"browserify": "^13.0.0",
"chai": "^3.5.0",
"chai-jquery": "^2.0.0",
"es6-promise": "^3.0.2",
"eslint-plugin-react": "^6.2.0",
"font-awesome": "^4.5.0",
Expand All @@ -41,8 +44,10 @@
"immutable": "^3.7.6",
"isomorphic-fetch": "^2.2.0",
"jquery": "^3.1.0",
"jsdom": "^9.5.0",
"mocha": "^3.0.2",
"react": "^15.3.1",
"react-addons-test-utils": "^15.3.1",
"react-dom": "^15.3.1",
"react-redux": "^4.2.1",
"react-router": "^2.0.0-rc5",
Expand Down
22 changes: 22 additions & 0 deletions test/components/measure_category_test.js
@@ -0,0 +1,22 @@
import { renderComponent, expect } from '../test_helper';
import MeasureCategory from '../../src/components/MeasureCategory';

describe('MeasureCategory', () => {
let component;

beforeEach(() => {
const props = {
category: "Core",
measures: [{cmsId: "123v1", name: "Controlling BP", description: "", hqmfId: "1234", category: "Core"},
{cmsId: "124v1", name: "Controlling Weight", description: "", hqmfId: "5678", category: "Core"}],
onAddMeasure: (measure) => {
expect(measure.hqmfId).to.equal("1234");
}
};
component = renderComponent(MeasureCategory, props);
});

it('will display both measures', () => {
expect(component.find("button").length).to.equal(3); // two measures + select all
});
});
7 changes: 0 additions & 7 deletions test/initTest.js

This file was deleted.

37 changes: 37 additions & 0 deletions test/test_helper.js
@@ -0,0 +1,37 @@
// copied from https://github.com/StephenGrider/ReduxSimpleStarter

import _$ from 'jquery';
import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-addons-test-utils';
import jsdom from 'jsdom';
import chai, { expect } from 'chai';
import chaiJquery from 'chai-jquery';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import reducers from '../src/reducers';

global.document = jsdom.jsdom('<!doctype html><html><body></body></html>');
global.window = global.document.defaultView;
const $ = _$(window);

chaiJquery(chai, chai.util, $);

function renderComponent(ComponentClass, props = {}, state = {}) {
const componentInstance = TestUtils.renderIntoDocument(
<Provider store={createStore(reducers, state)}>
<ComponentClass {...props} />
</Provider>
);

return $(ReactDOM.findDOMNode(componentInstance));
}

$.fn.simulate = function(eventName, value) {
if (value) {
this.val(value);
}
TestUtils.Simulate[eventName](this[0]);
};

export {renderComponent, expect};

0 comments on commit 3b0f99c

Please sign in to comment.