forked from react-bootstrap/react-router-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThumbnailLink.spec.js
105 lines (86 loc) · 2.96 KB
/
ThumbnailLink.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
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()();
});
});
});
});
});