mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-23 17:06:16 -04:00
tests: Support injecting hook functions during pad load
This commit is contained in:
parent
c8e544ec8d
commit
e28c9ffc97
3 changed files with 28 additions and 1 deletions
|
@ -47,6 +47,9 @@
|
||||||
hook. Plugins should use this instead of the `clientVars` global variable.
|
hook. Plugins should use this instead of the `clientVars` global variable.
|
||||||
* New `userJoin` server-side hook.
|
* New `userJoin` server-side hook.
|
||||||
* The `userLeave` server-side hook has a new `socket` context property.
|
* The `userLeave` server-side hook has a new `socket` context property.
|
||||||
|
* The `helper.aNewPad()` function (accessible to client-side tests) now
|
||||||
|
accepts hook functions to inject when opening a pad. This can be used to
|
||||||
|
test any new client-side hooks your plugin provides.
|
||||||
|
|
||||||
# 1.8.14
|
# 1.8.14
|
||||||
|
|
||||||
|
|
|
@ -478,6 +478,10 @@
|
||||||
|
|
||||||
plugins.baseURL = baseURL;
|
plugins.baseURL = baseURL;
|
||||||
plugins.update(function () {
|
plugins.update(function () {
|
||||||
|
// Mechanism for tests to register hook functions (install fake plugins).
|
||||||
|
window._postPluginUpdateForTestingDone = false;
|
||||||
|
if (window._postPluginUpdateForTesting != null) window._postPluginUpdateForTesting();
|
||||||
|
window._postPluginUpdateForTestingDone = true;
|
||||||
// Call documentReady hook
|
// Call documentReady hook
|
||||||
$(function() {
|
$(function() {
|
||||||
hooks.aCallAll('documentReady');
|
hooks.aCallAll('documentReady');
|
||||||
|
|
|
@ -96,6 +96,7 @@ const helper = {};
|
||||||
_retry: 0,
|
_retry: 0,
|
||||||
clearCookies: true,
|
clearCookies: true,
|
||||||
id: `FRONTEND_TEST_${helper.randomString(20)}`,
|
id: `FRONTEND_TEST_${helper.randomString(20)}`,
|
||||||
|
hookFns: {},
|
||||||
}, opts);
|
}, opts);
|
||||||
|
|
||||||
// if opts.params is set we manipulate the URL to include URL parameters IE ?foo=Bah.
|
// if opts.params is set we manipulate the URL to include URL parameters IE ?foo=Bah.
|
||||||
|
@ -122,7 +123,26 @@ const helper = {};
|
||||||
$('#iframe-container iframe').remove();
|
$('#iframe-container iframe').remove();
|
||||||
// set new iframe
|
// set new iframe
|
||||||
$('#iframe-container').append($iframe);
|
$('#iframe-container').append($iframe);
|
||||||
await new Promise((resolve) => $iframe.one('load', resolve));
|
await Promise.all([
|
||||||
|
new Promise((resolve) => $iframe.one('load', resolve)),
|
||||||
|
// Install the hook functions as early as possible because some of them fire right away.
|
||||||
|
new Promise((resolve, reject) => {
|
||||||
|
if ($iframe[0].contentWindow._postPluginUpdateForTestingDone) {
|
||||||
|
return reject(new Error(
|
||||||
|
'failed to set _postPluginUpdateForTesting before it would have been called'));
|
||||||
|
}
|
||||||
|
$iframe[0].contentWindow._postPluginUpdateForTesting = () => {
|
||||||
|
const {hooks} =
|
||||||
|
$iframe[0].contentWindow.require('ep_etherpad-lite/static/js/pluginfw/plugin_defs');
|
||||||
|
for (const [hookName, hookFns] of Object.entries(opts.hookFns)) {
|
||||||
|
if (hooks[hookName] == null) hooks[hookName] = [];
|
||||||
|
hooks[hookName].push(
|
||||||
|
...hookFns.map((hookFn) => ({hook_name: hookName, hook_fn: hookFn})));
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
]);
|
||||||
helper.padChrome$ = await helper.getFrameJQuery($('#iframe-container iframe'), true);
|
helper.padChrome$ = await helper.getFrameJQuery($('#iframe-container iframe'), true);
|
||||||
helper.padChrome$.padeditor =
|
helper.padChrome$.padeditor =
|
||||||
helper.padChrome$.window.require('ep_etherpad-lite/static/js/pad_editor').padeditor;
|
helper.padChrome$.window.require('ep_etherpad-lite/static/js/pad_editor').padeditor;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue