Skip to content

Commit 6b27ab0

Browse files
author
Jan Stümmel
committed
feat(testing): added a bunch of tests
related to instructure-react#65
1 parent c01162f commit 6b27ab0

File tree

9 files changed

+234
-17
lines changed

9 files changed

+234
-17
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": [ "react", "es2015" ]
3+
}

karma.conf.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
module.exports = function(config) {
2+
config.set({
3+
4+
basePath: '',
5+
6+
frameworks: [
7+
'mocha',
8+
'browserify',
9+
'chai'
10+
],
11+
12+
files: [
13+
14+
// tinymce
15+
'node_modules/tinymce/tinymce.min.js',
16+
'node_modules/tinymce/plugins/**/*.min.js',
17+
'node_modules/tinymce/themes/**/*.min.js',
18+
{ pattern: 'node_modules/tinymce/skins/**', watched: false, included: false },
19+
20+
// tests
21+
'test/**/*Spec.js',
22+
],
23+
24+
exclude: [
25+
],
26+
27+
preprocessors: {
28+
'test/**/*Spec.js': [ 'browserify' ]
29+
},
30+
31+
reporters: ['spec'],
32+
33+
port: 9876,
34+
35+
colors: true,
36+
37+
logLevel: config.LOG_INFO,
38+
39+
autoWatch: true,
40+
41+
browsers: ['PhantomJS'],
42+
43+
singleRun: false,
44+
45+
concurrency: Infinity,
46+
47+
// browserify configuration
48+
browserify: {
49+
debug: true,
50+
transform: [ [ 'babelify' ] ]
51+
}
52+
})
53+
}

lib/components/__tests__/TinyMCE-test.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

package.json

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"description": "React TinyMCE component",
55
"main": "lib/main.js",
66
"scripts": {
7-
"test": "node_modules/.bin/rackt test --single-run --browsers Firefox",
8-
"start": "node_modules/.bin/rackt server"
7+
"test": "karma start --single-run",
8+
"test-watch": "karma start"
99
},
1010
"repository": {
1111
"type": "git",
@@ -23,11 +23,31 @@
2323
"react-dom": "^0.14.0 || ^15.0.0"
2424
},
2525
"devDependencies": {
26+
"babel-preset-es2015": "^6.24.1",
27+
"babel-preset-react": "^6.24.1",
28+
"babelify": "^7.3.0",
29+
"browserify": "^14.4.0",
30+
"chai": "^4.0.2",
31+
"domify": "^1.4.0",
32+
"karma": "^1.7.0",
33+
"karma-browserify": "^5.1.1",
34+
"karma-chai": "^0.1.0",
35+
"karma-chrome-launcher": "^2.1.1",
36+
"karma-firefox-launcher": "^1.0.1",
37+
"karma-mocha": "^1.3.0",
38+
"karma-phantomjs-launcher": "^1.0.4",
39+
"karma-spec-reporter": "0.0.31",
40+
"mocha": "^3.4.2",
41+
"mocha-test-container-support": "^0.2.0",
2642
"rackt-cli": "^0.5.3",
27-
"react": "^15.0.0",
28-
"react-dom": "^15.0.0"
43+
"react": "^15.6.0",
44+
"react-dom": "^15.6.0",
45+
"sinon": "^2.3.4",
46+
"tinymce": "^4.6.4",
47+
"watchify": "^3.9.0"
2948
},
3049
"dependencies": {
31-
"lodash": "^3.9.3"
50+
"lodash": "^3.9.3",
51+
"prop-types": "^15.5.10"
3252
}
33-
}
53+
}

test/TinyMCESpec.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
3+
4+
import domify from 'domify';
5+
import TestContainer from 'mocha-test-container-support';
6+
7+
import TinyMCE from '../';
8+
9+
describe('TinyMCE component tests', () => {
10+
11+
var testContainer;
12+
13+
beforeEach( function () {
14+
testContainer = TestContainer.get(this);
15+
});
16+
17+
18+
it('should render TinyMCE Component', () => {
19+
20+
ReactDOM.render(<TinyMCE config={{}} />, testContainer);
21+
});
22+
23+
24+
it('should render TinyMCE Component inline', () => {
25+
26+
var div = document.createElement('div');
27+
testContainer.appendChild(div);
28+
29+
ReactDOM.render(
30+
<TinyMCE config={{ inline: true }} content="<strong>Hello World</strong>"/>,
31+
div
32+
);
33+
});
34+
35+
36+
});

test/basicSpec.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const domify = require('domify');
2+
const TestContainer = require('mocha-test-container-support');
3+
4+
describe('basic test with global tinymce', () => {
5+
6+
var testContainer;
7+
8+
beforeEach( function () {
9+
testContainer = TestContainer.get(this);
10+
});
11+
12+
13+
it('should be defined', () => {
14+
15+
// when
16+
var tm = global.tinymce
17+
18+
// then
19+
expect(tm).to.be.not.undefined
20+
});
21+
22+
23+
it('should tinymceify textarea', () => {
24+
25+
// given
26+
testContainer.appendChild(document.createElement('textarea'));
27+
28+
// when
29+
tinymce.init({ selector: 'textarea' });
30+
31+
// then
32+
expect(testContainer.childNodes[0].className).to.include('mce-tinymce');
33+
});
34+
35+
36+
it('should tinymceify textarea inline', () => {
37+
38+
// given
39+
const div = domify('<div id="inline">Hello World</div>')
40+
testContainer.appendChild(div);
41+
42+
// when
43+
tinymce.init({ selector: '#inline', inline: true });
44+
45+
// then
46+
expect(div.contentEditable).to.equal('true');
47+
expect(div.innerHTML).to.equal('<p>Hello World</p>');
48+
});
49+
50+
});

test/fixtures/badCreateClass.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const React = require('react');
2+
var test = React.createClass({
3+
render: function(){ return null; }
4+
});
5+
module.exports = Test;

test/fixtures/badPropTypes.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const React = require('react');
2+
class Test extends React.Component {
3+
render() { return null; }
4+
}
5+
Test.propTypes = { foo: React.PropTypes.string };
6+
module.exports = Test;

test/reactWarningSpec.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
describe('createClass/PropTypes Error', () => {
3+
4+
var warn;
5+
6+
before(() => {
7+
// let console.warn throw an error
8+
warn = console.warn;
9+
console.warn = (msg) => { throw new Error(msg);
10+
}});
11+
12+
after(() => console.warn = warn);
13+
14+
15+
it('should throw PropTypes Warning', () => {
16+
17+
expect(() => {
18+
19+
// when
20+
var BadPropTypesTest = require('./fixtures/badPropTypes');
21+
})
22+
23+
// then
24+
.to.throw(/^Warning: Accessing PropTypes via the main React/);
25+
26+
});
27+
28+
29+
it('should throw createClass Warning', () => {
30+
31+
expect(() => {
32+
33+
// when
34+
var BadPropTypesTest = require('./fixtures/badCreateClass');
35+
})
36+
37+
// then
38+
.to.throw(/^Warning: Accessing createClass via the main React/);
39+
40+
});
41+
42+
43+
it('should should not throw creatClass or PropTypes Warning', () => {
44+
45+
expect(() => {
46+
47+
// when
48+
var TinyMCE = require('../')
49+
})
50+
51+
// then
52+
.to.not.throw();
53+
});
54+
55+
});

0 commit comments

Comments
 (0)