tests: Factor out duplicate `getFrameJQuery()`
parent
42026ff771
commit
ff39eeafca
|
@ -15,7 +15,7 @@ const helper = {};
|
||||||
return randomstring;
|
return randomstring;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getFrameJQuery = async ($iframe, includeSendkeys = false) => {
|
helper.getFrameJQuery = async ($iframe, includeSendkeys = false) => {
|
||||||
const win = $iframe[0].contentWindow;
|
const win = $iframe[0].contentWindow;
|
||||||
const doc = win.document;
|
const doc = win.document;
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ const helper = {};
|
||||||
// set new iframe
|
// set new iframe
|
||||||
$('#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$ = await 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;
|
||||||
if (opts.clearCookies) {
|
if (opts.clearCookies) {
|
||||||
|
@ -139,8 +139,10 @@ const helper = {};
|
||||||
if (opts._retry++ >= 4) throw new Error('Pad never loaded');
|
if (opts._retry++ >= 4) throw new Error('Pad never loaded');
|
||||||
return await helper.aNewPad(opts);
|
return await helper.aNewPad(opts);
|
||||||
}
|
}
|
||||||
helper.padOuter$ = await getFrameJQuery(helper.padChrome$('iframe[name="ace_outer"]'), false);
|
helper.padOuter$ =
|
||||||
helper.padInner$ = await getFrameJQuery(helper.padOuter$('iframe[name="ace_inner"]'), true);
|
await helper.getFrameJQuery(helper.padChrome$('iframe[name="ace_outer"]'), false);
|
||||||
|
helper.padInner$ =
|
||||||
|
await helper.getFrameJQuery(helper.padOuter$('iframe[name="ace_inner"]'), true);
|
||||||
|
|
||||||
// disable all animations, this makes tests faster and easier
|
// disable all animations, this makes tests faster and easier
|
||||||
helper.padChrome$.fx.off = true;
|
helper.padChrome$.fx.off = true;
|
||||||
|
@ -183,7 +185,7 @@ const helper = {};
|
||||||
// set new iframe
|
// set new iframe
|
||||||
$('#iframe-container').append($iframe);
|
$('#iframe-container').append($iframe);
|
||||||
$iframe.one('load', async () => {
|
$iframe.one('load', async () => {
|
||||||
helper.admin$ = await getFrameJQuery($('#iframe-container iframe'), false);
|
helper.admin$ = await helper.getFrameJQuery($('#iframe-container iframe'), false);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -34,11 +34,11 @@ helper.multipleUsers = {
|
||||||
},
|
},
|
||||||
|
|
||||||
async _loadJQueryForUser1Frame() {
|
async _loadJQueryForUser1Frame() {
|
||||||
this._user1.padChrome$ = await getFrameJQuery(this._user1.$frame, true);
|
this._user1.padChrome$ = await helper.getFrameJQuery(this._user1.$frame, true);
|
||||||
this._user1.padOuter$ =
|
this._user1.padOuter$ =
|
||||||
await getFrameJQuery(this._user1.padChrome$('iframe[name="ace_outer"]'), false);
|
await helper.getFrameJQuery(this._user1.padChrome$('iframe[name="ace_outer"]'), false);
|
||||||
this._user1.padInner$ =
|
this._user1.padInner$ =
|
||||||
await getFrameJQuery(this._user1.padOuter$('iframe[name="ace_inner"]'), true);
|
await helper.getFrameJQuery(this._user1.padOuter$('iframe[name="ace_inner"]'), true);
|
||||||
|
|
||||||
// update helper vars now that they are available
|
// update helper vars now that they are available
|
||||||
helper.padChrome$ = this._user1.padChrome$;
|
helper.padChrome$ = this._user1.padChrome$;
|
||||||
|
@ -79,37 +79,6 @@ helper.multipleUsers = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// copied from helper.js
|
|
||||||
const getFrameJQuery = async ($iframe, includeSendkeys = false) => {
|
|
||||||
const win = $iframe[0].contentWindow;
|
|
||||||
const doc = win.document;
|
|
||||||
|
|
||||||
const load = async (url) => {
|
|
||||||
const elem = doc.createElement('script');
|
|
||||||
elem.setAttribute('src', url);
|
|
||||||
const p = new Promise((resolve, reject) => {
|
|
||||||
const handler = (evt) => {
|
|
||||||
elem.removeEventListener('load', handler);
|
|
||||||
elem.removeEventListener('error', handler);
|
|
||||||
if (evt.type === 'error') return reject(new Error(`failed to load ${url}`));
|
|
||||||
resolve();
|
|
||||||
};
|
|
||||||
elem.addEventListener('load', handler);
|
|
||||||
elem.addEventListener('error', handler);
|
|
||||||
});
|
|
||||||
doc.head.appendChild(elem);
|
|
||||||
await p;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!win.$) await load('../../static/js/vendors/jquery.js');
|
|
||||||
if (!win.bililiteRange && includeSendkeys) await load('../tests/frontend/lib/sendkeys.js');
|
|
||||||
|
|
||||||
win.$.window = win;
|
|
||||||
win.$.document = doc;
|
|
||||||
|
|
||||||
return win.$;
|
|
||||||
};
|
|
||||||
|
|
||||||
const getCookies =
|
const getCookies =
|
||||||
() => helper.padChrome$.window.require('ep_etherpad-lite/static/js/pad_utils').Cookies;
|
() => helper.padChrome$.window.require('ep_etherpad-lite/static/js/pad_utils').Cookies;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue