Update annoying TimelinePanel test

* Actually test what we were supposed to be testing (viz, that we can paginate
  back down after we hit the top of the room)

* Make the cap on the number of events we show in the timeline a configurable
  property, so that we can set it in the test

* Use a smaller cap in the test, so that we have to do less paginating to hit
  the cap, to make the test run quicker.

* add some more logging so that we can see how far it's got if it gets stuck.
This commit is contained in:
Richard van der Hoff 2016-08-24 15:48:19 +01:00
parent 2f0599aae1
commit cdd2902b01
2 changed files with 48 additions and 11 deletions

View file

@ -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();

View file

@ -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: ""+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,9 +284,13 @@ 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.
@ -286,6 +298,23 @@ describe('TimelinePanel', function() {
scrollingDiv.scrollTop = scrollingDiv.scrollHeight; scrollingDiv.scrollTop = scrollingDiv.scrollHeight;
return awaitScroll(); return awaitScroll();
}).then(() => { }).then(() => {
expect(messagePanel.props.backPaginating).toBe(false);
expect(messagePanel.props.forwardPaginating).toBe(true);
return awaitScroll();
}).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);
}); });