Fakultas Ilmu Komputer UI

Commit 736580be authored by M. Reza Qorib's avatar M. Reza Qorib
Browse files

[#140382397] #3 fix karma testing for ES6

parent f7534d55
var testsContext = require.context("../../assets/js/__test__", false);
var runnable = testsContext.keys();
runnable.forEach(testsContext);
\ No newline at end of file
/**
* Created by M. Reza Qorib on 3/23/2017.
*/
import React from 'react';
// import expect from 'expect';
import ReactDOM from 'react-dom';
import ReactTestUtils from 'react-addons-test-utils';
import FormLogin from '../components/FormLogin';
import 'babel-polyfill';
describe('FormLogin', () => {
it('created without problem', () => {
const formLogin = new FormLogin({ url: 'tes' });
expect(formLogin).to.be.an.instanceof(FormLogin);
});
it('renders without problem', () => {
const formLogin = ReactTestUtils.renderIntoDocument(
<FormLogin url="" />);
expect(formLogin).to.exist;
const formDiv = ReactTestUtils.findRenderedDOMComponentWithClass(
formLogin, 'formLogin');
expect(formDiv).to.exist;
const form = ReactTestUtils.findRenderedDOMComponentWithTag(
formLogin, 'form');
expect(form).to.exist;
});
it('handle email input without problem', () => {
const formLogin = ReactTestUtils.renderIntoDocument(
<FormLogin url="" />);
expect(formLogin.state.email).to.equal('');
const emailNode = ReactTestUtils.scryRenderedDOMComponentsWithTag(formLogin, 'Input')[0];
// const emailNode = ReactDOM.findDOMNode(formLogin.refs.email);
const email = 'jojon';
emailNode.value = email;
ReactTestUtils.Simulate.change(emailNode, { target: { value: email } });
expect(emailNode.value).to.equal(email);
expect(formLogin.state.email).to.equal(email);
});
it('submit form without problem', () => {
const formLogin = ReactTestUtils.renderIntoDocument(
<FormLogin url="" />);
const passwordNode = ReactTestUtils.scryRenderedDOMComponentsWithTag(formLogin, 'Input')[1];
// const passwordNode = ReactDOM.findDOMNode(formLogin.refs.password);
const password = 'passwd';
passwordNode.value = password;
expect(formLogin.state.password).to.equal('');
ReactTestUtils.Simulate.change(passwordNode, { target: { value: password } });
expect(passwordNode.value).to.equal(password);
expect(formLogin.state.password).to.equal(password);
});
it('handle password input without problem', () => {
const formLogin = ReactTestUtils.renderIntoDocument(
<FormLogin url="" />);
const submitButton = ReactDOM.findDOMNode(formLogin.refs.submit);
ReactTestUtils.Simulate.click(submitButton);
const form = ReactTestUtils.findRenderedDOMComponentWithTag(formLogin, 'Form');
ReactTestUtils.Simulate.submit(form);
});
});
// import React from 'react';
// import expect from 'expect'; //kebutuhan dasar
// import Server from "../lib/server";
// import Logger from "../lib/logger";
//
// describe('server', function () {
// it('check logged in or not', function () {
// let logged = Server.isLoggedIn();
// expect(logged).toEqual(null);
// document.cookie = "sessionid=John Smith; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/";
// Logger.log(document.cookie);
// logged = Server.isLoggedIn();
// // expect(logged).toEqual("John Smith");
// });
// });
\ No newline at end of file
import React from 'react';
import { Form, Input, Button, Image } from 'semantic-ui-react';
import Server from '../lib/server';
export default class FormLogin extends React.Component {
static propTypes = {
url: React.PropTypes.string.isRequired,
imgSrc: React.PropTypes.string,
imgSize: React.PropTypes.string,
};
static defaultProps = {
imgSrc: '',
imgSize: 'small',
};
constructor(props) {
super(props);
/* istanbul ignore next */
this.state = { email: '', password: '' };
// this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(name, event) {
this.setState({ [name]: event.target.value });
}
handleSubmit() {
Server.post(this.props.url, this.state);
}
render = () => (
<div className="formLogin" >
<Image src="/assets/img/logo.png" size="small" verticalAlign="middle" /> <span>Company Login</span>
<Image src={`./assets/img/${this.props.imgSrc}`} size={this.props.imgSize} verticalAlign="middle" /> <span>Company Login</span>
<Form>
<Form onSubmit={this.handleSubmit}>
<Form.Group widths="equal">
<Form.Field>
<label htmlFor="id"> Email </label>
<Input id="email" icon="user" iconPosition="left" placeholder="email" />
<Input ref="email" type="text" id="email" icon="user" iconPosition="left" placeholder="email" onChange={this.handleChange.bind(this, 'email')} />
</Form.Field>
</Form.Group>
<Form.Group widths="equal">
<Form.Field>
<label htmlFor="password"> Password </label>
<Input id="password" icon="key" iconPosition="left" placeholder="password" />
<Input ref="password" type="password" id="password" icon="key" iconPosition="left" placeholder="password" onChange={this.handleChange.bind(this, 'password')} />
</Form.Field>
</Form.Group>
<Button fluid color="blue">Login</Button>
<Button ref="submit" type="submit" fluid color="blue">Login</Button>
</Form>
</div>
......
......@@ -11,17 +11,17 @@ module.exports = function (config) {
}
},
singleRun: true, //just run once by default
frameworks: [ 'mocha' ], //use the mocha test framework
frameworks: [ 'mocha', 'chai' ], //use the mocha test framework
files: [
'tests.webpack.js' //just load this file
],
plugins: [ 'karma-chrome-launcher', 'karma-mocha',
'karma-sourcemap-loader', 'karma-webpack', 'karma-coverage'
plugins: [ 'karma-chrome-launcher', 'karma-mocha', 'karma-chai-plugins',
'karma-sourcemap-loader', 'karma-webpack', 'karma-mocha-reporter', 'karma-coverage-istanbul-reporter'
],
preprocessors: {
'tests.webpack.js': [ 'webpack', 'sourcemap' ] //preprocess with webpack and our sourcemap loader
'tests.webpack.js': [ 'webpack', 'sourcemap'] //preprocess with webpack and our sourcemap loader
},
reporters: [ 'dots', 'coverage' ], //report results in this format
reporters: [ 'dots', 'mocha', 'coverage-istanbul' ], //report results in this format
webpack: webpackConfig,
webpackServer: {
noInfo: true //please don't spam the console when running in karma!
......@@ -30,6 +30,27 @@ module.exports = function (config) {
type: 'html', //produces a html document after code is run
dir: 'test/frontend', //path to created html doc
subdir: '.'
}
},
coverageIstanbulReporter: {
// reports can be any that are listed here: https://github.com/istanbuljs/istanbul-reports/tree/590e6b0089f67b723a1fdf57bc7ccc080ff189d7/lib
reports: ['html', 'lcovonly', 'text-summary'],
// base output directory. If you include %browser% in the path it will be replaced with the karma browser name
dir: 'test/frontend', //path to created html doc
// if using webpack and pre-loaders, work around webpack breaking the source path
fixWebpackSourcePaths: true,
// Most reporters accept additional config options. You can pass these through the `report-config` option
'report-config': {
// all options available at: https://github.com/istanbuljs/istanbul-reports/blob/590e6b0089f67b723a1fdf57bc7ccc080ff189d7/lib/html/index.js#L135-L137
html: {
// outputs the report in ./coverage/html
subdir: 'html'
}
}
}
});
};
\ No newline at end of file
}
\ No newline at end of file
......@@ -13,11 +13,16 @@
"author": "",
"license": "ISC",
"devDependencies": {
"babel": "^6.5.2",
"babel-eslint": "^7.2.0",
"babel-loader": "^6.2.5",
"babel-preset-es2015": "^6.22.0",
"babel-preset-stage-1": "^6.16.0",
"babel-cli": "^6.24.0",
"babel-eslint": "^7.2.1",
"babel-istanbul-instrumenter-loader": "^1.0.1",
"babel-loader": "^6.4.1",
"babel-polyfill": "^6.23.0",
"babel-preset-es2015": "^6.24.0",
"babel-preset-latest": "^6.24.0",
"babel-preset-react": "^6.23.0",
"babel-preset-stage-1": "^6.22.0",
"babel-register": "^6.24.0",
"compression-webpack-plugin": "^0.3.2",
"eslint": "^3.18.0",
"eslint-config-airbnb": "^14.1.0",
......@@ -25,18 +30,20 @@
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "^6.10.3",
"eslint-watch": "^3.0.1",
"expect": "^1.20.2",
"expect.js": "^0.3.1",
"isparta": "^4.0.0",
"isparta-loader": "^2.0.0",
"istanbul-instrumenter-loader": "^2.0.0",
"karma": "^1.5.0",
"karma-chai-plugins": "^0.8.0",
"karma-chrome-launcher": "^2.0.0",
"karma-coverage": "^1.1.1",
"karma-coverage-istanbul-reporter": "^1.0.0",
"karma-firefox-launcher": "^1.0.1",
"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.3",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^2.0.2",
"karma-webpack": "^2.0.3",
"mocha": "^3.2.0",
"react-addons-test-utils": "^15.4.2",
"react-hot-loader": "^3.0.0-beta.5",
"react-test-utils": "0.0.1",
"webpack": "^1.13.2",
......@@ -44,13 +51,14 @@
"webpack-dev-server": "^1.16.2"
},
"dependencies": {
"react": "^15.4.0",
"axios": "^0.14.0",
"babel-core": "^6.17.0",
"axios": "^0.15.3",
"babel-core": "^6.24.0",
"babel-preset-react": "^6.16.0",
"react-dom": "^15.4.1",
"react": "^15.4.2",
"react-addons-test-utils": "^15.4.2",
"react-dom": "^15.4.2",
"react-router": "^3.0.2",
"react-tap-event-plugin": "^2.0.1",
"semantic-ui-react": "^0.65.0"
"semantic-ui-react": "^0.67.2"
}
}
var context = require.context('./assets/js', true, /-test\.js/); //make sure you have your directory and regex test set correctly!
var context = require.context('./assets/js/', true, /-test\.jsx?/); //make sure you have your directory and regex test set correctly!
context.keys().forEach(context);
\ No newline at end of file
......@@ -29,9 +29,14 @@ module.exports = {
},
],
postLoaders: [{
test: /\.js$/,
exclude: /(test|node_modules|bower_components)\//,
loader: 'istanbul-instrumenter' }],
test: /\.jsx?$/,
include: path.resolve('assets/js/'),
exclude: [
path.resolve('node_modules/'),
path.resolve('assets/js/__test__/'),
path.resolve('assets/js/lib/'),
],
loader: 'istanbul-instrumenter-loader' }],
},
resolve: {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment