-
Notifications
You must be signed in to change notification settings - Fork 158
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
10 changed files
with
152 additions
and
1 deletion.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,20 @@ | ||
import React from 'react'; | ||
|
||
import Thumbnail from 'react-bootstrap/lib/Thumbnail'; | ||
import LinkMixin from './LinkMixin'; | ||
|
||
const ThumbnailLink = React.createClass({ | ||
mixins: [ | ||
LinkMixin | ||
], | ||
|
||
render() { | ||
return ( | ||
<Thumbnail {...this.getLinkProps()} ref='thumbnail'> | ||
{this.props.children} | ||
</Thumbnail> | ||
); | ||
} | ||
}); | ||
|
||
export default ThumbnailLink; |
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,105 @@ | ||
/* globals describe, it, assert, expect */ | ||
|
||
import React from 'react/addons'; | ||
import ThumbnailLink from '../src/ThumbnailLink'; | ||
import Router, { Route } from 'react-router'; | ||
import { Foo } from './TestHandlers'; | ||
import TestLocation from 'react-router/lib/locations/TestLocation'; | ||
let { click } = React.addons.TestUtils.Simulate; | ||
|
||
describe('A ThumbnailLink', function () { | ||
describe('with params and a query', function () { | ||
it('knows how to make its href', function () { | ||
let ThumbnailLinkHandler = React.createClass({ | ||
render() { | ||
return <ThumbnailLink to="foo" params={{bar: 'baz'}} query={{qux: 'quux'}} />; | ||
} | ||
}); | ||
|
||
let routes = [ | ||
<Route name="foo" path="foo/:bar" handler={Foo} />, | ||
<Route name="link" handler={ThumbnailLinkHandler} /> | ||
]; | ||
|
||
let div = document.createElement('div'); | ||
let testLocation = new TestLocation(); | ||
testLocation.history = ['/link']; | ||
|
||
Router.run(routes, testLocation, function (Handler) { | ||
React.render(<Handler/>, div, function () { | ||
let a = div.querySelector('a'); | ||
expect(a.getAttribute('href')).to.equal('/foo/baz?qux=quux'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when clicked', function () { | ||
it('calls a user defined click handler', function (done) { | ||
let ThumbnailLinkHandler = React.createClass({ | ||
handleClick(event) { | ||
assert.ok(true); | ||
done(); | ||
}, | ||
|
||
render() { | ||
return <ThumbnailLink to="foo" onClick={this.handleClick} />; | ||
} | ||
}); | ||
|
||
let routes = [ | ||
<Route name="foo" handler={Foo} />, | ||
<Route name="link" handler={ThumbnailLinkHandler} /> | ||
]; | ||
let div = document.createElement('div'); | ||
let testLocation = new TestLocation(); | ||
testLocation.history = ['/link']; | ||
|
||
Router.run(routes, testLocation, function (Handler) { | ||
React.render(<Handler/>, div, function () { | ||
click(div.querySelector('a')); | ||
}); | ||
}); | ||
}); | ||
|
||
it('transitions to the correct route', function (done) { | ||
let div = document.createElement('div'); | ||
let testLocation = new TestLocation(); | ||
testLocation.history = ['/link']; | ||
|
||
let ThumbnailLinkHandler = React.createClass({ | ||
handleClick() { | ||
// just here to make sure click handlers don't prevent it from happening | ||
}, | ||
|
||
render() { | ||
return <ThumbnailLink to="foo" onClick={this.handleClick} />; | ||
} | ||
}); | ||
|
||
let routes = [ | ||
<Route name="foo" handler={Foo} />, | ||
<Route name="link" handler={ThumbnailLinkHandler} /> | ||
]; | ||
|
||
let steps = []; | ||
|
||
steps.push(function () { | ||
click(div.querySelector('a'), {button: 0}); | ||
}); | ||
|
||
steps.push(function () { | ||
expect(div.innerHTML).to.match(/Foo/); | ||
done(); | ||
}); | ||
|
||
Router.run(routes, testLocation, function (Handler) { | ||
React.render(<Handler/>, div, function () { | ||
steps.shift()(); | ||
}); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
}); |
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,21 @@ | ||
import React from 'react'; | ||
import {Link} from 'react-router'; | ||
import Thumbnail from 'react-bootstrap/lib/Thumbnail'; | ||
import ThumbnailLink from '../../src/ThumbnailLink'; | ||
|
||
const ThumbnailVisual = React.createClass({ | ||
render() { | ||
return ( | ||
<div> | ||
<Link to='home'><-- Back to Index</Link> | ||
<h2>Thumbnailink</h2> | ||
<h3>Baseline (Raw React-Bootstrap)</h3> | ||
<Thumbnail alt='171x180' src='/assets/thumbnail.png' /> | ||
<h3>ThumbnailLink</h3> | ||
<ThumbnailLink to='home' alt='171x180' src='/assets/thumbnail.png' /> | ||
</div> | ||
); | ||
} | ||
}); | ||
|
||
export default ThumbnailVisual; |
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