Merge branch 'develop' of github.com:matrix-org/matrix-react-sdk into t3chguy/hide-join-part-2
This commit is contained in:
commit
928294eba3
145 changed files with 9478 additions and 3774 deletions
|
@ -18,7 +18,7 @@ var React = require('react');
|
|||
var ReactDOM = require("react-dom");
|
||||
var ReactTestUtils = require('react-addons-test-utils');
|
||||
var expect = require('expect');
|
||||
var q = require('q');
|
||||
import Promise from 'bluebird';
|
||||
|
||||
var sdk = require('matrix-react-sdk');
|
||||
|
||||
|
@ -58,7 +58,7 @@ var Tester = React.createClass({
|
|||
if (handler) {
|
||||
res = handler();
|
||||
} else {
|
||||
res = q(false);
|
||||
res = Promise.resolve(false);
|
||||
}
|
||||
|
||||
if (defer) {
|
||||
|
@ -74,7 +74,7 @@ var Tester = React.createClass({
|
|||
/* returns a promise which will resolve when the fill happens */
|
||||
awaitFill: function(dir) {
|
||||
console.log("ScrollPanel Tester: awaiting " + dir + " fill");
|
||||
var defer = q.defer();
|
||||
var defer = Promise.defer();
|
||||
this._fillDefers[dir] = defer;
|
||||
return defer.promise;
|
||||
},
|
||||
|
@ -94,7 +94,7 @@ var Tester = React.createClass({
|
|||
/* returns a promise which will resolve when a scroll event happens */
|
||||
awaitScroll: function() {
|
||||
console.log("Awaiting scroll");
|
||||
this._scrollDefer = q.defer();
|
||||
this._scrollDefer = Promise.defer();
|
||||
return this._scrollDefer.promise;
|
||||
},
|
||||
|
||||
|
@ -168,7 +168,7 @@ describe('ScrollPanel', function() {
|
|||
const sp = tester.scrollPanel();
|
||||
let retriesRemaining = 1;
|
||||
const awaitReady = function() {
|
||||
return q().then(() => {
|
||||
return Promise.resolve().then(() => {
|
||||
if (sp._pendingFillRequests.b === false &&
|
||||
sp._pendingFillRequests.f === false
|
||||
) {
|
||||
|
@ -192,57 +192,42 @@ describe('ScrollPanel', function() {
|
|||
}
|
||||
});
|
||||
|
||||
it('should handle scrollEvent strangeness', function(done) {
|
||||
var events = [];
|
||||
it('should handle scrollEvent strangeness', function() {
|
||||
const events = [];
|
||||
|
||||
q().then(() => {
|
||||
// initialise with a few events
|
||||
for (var i = 0; i < 10; i++) {
|
||||
events.push(i+90);
|
||||
return Promise.resolve().then(() => {
|
||||
// initialise with a load of events
|
||||
for (let i = 0; i < 20; i++) {
|
||||
events.push(i+80);
|
||||
}
|
||||
tester.setTileKeys(events);
|
||||
expect(tester.fillCounts.b).toEqual(1);
|
||||
expect(tester.fillCounts.f).toEqual(2);
|
||||
expect(scrollingDiv.scrollHeight).toEqual(1550) // 10*150 + 50
|
||||
expect(scrollingDiv.scrollTop).toEqual(1550 - 600);
|
||||
expect(scrollingDiv.scrollHeight).toEqual(3050); // 20*150 + 50
|
||||
expect(scrollingDiv.scrollTop).toEqual(3050 - 600);
|
||||
return tester.awaitScroll();
|
||||
}).then(() => {
|
||||
expect(tester.lastScrollEvent).toBe(950);
|
||||
expect(tester.lastScrollEvent).toBe(3050 - 600);
|
||||
|
||||
// we want to simulate back-filling as we scroll up
|
||||
tester.addFillHandler('b', function() {
|
||||
var newEvents = [];
|
||||
for (var i = 0; i < 10; i++) {
|
||||
newEvents.push(i+80);
|
||||
}
|
||||
events.unshift.apply(events, newEvents);
|
||||
tester.setTileKeys(events);
|
||||
return q(true);
|
||||
});
|
||||
|
||||
// simulate scrolling up; this should trigger the backfill
|
||||
scrollingDiv.scrollTop = 200;
|
||||
|
||||
return tester.awaitFill('b');
|
||||
}).then(() => {
|
||||
console.log('filled');
|
||||
tester.scrollPanel().scrollToToken("92", 0);
|
||||
|
||||
// at this point, ScrollPanel will have updated scrollTop, but
|
||||
// the event hasn't fired. Stamp over the scrollTop.
|
||||
expect(tester.lastScrollEvent).toEqual(200);
|
||||
expect(scrollingDiv.scrollTop).toEqual(10*150 + 200);
|
||||
// the event hasn't fired.
|
||||
expect(tester.lastScrollEvent).toEqual(3050 - 600);
|
||||
expect(scrollingDiv.scrollTop).toEqual(1950);
|
||||
|
||||
// now stamp over the scrollTop.
|
||||
console.log('faking #528');
|
||||
scrollingDiv.scrollTop = 500;
|
||||
|
||||
return tester.awaitScroll();
|
||||
}).then(() => {
|
||||
expect(tester.lastScrollEvent).toBe(10*150 + 200);
|
||||
expect(scrollingDiv.scrollTop).toEqual(10*150 + 200);
|
||||
}).done(done);
|
||||
expect(tester.lastScrollEvent).toBe(1950);
|
||||
expect(scrollingDiv.scrollTop).toEqual(1950);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not get stuck in #528 workaround', function(done) {
|
||||
var events = [];
|
||||
q().then(() => {
|
||||
Promise.resolve().then(() => {
|
||||
// initialise with a bunch of events
|
||||
for (var i = 0; i < 40; i++) {
|
||||
events.push(i);
|
||||
|
@ -250,7 +235,7 @@ describe('ScrollPanel', function() {
|
|||
tester.setTileKeys(events);
|
||||
expect(tester.fillCounts.b).toEqual(1);
|
||||
expect(tester.fillCounts.f).toEqual(2);
|
||||
expect(scrollingDiv.scrollHeight).toEqual(6050) // 40*150 + 50
|
||||
expect(scrollingDiv.scrollHeight).toEqual(6050); // 40*150 + 50
|
||||
expect(scrollingDiv.scrollTop).toEqual(6050 - 600);
|
||||
|
||||
// try to scroll up, to a non-integer offset.
|
||||
|
|
|
@ -18,7 +18,7 @@ var React = require('react');
|
|||
var ReactDOM = require('react-dom');
|
||||
var ReactTestUtils = require('react-addons-test-utils');
|
||||
var expect = require('expect');
|
||||
var q = require('q');
|
||||
import Promise from 'bluebird';
|
||||
var sinon = require('sinon');
|
||||
|
||||
var jssdk = require('matrix-js-sdk');
|
||||
|
@ -126,10 +126,15 @@ describe('TimelinePanel', function() {
|
|||
timeline.addEvent(mkMessage(i));
|
||||
}
|
||||
|
||||
var scrollDefer;
|
||||
let scrollDefer;
|
||||
const onScroll = (e) => {
|
||||
console.log(`TimelinePanel called onScroll: ${e.target.scrollTop}`);
|
||||
if (scrollDefer) {
|
||||
scrollDefer.resolve();
|
||||
}
|
||||
};
|
||||
var rendered = ReactDOM.render(
|
||||
<WrappedTimelinePanel timelineSet={timelineSet} onScroll={() => {scrollDefer.resolve()}}
|
||||
/>,
|
||||
<WrappedTimelinePanel timelineSet={timelineSet} onScroll={onScroll} />,
|
||||
parentDiv,
|
||||
);
|
||||
var panel = rendered.refs.panel;
|
||||
|
@ -140,21 +145,20 @@ describe('TimelinePanel', function() {
|
|||
// panel isn't paginating
|
||||
var awaitPaginationCompletion = function() {
|
||||
if(!panel.state.forwardPaginating)
|
||||
return q();
|
||||
return Promise.resolve();
|
||||
else
|
||||
return q.delay(0).then(awaitPaginationCompletion);
|
||||
return Promise.delay(0).then(awaitPaginationCompletion);
|
||||
};
|
||||
|
||||
// helper function which will return a promise which resolves when
|
||||
// the TimelinePanel fires a scroll event
|
||||
var awaitScroll = function() {
|
||||
scrollDefer = q.defer();
|
||||
scrollDefer = Promise.defer();
|
||||
return scrollDefer.promise;
|
||||
};
|
||||
|
||||
// wait for the panel to load - we'll get a scroll event once it
|
||||
// happens
|
||||
awaitScroll().then(() => {
|
||||
// let the first round of pagination finish off
|
||||
Promise.delay(5).then(() => {
|
||||
expect(panel.state.canBackPaginate).toBe(false);
|
||||
expect(scryEventTiles(panel).length).toEqual(N_EVENTS);
|
||||
|
||||
|
@ -164,6 +168,8 @@ describe('TimelinePanel', function() {
|
|||
|
||||
// wait for the scroll event to land
|
||||
}).then(awaitScroll).then(() => {
|
||||
expect(scrollingDiv.scrollTop).toEqual(0);
|
||||
|
||||
// there should be no pagination going on now
|
||||
expect(panel.state.backPaginating).toBe(false);
|
||||
expect(panel.state.forwardPaginating).toBe(false);
|
||||
|
@ -208,7 +214,7 @@ describe('TimelinePanel', function() {
|
|||
client.paginateEventTimeline = sinon.spy((tl, opts) => {
|
||||
console.log("paginate:", opts);
|
||||
expect(opts.backwards).toBe(true);
|
||||
return q(true);
|
||||
return Promise.resolve(true);
|
||||
});
|
||||
|
||||
var rendered = ReactDOM.render(
|
||||
|
@ -273,7 +279,7 @@ describe('TimelinePanel', function() {
|
|||
// helper function which will return a promise which resolves when
|
||||
// the TimelinePanel fires a scroll event
|
||||
var awaitScroll = function() {
|
||||
scrollDefer = q.defer();
|
||||
scrollDefer = Promise.defer();
|
||||
|
||||
return scrollDefer.promise.then(() => {
|
||||
console.log("got scroll event; scrollTop now " +
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue