-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1331 from jkruder/test-framework
Test Framework
- Loading branch information
Showing
8 changed files
with
176 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
node_modules | ||
npm-debug.log | ||
build | ||
coverage | ||
|
||
# Exclude compiled files | ||
lib | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
build | ||
coverage | ||
docs | ||
example | ||
icon-builder | ||
icon-builder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Karma configuration | ||
module.exports = function(config) { | ||
config.set({ | ||
|
||
basePath: '', | ||
|
||
frameworks: [ 'browserify', 'mocha', 'chai-sinon' ], | ||
|
||
files: [ | ||
'node_modules/babel/node_modules/babel-core/browser-polyfill.js', | ||
'test/**/*spec.js' | ||
], | ||
|
||
preprocessors: { | ||
'test/**/*spec.js': [ 'browserify' ] | ||
}, | ||
|
||
browserify: { | ||
debug: true, | ||
extensions: [ '.js', '.jsx' ], | ||
paths: [ './node_modules', './src' ], | ||
transform: [ | ||
['babelify', { | ||
stage: 1, | ||
sourceMap: 'inline' | ||
}], | ||
'browserify-istanbul' | ||
] | ||
}, | ||
|
||
reporters: ['mocha', 'coverage'], | ||
|
||
coverageReporter: { | ||
dir: 'coverage', | ||
|
||
subdir: function(browser) { | ||
return browser.toLowerCase().split(/[ /-]/)[0]; | ||
}, | ||
|
||
reporters: [ | ||
// Uncomment when 'TypeError: Cannot read property 'text' of undefined' has been addressed in Istanbul. | ||
// { type: 'html', subdir: '.' }, | ||
{ type: 'lcovonly', subdir: '.', file: 'lcov.info' }, | ||
{ type: 'text', subdir: '.', file: 'text.txt' }, | ||
{ type: 'text-summary', subdir: '.' } | ||
] | ||
}, | ||
|
||
port: 9876, | ||
colors: true, | ||
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG | ||
logLevel: config.LOG_INFO, | ||
autoWatch: false, | ||
singleRun: false, | ||
browsers: [ 'PhantomJS' ] | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import React from 'react/addons'; | ||
import Checkbox from 'checkbox'; | ||
import injectTheme from './fixtures/inject-theme'; | ||
|
||
const TestUtils = React.addons.TestUtils; | ||
|
||
|
||
describe('Checkbox', () => { | ||
const CHECKMARK_PATH = 'M19 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.11 0 2-.9 2-2V5c0-1.1-.89-2-2-2zm-9 14l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z'; | ||
let ThemedCheckbox; | ||
|
||
|
||
beforeEach(() => { | ||
ThemedCheckbox = injectTheme(Checkbox); | ||
}); | ||
|
||
|
||
it('should display checkmark when checked by default', () => { | ||
let render = TestUtils.renderIntoDocument(<ThemedCheckbox defaultChecked={true} />); | ||
let input = TestUtils.findRenderedDOMComponentWithTag(render, 'input'); | ||
let svgs = TestUtils.scryRenderedDOMComponentsWithTag(render, 'svg'); | ||
let checkMarkNode = svgs[1].getDOMNode(); | ||
|
||
expect(input.getDOMNode().hasAttribute('checked')).to.be.true; | ||
expect(checkMarkNode.style.opacity).to.equal('1'); | ||
expect(checkMarkNode.firstChild.getAttribute('d')).to.equal(CHECKMARK_PATH); | ||
}); | ||
|
||
|
||
it('should NOT display checkmark when not checked by default', () => { | ||
let render = TestUtils.renderIntoDocument(<ThemedCheckbox defaultChecked={false} />); | ||
let input = TestUtils.findRenderedDOMComponentWithTag(render, 'input'); | ||
let svgs = TestUtils.scryRenderedDOMComponentsWithTag(render, 'svg'); | ||
let checkMarkNode = svgs[1].getDOMNode(); | ||
|
||
expect(input.getDOMNode().hasAttribute('checked')).to.be.false; | ||
expect(checkMarkNode.style.opacity).to.equal('0'); | ||
expect(checkMarkNode.firstChild.getAttribute('d')).to.equal(CHECKMARK_PATH); | ||
}); | ||
|
||
|
||
describe('when initially unchecked', () => { | ||
let renderedCheckbox; | ||
|
||
|
||
beforeEach(() => { | ||
renderedCheckbox = TestUtils.renderIntoDocument(<ThemedCheckbox defaultChecked={false} />); | ||
}); | ||
|
||
|
||
it('should display checkmark when clicked once', () => { | ||
let input = TestUtils.findRenderedDOMComponentWithTag(renderedCheckbox, 'input'); | ||
let inputNode = input.getDOMNode(); | ||
inputNode.checked = !inputNode.checked; | ||
TestUtils.Simulate.change(input); | ||
|
||
let svgs = TestUtils.scryRenderedDOMComponentsWithTag(renderedCheckbox, 'svg'); | ||
let checkMarkNode = svgs[1].getDOMNode(); | ||
expect(checkMarkNode.style.opacity).to.equal('1'); | ||
expect(checkMarkNode.firstChild.getAttribute('d')).to.equal(CHECKMARK_PATH); | ||
}); | ||
|
||
|
||
it('should NOT display checkmark when clicked twice', () => { | ||
let input = TestUtils.findRenderedDOMComponentWithTag(renderedCheckbox, 'input'); | ||
let inputNode = input.getDOMNode(); | ||
// Simulate events | ||
inputNode.checked = !inputNode.checked; | ||
TestUtils.Simulate.change(input); | ||
inputNode.checked = !inputNode.checked; | ||
TestUtils.Simulate.change(input); | ||
|
||
let svgs = TestUtils.scryRenderedDOMComponentsWithTag(renderedCheckbox, 'svg'); | ||
let checkMarkNode = svgs[1].getDOMNode(); | ||
expect(checkMarkNode.style.opacity).to.equal('0'); | ||
expect(checkMarkNode.firstChild.getAttribute('d')).to.equal(CHECKMARK_PATH); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import stubContext from 'react-stub-context'; | ||
import ThemeManager from 'styles/theme-manager'; | ||
|
||
const Manager = new ThemeManager(); | ||
|
||
|
||
function injectTheme(Component, theme) { | ||
let injectedTheme = theme || Manager.getCurrentTheme(); | ||
return stubContext(Component, {muiTheme: injectedTheme}); | ||
} | ||
|
||
module.exports = injectTheme; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--require chai | ||
--reporter html | ||
--ui bdd |