forked from remix-run/react-router
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScrollManagementMixin-test.js
More file actions
73 lines (61 loc) · 2.05 KB
/
ScrollManagementMixin-test.js
File metadata and controls
73 lines (61 loc) · 2.05 KB
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
import expect from 'expect';
import React from 'react';
import createHistory from 'history/lib/createHashHistory';
import resetHash from './resetHash';
import execStepsWithDelay from './execStepsWithDelay';
import { getWindowScrollPosition } from '../DOMUtils';
import Router from '../Router';
import Route from '../Route';
describe.skip('ScrollManagementMixin', function () {
var Home = React.createClass({
render() {
return <p style={{ padding: '100px 5000px 5000px 100px' }}>Yo, this page is huge.</p>;
}
});
var Inbox = React.createClass({
render() {
return <p style={{ padding: '100px 5000px 5000px 100px' }}>Yo, this page is huge.</p>;
}
});
beforeEach(resetHash);
var node;
beforeEach(function (done) {
node = document.createElement('div');
document.body.appendChild(node);
});
afterEach(function () {
React.unmountComponentAtNode(node);
document.body.removeChild(node);
});
it('correctly updates the window scroll position', function (done) {
var steps = [
function () {
expect(this.state.location.pathname).toEqual('/');
window.scrollTo(200, 200);
expect(getWindowScrollPosition()).toEqual({ x: 200, y: 200 });
this.transitionTo('/inbox');
},
function () {
expect(this.state.location.pathname).toEqual('/inbox');
expect(getWindowScrollPosition()).toEqual({ x: 0, y: 0 });
this.goBack();
},
function () {
expect(this.state.location.pathname).toEqual('/');
expect(getWindowScrollPosition()).toEqual({ x: 200, y: 200 });
}
];
var execNextStep = execStepsWithDelay(steps, 10, done);
// Needs scroll support in the history module
// See https://github.com/rackt/history/issues/17
var history = createHistory({
getScrollPosition: getWindowScrollPosition
});
React.render((
<Router history={history} onUpdate={execNextStep}>
<Route path="/" component={Home}/>
<Route path="/inbox" component={Inbox}/>
</Router>
), node, execNextStep);
});
});