Merge pull request #429 from matrix-org/rav/timelinepanel_test
Update annoying TimelinePanel test
This commit is contained in:
commit
c1db6fb42d
2 changed files with 50 additions and 12 deletions
|
@ -31,7 +31,6 @@ var KeyCode = require('../../KeyCode');
|
||||||
|
|
||||||
var PAGINATE_SIZE = 20;
|
var PAGINATE_SIZE = 20;
|
||||||
var INITIAL_SIZE = 20;
|
var INITIAL_SIZE = 20;
|
||||||
var TIMELINE_CAP = 250; // the most events to show in a timeline
|
|
||||||
|
|
||||||
var DEBUG = false;
|
var DEBUG = false;
|
||||||
|
|
||||||
|
@ -82,6 +81,9 @@ var TimelinePanel = React.createClass({
|
||||||
|
|
||||||
// opacity for dynamic UI fading effects
|
// opacity for dynamic UI fading effects
|
||||||
opacity: React.PropTypes.number,
|
opacity: React.PropTypes.number,
|
||||||
|
|
||||||
|
// maximum number of events to show in a timeline
|
||||||
|
timelineCap: React.PropTypes.number,
|
||||||
},
|
},
|
||||||
|
|
||||||
statics: {
|
statics: {
|
||||||
|
@ -92,6 +94,12 @@ var TimelinePanel = React.createClass({
|
||||||
roomReadMarkerTsMap: {},
|
roomReadMarkerTsMap: {},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getDefaultProps: function() {
|
||||||
|
return {
|
||||||
|
timelineCap: 250,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
var initialReadMarker =
|
var initialReadMarker =
|
||||||
TimelinePanel.roomReadMarkerMap[this.props.room.roomId]
|
TimelinePanel.roomReadMarkerMap[this.props.room.roomId]
|
||||||
|
@ -684,7 +692,7 @@ var TimelinePanel = React.createClass({
|
||||||
_loadTimeline: function(eventId, pixelOffset, offsetBase) {
|
_loadTimeline: function(eventId, pixelOffset, offsetBase) {
|
||||||
this._timelineWindow = new Matrix.TimelineWindow(
|
this._timelineWindow = new Matrix.TimelineWindow(
|
||||||
MatrixClientPeg.get(), this.props.room,
|
MatrixClientPeg.get(), this.props.room,
|
||||||
{windowLimit: TIMELINE_CAP});
|
{windowLimit: this.props.timelineCap});
|
||||||
|
|
||||||
var onLoaded = () => {
|
var onLoaded = () => {
|
||||||
this._reloadEvents();
|
this._reloadEvents();
|
||||||
|
|
|
@ -40,11 +40,12 @@ describe('TimelinePanel', function() {
|
||||||
var timeline;
|
var timeline;
|
||||||
var parentDiv;
|
var parentDiv;
|
||||||
|
|
||||||
function mkMessage() {
|
function mkMessage(opts) {
|
||||||
return test_utils.mkMessage(
|
return test_utils.mkMessage(
|
||||||
{
|
{
|
||||||
event: true, room: ROOM_ID, user: USER_ID,
|
event: true, room: ROOM_ID, user: USER_ID,
|
||||||
ts: Date.now(),
|
ts: Date.now(),
|
||||||
|
... opts,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,10 +208,11 @@ describe('TimelinePanel', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should let you scroll down again after you've scrolled up", function(done) {
|
it("should let you scroll down again after you've scrolled up", function(done) {
|
||||||
var N_EVENTS = 600;
|
var TIMELINE_CAP = 100; // needs to be more than we can fit in the div
|
||||||
|
var N_EVENTS = 120; // needs to be more than TIMELINE_CAP
|
||||||
|
|
||||||
// sadly, loading all those events takes a while
|
// sadly, loading all those events takes a while
|
||||||
this.timeout(N_EVENTS * 30);
|
this.timeout(N_EVENTS * 50);
|
||||||
|
|
||||||
// client.getRoom is called a /lot/ in this test, so replace
|
// client.getRoom is called a /lot/ in this test, so replace
|
||||||
// sinon's spy with a fast noop.
|
// sinon's spy with a fast noop.
|
||||||
|
@ -218,13 +220,15 @@ describe('TimelinePanel', function() {
|
||||||
|
|
||||||
// fill the timeline with lots of events
|
// fill the timeline with lots of events
|
||||||
for (var i = 0; i < N_EVENTS; i++) {
|
for (var i = 0; i < N_EVENTS; i++) {
|
||||||
timeline.addEvent(mkMessage());
|
timeline.addEvent(mkMessage({msg: "Event "+i}));
|
||||||
}
|
}
|
||||||
console.log("added events to timeline");
|
console.log("added events to timeline");
|
||||||
|
|
||||||
var scrollDefer;
|
var scrollDefer;
|
||||||
var panel = ReactDOM.render(
|
var panel = ReactDOM.render(
|
||||||
<TimelinePanel room={room} onScroll={() => {scrollDefer.resolve()}} />,
|
<TimelinePanel room={room} onScroll={() => {scrollDefer.resolve()}}
|
||||||
|
timelineCap={TIMELINE_CAP}
|
||||||
|
/>,
|
||||||
parentDiv
|
parentDiv
|
||||||
);
|
);
|
||||||
console.log("TimelinePanel rendered");
|
console.log("TimelinePanel rendered");
|
||||||
|
@ -256,14 +260,18 @@ describe('TimelinePanel', function() {
|
||||||
console.log("back paginating...");
|
console.log("back paginating...");
|
||||||
setScrollTop(0);
|
setScrollTop(0);
|
||||||
return awaitScroll().then(() => {
|
return awaitScroll().then(() => {
|
||||||
|
let eventTiles = scryEventTiles(panel);
|
||||||
|
let firstEvent = eventTiles[0].props.mxEvent;
|
||||||
|
|
||||||
|
console.log("TimelinePanel contains " + eventTiles.length +
|
||||||
|
" events; first is " +
|
||||||
|
firstEvent.getContent().body);
|
||||||
|
|
||||||
if(scrollingDiv.scrollTop > 0) {
|
if(scrollingDiv.scrollTop > 0) {
|
||||||
// need to go further
|
// need to go further
|
||||||
return backPaginate();
|
return backPaginate();
|
||||||
}
|
}
|
||||||
console.log("paginated to start.");
|
console.log("paginated to start.");
|
||||||
|
|
||||||
// hopefully, we got to the start of the timeline
|
|
||||||
expect(messagePanel.props.backPaginating).toBe(false);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,16 +284,38 @@ describe('TimelinePanel', function() {
|
||||||
// back-paginate until we hit the start
|
// back-paginate until we hit the start
|
||||||
return backPaginate();
|
return backPaginate();
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
|
// hopefully, we got to the start of the timeline
|
||||||
|
expect(messagePanel.props.backPaginating).toBe(false);
|
||||||
|
|
||||||
expect(messagePanel.props.suppressFirstDateSeparator).toBe(false);
|
expect(messagePanel.props.suppressFirstDateSeparator).toBe(false);
|
||||||
var events = scryEventTiles(panel);
|
var events = scryEventTiles(panel);
|
||||||
expect(events[0].props.mxEvent).toBe(timeline.getEvents()[0])
|
expect(events[0].props.mxEvent).toBe(timeline.getEvents()[0]);
|
||||||
|
expect(events.length).toEqual(TIMELINE_CAP);
|
||||||
|
|
||||||
// we should now be able to scroll down, and paginate in the other
|
// we should now be able to scroll down, and paginate in the other
|
||||||
// direction.
|
// direction.
|
||||||
setScrollTop(scrollingDiv.scrollHeight);
|
setScrollTop(scrollingDiv.scrollHeight);
|
||||||
scrollingDiv.scrollTop = scrollingDiv.scrollHeight;
|
scrollingDiv.scrollTop = scrollingDiv.scrollHeight;
|
||||||
return awaitScroll();
|
|
||||||
|
// the delay() below is a heinous hack to deal with the fact that,
|
||||||
|
// without it, we may or may not get control back before the
|
||||||
|
// forward pagination completes. The delay means that it should
|
||||||
|
// have completed.
|
||||||
|
return awaitScroll().delay(0);
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
|
expect(messagePanel.props.backPaginating).toBe(false);
|
||||||
|
expect(messagePanel.props.forwardPaginating).toBe(false);
|
||||||
|
expect(messagePanel.props.suppressFirstDateSeparator).toBe(true);
|
||||||
|
|
||||||
|
var events = scryEventTiles(panel);
|
||||||
|
expect(events.length).toEqual(TIMELINE_CAP);
|
||||||
|
|
||||||
|
// we don't really know what the first event tile will be, since that
|
||||||
|
// depends on how much the timelinepanel decides to paginate.
|
||||||
|
//
|
||||||
|
// just check that the first tile isn't event 0.
|
||||||
|
expect(events[0].props.mxEvent).toNotBe(timeline.getEvents()[0]);
|
||||||
|
|
||||||
console.log("done");
|
console.log("done");
|
||||||
}).done(done, done);
|
}).done(done, done);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue