-
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.
- Loading branch information
Showing
30 changed files
with
151 additions
and
562 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,3 +1,6 @@ | ||
{ | ||
"stage": 0 | ||
"presets": [ | ||
"react", | ||
"es2015" | ||
] | ||
} |
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,4 @@ | ||
--full-trace | ||
--compilers js:babel/register | ||
--compilers js:babel-register | ||
--harmony-proxies | ||
--recursive ./tests/**/*.jsx | ||
--recursive ./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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,23 @@ | ||
|
||
import React from 'react'; | ||
|
||
/** | ||
* Traverses the tree and returns all components that satisfy the function `test`. | ||
* | ||
* @param {ReactComponent} tree the tree to traverse | ||
* @param {Function} test the test for each component | ||
* @return {Array} the components that satisfied `test` | ||
*/ | ||
export default function findAll(tree, test) { | ||
let found = test(tree) ? [tree] : []; | ||
|
||
if (React.isValidElement(tree)) { | ||
if (React.Children.count(tree.props.children) > 0) { | ||
React.Children.forEach(tree.props.children, (child) => { | ||
found = found.concat(findAll(child, test)); | ||
}); | ||
} | ||
} | ||
|
||
return found; | ||
} |
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,2 +1,56 @@ | ||
import './dom' | ||
export default from './tests' | ||
import TestUtils from 'react-addons-test-utils' | ||
import React from 'react' | ||
import findAll from './find-all' | ||
|
||
export default (component) => { | ||
let items, selectedIndex | ||
|
||
const shallowRenderer = TestUtils.createRenderer() | ||
shallowRenderer.render(component) | ||
const instance = shallowRenderer.getRenderOutput(); | ||
|
||
const find = (term, child) => { | ||
const selector = term.charAt(0) | ||
switch (selector) { | ||
case '.': | ||
items = findAll(instance, child => child.props ? child.props.className == term.slice(1) : false) | ||
return proxy | ||
case '#': | ||
items = findAll(instance, child => child.props ? child.props.id == term.slice(1) : false) | ||
return proxy | ||
default: | ||
return proxy | ||
} | ||
} | ||
|
||
const first = () => { | ||
selectedIndex = 0 | ||
return proxy | ||
} | ||
|
||
const last = () => { | ||
selectedIndex = items.length - 1 | ||
return proxy | ||
} | ||
|
||
const get = (index) => { | ||
selectedIndex = index | ||
return proxy | ||
} | ||
|
||
const utils = { | ||
props: instance.props, | ||
find, | ||
first, | ||
last, | ||
get | ||
} | ||
|
||
const proxy = Proxy.create({ | ||
get: (proxy, name) => { | ||
if(utils[name]) return value => utils[name](value) | ||
return items[selectedIndex || 0].props[name] | ||
} | ||
}) | ||
return proxy | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.