Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit cf41155

Browse files
authored
Test TimelinePanel canForwardPaginate (#561)
Fix scroll up, down pagination test NB: this test may not fail on Travis, although it did fail locally without a fix: #563. Once the test has scrolled the panel to the top, to the earliest events, it should be able to forward paginate, because some degree of unpagination occurs. This does assume that unpagination will occur when scrolling to the beginning of the events and that unpagination should allow pagination again in the same direction. Instead of checking that the first event is no longer the first event (varies due to unpagination), check instead that the most recent event can be seen when scrolling all the way down to the bottom of the TimelinePanel. Scrolling past the bottom of content seems to have strange behaviour, which isn't a useful part of the test. So now the test will scroll down until the last event instead.
1 parent 341175e commit cf41155

File tree

1 file changed

+35
-25
lines changed

1 file changed

+35
-25
lines changed

test/components/structures/TimelinePanel-test.js

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,8 @@ describe('TimelinePanel', function() {
238238
}, 0);
239239
});
240240

241-
it("should let you scroll down again after you've scrolled up", function(done) {
242-
var TIMELINE_CAP = 100; // needs to be more than we can fit in the div
243-
var N_EVENTS = 120; // needs to be more than TIMELINE_CAP
241+
it("should let you scroll down to the bottom after you've scrolled up", function(done) {
242+
var N_EVENTS = 120; // the number of events to simulate being added to the timeline
244243

245244
// sadly, loading all those events takes a while
246245
this.timeout(N_EVENTS * 50);
@@ -257,9 +256,7 @@ describe('TimelinePanel', function() {
257256

258257
var scrollDefer;
259258
var rendered = ReactDOM.render(
260-
<WrappedTimelinePanel timelineSet={timelineSet} onScroll={() => {scrollDefer.resolve()}}
261-
timelineCap={TIMELINE_CAP}
262-
/>,
259+
<WrappedTimelinePanel timelineSet={timelineSet} onScroll={() => {scrollDefer.resolve()}}/>,
263260
parentDiv
264261
);
265262
console.log("TimelinePanel rendered");
@@ -273,6 +270,7 @@ describe('TimelinePanel', function() {
273270
// the TimelinePanel fires a scroll event
274271
var awaitScroll = function() {
275272
scrollDefer = q.defer();
273+
276274
return scrollDefer.promise.then(() => {
277275
console.log("got scroll event; scrollTop now " +
278276
scrollingDiv.scrollTop);
@@ -306,6 +304,27 @@ describe('TimelinePanel', function() {
306304
});
307305
}
308306

307+
function scrollDown() {
308+
// Scroll the bottom of the viewport to the bottom of the panel
309+
setScrollTop(scrollingDiv.scrollHeight - scrollingDiv.clientHeight);
310+
console.log("scrolling down... " + scrollingDiv.scrollTop);
311+
return awaitScroll().delay(0).then(() => {
312+
313+
let eventTiles = scryEventTiles(panel);
314+
let events = timeline.getEvents();
315+
316+
let lastEventInPanel = eventTiles[eventTiles.length - 1].props.mxEvent;
317+
let lastEventInTimeline = events[events.length - 1];
318+
319+
// Scroll until the last event in the panel = the last event in the timeline
320+
if(lastEventInPanel.getId() !== lastEventInTimeline.getId()) {
321+
// need to go further
322+
return scrollDown();
323+
}
324+
console.log("paginated to end.");
325+
});
326+
}
327+
309328
// let the first round of pagination finish off
310329
awaitScroll().then(() => {
311330
// we should now have loaded the first few events
@@ -321,31 +340,22 @@ describe('TimelinePanel', function() {
321340
expect(messagePanel.props.suppressFirstDateSeparator).toBe(false);
322341
var events = scryEventTiles(panel);
323342
expect(events[0].props.mxEvent).toBe(timeline.getEvents()[0]);
324-
expect(events.length).toBeLessThanOrEqualTo(TIMELINE_CAP);
325-
326-
// we should now be able to scroll down, and paginate in the other
327-
// direction.
328-
setScrollTop(scrollingDiv.scrollHeight);
329-
scrollingDiv.scrollTop = scrollingDiv.scrollHeight;
330-
331-
// the delay() below is a heinous hack to deal with the fact that,
332-
// without it, we may or may not get control back before the
333-
// forward pagination completes. The delay means that it should
334-
// have completed.
335-
return awaitScroll().delay(0);
343+
344+
// Expect to be able to paginate forwards, having unpaginated a few events
345+
expect(panel.state.canForwardPaginate).toBe(true);
346+
347+
// scroll all the way to the bottom
348+
return scrollDown();
336349
}).then(() => {
337350
expect(messagePanel.props.backPaginating).toBe(false);
338351
expect(messagePanel.props.forwardPaginating).toBe(false);
339-
expect(messagePanel.props.suppressFirstDateSeparator).toBe(true);
340352

341353
var events = scryEventTiles(panel);
342-
expect(events.length).toBeLessThanOrEqualTo(TIMELINE_CAP);
343354

344-
// we don't really know what the first event tile will be, since that
345-
// depends on how much the timelinepanel decides to paginate.
346-
//
347-
// just check that the first tile isn't event 0.
348-
expect(events[0].props.mxEvent).toNotBe(timeline.getEvents()[0]);
355+
// Expect to be able to see the most recent event
356+
var lastEventInPanel = events[events.length - 1].props.mxEvent;
357+
var lastEventInTimeline = timeline.getEvents()[timeline.getEvents().length - 1];
358+
expect(lastEventInPanel.getContent()).toBe(lastEventInTimeline.getContent());
349359

350360
console.log("done");
351361
}).done(done, done);

0 commit comments

Comments
 (0)