tests: Speed up `helper.edit()` and `helper.clearPad()`
parent
7a154b1e1d
commit
7cbb3f565d
|
@ -44,6 +44,7 @@ const getCollabClient = (ace2editor, serverVars, initialUserInfo, options, _pad)
|
||||||
let channelState = 'CONNECTING';
|
let channelState = 'CONNECTING';
|
||||||
let lastCommitTime = 0;
|
let lastCommitTime = 0;
|
||||||
let initialStartConnectTime = 0;
|
let initialStartConnectTime = 0;
|
||||||
|
let commitDelay = 500;
|
||||||
|
|
||||||
const userId = initialUserInfo.userId;
|
const userId = initialUserInfo.userId;
|
||||||
// var socket;
|
// var socket;
|
||||||
|
@ -102,7 +103,7 @@ const getCollabClient = (ace2editor, serverVars, initialUserInfo, options, _pad)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const earliestCommit = lastCommitTime + 500;
|
const earliestCommit = lastCommitTime + commitDelay;
|
||||||
if (now < earliestCommit) {
|
if (now < earliestCommit) {
|
||||||
setTimeout(handleUserChanges, earliestCommit - now);
|
setTimeout(handleUserChanges, earliestCommit - now);
|
||||||
return;
|
return;
|
||||||
|
@ -488,6 +489,8 @@ const getCollabClient = (ace2editor, serverVars, initialUserInfo, options, _pad)
|
||||||
setChannelState,
|
setChannelState,
|
||||||
setStateIdle,
|
setStateIdle,
|
||||||
setIsPendingRevision,
|
setIsPendingRevision,
|
||||||
|
set commitDelay(ms) { commitDelay = ms; },
|
||||||
|
get commitDelay() { return commitDelay; },
|
||||||
};
|
};
|
||||||
|
|
||||||
tellAceAboutHistoricalAuthors(serverVars.historicalAuthorData);
|
tellAceAboutHistoricalAuthors(serverVars.historicalAuthorData);
|
||||||
|
|
|
@ -127,6 +127,8 @@ const helper = {};
|
||||||
$('#iframe-container').append($iframe);
|
$('#iframe-container').append($iframe);
|
||||||
await new Promise((resolve) => $iframe.one('load', resolve));
|
await new Promise((resolve) => $iframe.one('load', resolve));
|
||||||
helper.padChrome$ = getFrameJQuery($('#iframe-container iframe'));
|
helper.padChrome$ = getFrameJQuery($('#iframe-container iframe'));
|
||||||
|
helper.padChrome$.padeditor =
|
||||||
|
helper.padChrome$.window.require('ep_etherpad-lite/static/js/pad_editor').padeditor;
|
||||||
if (opts.clearCookies) {
|
if (opts.clearCookies) {
|
||||||
helper.clearPadPrefCookie();
|
helper.clearPadPrefCookie();
|
||||||
}
|
}
|
||||||
|
@ -260,6 +262,22 @@ const helper = {};
|
||||||
selection.addRange(range);
|
selection.addRange(range);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Temporarily reduces minimum time between commits and calls the provided function with a single
|
||||||
|
// argument: a function that immediately incorporates all pad edits (as opposed to waiting for the
|
||||||
|
// idle timer to fire).
|
||||||
|
helper.withFastCommit = async (fn) => {
|
||||||
|
const incorp = () => helper.padChrome$.padeditor.ace.callWithAce(
|
||||||
|
(ace) => ace.ace_inCallStackIfNecessary('helper.edit', () => ace.ace_fastIncorp()));
|
||||||
|
const cc = helper.padChrome$.window.pad.collabClient;
|
||||||
|
const {commitDelay} = cc;
|
||||||
|
cc.commitDelay = 0;
|
||||||
|
try {
|
||||||
|
return await fn(incorp);
|
||||||
|
} finally {
|
||||||
|
cc.commitDelay = commitDelay;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const getTextNodeAndOffsetOf = ($targetLine, targetOffsetAtLine) => {
|
const getTextNodeAndOffsetOf = ($targetLine, targetOffsetAtLine) => {
|
||||||
const $textNodes = $targetLine.find('*').contents().filter(function () {
|
const $textNodes = $targetLine.find('*').contents().filter(function () {
|
||||||
return this.nodeType === Node.TEXT_NODE;
|
return this.nodeType === Node.TEXT_NODE;
|
||||||
|
|
|
@ -32,8 +32,11 @@ helper.spyOnSocketIO = () => {
|
||||||
helper.edit = async (message, line) => {
|
helper.edit = async (message, line) => {
|
||||||
const editsNum = helper.commits.length;
|
const editsNum = helper.commits.length;
|
||||||
line = line ? line - 1 : 0;
|
line = line ? line - 1 : 0;
|
||||||
helper.linesDiv()[line].sendkeys(message);
|
await helper.withFastCommit(async (incorp) => {
|
||||||
return helper.waitForPromise(() => editsNum + 1 === helper.commits.length);
|
helper.linesDiv()[line].sendkeys(message);
|
||||||
|
incorp();
|
||||||
|
await helper.waitForPromise(() => editsNum + 1 === helper.commits.length);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -216,7 +219,10 @@ helper.clearPad = async () => {
|
||||||
await helper.waitForPromise(() => !helper.padInner$.document.getSelection().isCollapsed);
|
await helper.waitForPromise(() => !helper.padInner$.document.getSelection().isCollapsed);
|
||||||
const e = new helper.padInner$.Event(helper.evtType);
|
const e = new helper.padInner$.Event(helper.evtType);
|
||||||
e.keyCode = 8; // delete key
|
e.keyCode = 8; // delete key
|
||||||
helper.padInner$('#innerdocbody').trigger(e);
|
await helper.withFastCommit(async (incorp) => {
|
||||||
await helper.waitForPromise(helper.padIsEmpty);
|
helper.padInner$('#innerdocbody').trigger(e);
|
||||||
await helper.waitForPromise(() => helper.commits.length > commitsBefore);
|
incorp();
|
||||||
|
await helper.waitForPromise(helper.padIsEmpty);
|
||||||
|
await helper.waitForPromise(() => helper.commits.length > commitsBefore);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue