Skip to content

Commit

Permalink
OWA-13 added testing setup and basic test example for React OWA
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamGrzybkowski committed Jan 20, 2017
1 parent 932db18 commit a23649d
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 1 deletion.
13 changes: 13 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,15 @@ module.exports = generators.Base.extend({
);
},

babelrc: function() {
if (this.includeReact) {
this.fs.copyTpl(
this.templatePath('babelrc'),
this.destinationPath('.babelrc')
);
}
},

scripts: function() {
// AngularJS
if (this.includeAngular) {
Expand Down Expand Up @@ -296,6 +305,10 @@ module.exports = generators.Base.extend({
this.templatePath('scripts/react/components/App.jsx'),
this.destinationPath('app/js/components/App.jsx')
);
this.fs.copyTpl(
this.templatePath('scripts/react/test'),
this.destinationPath('app/test')
);

if (this.includeRedux) {
this.fs.copyTpl(
Expand Down
13 changes: 12 additions & 1 deletion app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@
"redux-promise-middleware": "^4.2.0",
"redux-thunk": "^2.1.0",
<% } %>
"react-router": "^3.0.0"
"react-router": "^3.0.0",
"sinon": "^1.17.7",
"chai": "^3.5.0",
"enzyme": "^2.7.0",
"jsdom": "^9.9.1",
"react-addons-test-utils": "^15.4.2",
"mocha": "^3.2.0"
<% } %>
},
"devDependencies": {
Expand Down Expand Up @@ -61,7 +67,12 @@
"build:prod": "npm run test && npm run build",
"build:deploy": "webpack --progress --colors --mode=deploy --target=web",
"watch": "webpack --progress --colors --watch --mode=deploy --target=web",
<% if(includeReact === true) { %>
"test": "mocha app/test/helpers/browser.js app/test/*.spec.js",
"test:watch": "npm run test -- -w"
<% } else { %>
"test": "echo \"Error: no test specified\""
<% } %>
},
"keywords": [
"OpenMRS",
Expand Down
3 changes: 3 additions & 0 deletions app/templates/babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["react", "es2015"]
}
23 changes: 23 additions & 0 deletions app/templates/scripts/react/test/App.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* The contents of this file are subject to the OpenMRS Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http:https://license.openmrs.org
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
* Copyright (C) OpenMRS, LLC. All Rights Reserved.
*/
import React from 'react';
import { mount, shallow } from 'enzyme';
import {expect} from 'chai';

import App from '../js/components/App';

describe('<App/>', function () {
it('should say Hello!', function () {
const wrapper = shallow(<App/>);
expect(wrapper.find('h1')).to.have.length(1);
});
});
31 changes: 31 additions & 0 deletions app/templates/scripts/react/test/helpers/browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* The contents of this file are subject to the OpenMRS Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http:https://license.openmrs.org
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
* Copyright (C) OpenMRS, LLC. All Rights Reserved.
*/
require('babel-register')();

var jsdom = require('jsdom').jsdom;

var exposedProperties = ['window', 'navigator', 'document'];

global.document = jsdom('');
global.window = document.defaultView;
Object.keys(document.defaultView).forEach((property) => {
if (typeof global[property] === 'undefined') {
exposedProperties.push(property);
global[property] = document.defaultView[property];
}
});

global.navigator = {
userAgent: 'node.js'
};

documentRef = document;

0 comments on commit a23649d

Please sign in to comment.