-
Notifications
You must be signed in to change notification settings - Fork 7
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 #24 from vramana/newer-api
[WIP] Refine API
- Loading branch information
Showing
24 changed files
with
266 additions
and
203 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"stage": 0 | ||
} |
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
node_modules | ||
legit-tests.js | ||
dom.js | ||
middleware.js | ||
middleware | ||
no-dom.js | ||
tests.js | ||
lib | ||
/legit-tests.js | ||
/dom.js | ||
/middleware.js | ||
/middleware | ||
/no-dom.js | ||
/tests.js | ||
npm-debug.log |
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
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,7 +1,2 @@ | ||
/* globals global */ | ||
import './dom' | ||
import Test from './tests' | ||
|
||
export default function TestWrapper(component, config){ | ||
return new Test(component, config) | ||
} | ||
export default from './tests' |
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 |
---|---|---|
@@ -1,11 +1,16 @@ | ||
import React from 'react' | ||
let { TestUtils } = React.addons | ||
|
||
export default function simulate(data){ | ||
let element = data.element ? this.helpers.elements[data.element] : this; | ||
element = Array.isArray(element) ? element[0] : element; | ||
export default function simulate(data) { | ||
let element | ||
if (data.element !== undefined ) { | ||
element = Array.isArray(this.elements[data.element]) ? | ||
this.elements[data.element][0] : this.elements[data.element] | ||
} else { | ||
throw new Error(`No element "${data.element}" is in elements`) | ||
} | ||
TestUtils.Simulate[data.method].call(this, | ||
element, | ||
data.options || null | ||
); | ||
) | ||
} |
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,5 +1 @@ | ||
import Test from './tests' | ||
|
||
export default function TestWrapper(component, config){ | ||
return new Test(component, config) | ||
} | ||
export default from './tests' |
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,89 +1,74 @@ | ||
import React from 'react/addons'; | ||
import React from 'react/addons' | ||
let { TestUtils } = React.addons | ||
global.React = React //expose React to tests so they can use jsx syntax when passing in components to the class | ||
require('react/lib/ExecutionEnvironment').canUseDOM = true | ||
|
||
import {Find, SetState, Simulate} from './middleware' | ||
import { Find, SetState, Simulate } from './middleware' | ||
|
||
export default class Test { | ||
function Test(component, config) { | ||
|
||
constructor(component, config){ | ||
this.component = component | ||
|
||
if(config && config.shallow === true){ | ||
let shallowRenderer = TestUtils.createRenderer(); | ||
shallowRenderer.render(component); | ||
this.instance = shallowRenderer.getRenderOutput(); | ||
} | ||
else{ | ||
this.instance = TestUtils.renderIntoDocument(component) | ||
} | ||
|
||
this.helpers = {} | ||
return this | ||
let instance | ||
if (config && config.shallow === true) { | ||
const shallowRenderer = TestUtils.createRenderer() | ||
shallowRenderer.render(component) | ||
instance = shallowRenderer.getRenderOutput() | ||
} else { | ||
instance = TestUtils.renderIntoDocument(component) | ||
} | ||
|
||
use(callback, data){ | ||
callback.call(this, data) | ||
return this | ||
} | ||
|
||
element(select, callback) { | ||
if(!this.helpers) return | ||
|
||
let element | ||
if(typeof select === 'string') { | ||
element = this.helpers.elements[select] | ||
callback.call(this, element) | ||
const testComponent = { | ||
instance, | ||
elements: {}, | ||
element(select, callback) { | ||
let element | ||
if (typeof select === 'string') { | ||
element = this.elements[select] | ||
callback.call(this, element) | ||
return this | ||
} | ||
|
||
if (Array.isArray(select)) { | ||
const args = select.map(elem => this.elements[elem]) | ||
callback.call(this, ...args) | ||
return this | ||
} | ||
|
||
if (Object.keys(this.elements).length === 1) { | ||
select.call(this, this.elements[Object.keys(this.elements)[0]]) | ||
} else { | ||
throw new Error("There are multiple elements select one") | ||
} | ||
return this | ||
}, | ||
use(callback, data) { | ||
callback.call(this, data) | ||
return this | ||
}, | ||
mixin(spec) { | ||
Object.keys(spec).forEach(key => { | ||
this[key] = (...args) => { | ||
spec[key].call(this, ...args) | ||
return this | ||
} | ||
}) | ||
return this | ||
}, | ||
test(callback) { | ||
const param = {...this, ...this.elements} | ||
callback.call(param, param) | ||
return this | ||
}, | ||
renderToString(callback) { | ||
const componentString = React.renderToStaticMarkup(component) | ||
callback.call(null, componentString) | ||
return this | ||
} | ||
|
||
element = this.getFirst(this.helpers.elements) | ||
select.call(this, element) | ||
return this | ||
} | ||
|
||
test(callback) { | ||
var params = this.params() | ||
callback.call(params, params) | ||
return this | ||
} | ||
|
||
params(){ | ||
var length = Object.keys(this.helpers).length | ||
if(this.helpers.elements && length === 1) { | ||
return Object.assign({}, this, this.helpers.elements) | ||
} | ||
return this | ||
} | ||
|
||
//private | ||
|
||
getFirst(object){ | ||
for (let element in object) return object[element] | ||
} | ||
|
||
//Built in middleware | ||
|
||
find(data){ | ||
Find.call(this, data) | ||
return this | ||
} | ||
|
||
setState(data){ | ||
SetState.call(this, data) | ||
return this | ||
} | ||
|
||
simulate(data){ | ||
Simulate.call(this, data) | ||
return this | ||
} | ||
|
||
renderToString(callback){ | ||
var component = React.renderToStaticMarkup(this.component) | ||
callback.call(null, component) | ||
return this | ||
} | ||
|
||
return testComponent.mixin({ | ||
find: Find, | ||
setState: SetState, | ||
simulate: Simulate | ||
}) | ||
} | ||
|
||
export default Test |
This file was deleted.
Oops, something went wrong.
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,29 @@ | ||
import React, { Component } from 'react' | ||
import TinyComponent from './tiny-component' | ||
|
||
export default class TestComponent extends Component { | ||
constructor(props, context){ | ||
super(props, context) | ||
this.state = {} | ||
} | ||
|
||
render(){ | ||
return ( | ||
<body> | ||
<div onClick={this.props.onClick}>{this.state.test}</div> | ||
<p className="box">found me!</p> | ||
<button | ||
type="button" | ||
onClick={this.props.onClick}> | ||
Click Me | ||
</button> | ||
<button | ||
type="button" | ||
onClick={this.props.onClick}> | ||
Click Me | ||
</button> | ||
<TinyComponent test="true"/> | ||
</body> | ||
) | ||
} | ||
} |
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,2 @@ | ||
export TestComponent from './component' | ||
export TinyComponent from './tiny-component' |
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,7 @@ | ||
import React, { Component } from 'react' | ||
|
||
export default class TinyComponent extends Component { | ||
render() { | ||
return <div className="foo"></div> | ||
} | ||
} |
Oops, something went wrong.