Merge branch 'develop' of github.com:matrix-org/matrix-react-sdk into t3chguy/hide-join-part-2

This commit is contained in:
Michael Telatynski 2017-07-21 19:23:42 +01:00
commit 928294eba3
No known key found for this signature in database
GPG key ID: 0435A1D4BBD34D64
145 changed files with 9478 additions and 3774 deletions

View file

@ -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.

View file

@ -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 " +

View file

@ -15,11 +15,12 @@ limitations under the License.
*/
import expect from 'expect';
import q from 'q';
import Promise from 'bluebird';
import React from 'react';
import ReactDOM from 'react-dom';
import ReactTestUtils from 'react-addons-test-utils';
import sinon from 'sinon';
import MatrixReactTestUtils from 'matrix-react-test-utils';
import sdk from 'matrix-react-sdk';
import MatrixClientPeg from '../../../../src/MatrixClientPeg';
@ -47,9 +48,9 @@ describe('InteractiveAuthDialog', function () {
sandbox.restore();
});
it('Should successfully complete a password flow', function(done) {
it('Should successfully complete a password flow', function() {
const onFinished = sinon.spy();
const doRequest = sinon.stub().returns(q({a:1}));
const doRequest = sinon.stub().returns(Promise.resolve({a:1}));
// tell the stub matrixclient to return a real userid
var client = MatrixClientPeg.get();
@ -69,7 +70,7 @@ describe('InteractiveAuthDialog', function () {
/>, parentDiv);
// wait for a password box and a submit button
test_utils.waitForRenderedDOMComponentWithTag(dlg, "form").then((formNode) => {
return MatrixReactTestUtils.waitForRenderedDOMComponentWithTag(dlg, "form", 2).then((formNode) => {
const inputNodes = ReactTestUtils.scryRenderedDOMComponentsWithTag(
dlg, "input"
);
@ -109,10 +110,10 @@ describe('InteractiveAuthDialog', function () {
);
// let the request complete
return q.delay(1);
return Promise.delay(1);
}).then(() => {
expect(onFinished.callCount).toEqual(1);
expect(onFinished.calledWithExactly(true, {a:1})).toBe(true);
}).done(done, done);
});
});
});

View file

@ -3,7 +3,7 @@ import ReactTestUtils from 'react-addons-test-utils';
import ReactDOM from 'react-dom';
import expect, {createSpy} from 'expect';
import sinon from 'sinon';
import Q from 'q';
import Promise from 'bluebird';
import * as testUtils from '../../../test-utils';
import sdk from 'matrix-react-sdk';
import UserSettingsStore from '../../../../src/UserSettingsStore';
@ -27,14 +27,10 @@ describe('MessageComposerInput', () => {
mci = null,
room = testUtils.mkStubRoom('!DdJkzRliezrwpNebLk:matrix.org');
// TODO Remove when RTE is out of labs.
beforeEach(function() {
testUtils.beforeEach(this);
sandbox = testUtils.stubClient(sandbox);
client = MatrixClientPeg.get();
UserSettingsStore.isFeatureEnabled = sinon.stub()
.withArgs('rich_text_editor').returns(true);
parentDiv = document.createElement('div');
document.body.appendChild(parentDiv);
@ -51,7 +47,7 @@ describe('MessageComposerInput', () => {
// warnings
// (please can we make the components not setState() after
// they are unmounted?)
Q.delay(10).done(() => {
Promise.delay(10).done(() => {
if (parentDiv) {
ReactDOM.unmountComponentAtNode(parentDiv);
parentDiv.remove();
@ -104,11 +100,12 @@ describe('MessageComposerInput', () => {
addTextToDraft('a');
mci.handleKeyCommand('toggle-mode');
mci.handleReturn(sinon.stub());
expect(spy.calledOnce).toEqual(true);
expect(spy.args[0][1]).toEqual('a');
});
it('should send emoji messages in rich text', () => {
it('should send emoji messages when rich text is enabled', () => {
const spy = sinon.spy(client, 'sendTextMessage');
mci.enableRichtext(true);
addTextToDraft('☹');
@ -117,7 +114,7 @@ describe('MessageComposerInput', () => {
expect(spy.calledOnce).toEqual(true, 'should send message');
});
it('should send emoji messages in Markdown', () => {
it('should send emoji messages when Markdown is enabled', () => {
const spy = sinon.spy(client, 'sendTextMessage');
mci.enableRichtext(false);
addTextToDraft('☹');