tests: New `helper.aNewPad()` (promisified `newPad()`)
parent
ec76a6548f
commit
718da6fc1b
|
@ -89,12 +89,22 @@ const helper = {};
|
||||||
}
|
}
|
||||||
helper.evtType = evtType;
|
helper.evtType = evtType;
|
||||||
|
|
||||||
helper.newPad = (opts, padName) => {
|
// Deprecated; use helper.aNewPad() instead.
|
||||||
|
helper.newPad = (opts, id) => {
|
||||||
|
if (!id) id = `FRONTEND_TEST_${helper.randomString(20)}`;
|
||||||
|
opts = Object.assign({id}, typeof opts === 'function' ? {cb: opts} : opts);
|
||||||
|
const {cb = (err) => { if (err != null) throw err; }} = opts;
|
||||||
|
delete opts.cb;
|
||||||
|
helper.aNewPad(opts).then((id) => cb(null, id), (err) => cb(err || new Error(err)));
|
||||||
|
return id;
|
||||||
|
};
|
||||||
|
|
||||||
|
helper.aNewPad = async (opts = {}) => {
|
||||||
opts = Object.assign({
|
opts = Object.assign({
|
||||||
_retry: 0,
|
_retry: 0,
|
||||||
cb: (err) => { if (err != null) throw err; },
|
|
||||||
clearCookies: true,
|
clearCookies: true,
|
||||||
}, typeof opts === 'function' ? {cb: opts} : opts);
|
id: `FRONTEND_TEST_${helper.randomString(20)}`,
|
||||||
|
}, 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.
|
||||||
let encodedParams;
|
let encodedParams;
|
||||||
|
@ -111,8 +121,7 @@ const helper = {};
|
||||||
helper.clearSessionCookies();
|
helper.clearSessionCookies();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!padName) padName = `FRONTEND_TEST_${helper.randomString(20)}`;
|
$iframe = $(`<iframe src='/p/${opts.id}${hash || ''}${encodedParams || ''}'></iframe>`);
|
||||||
$iframe = $(`<iframe src='/p/${padName}${hash || ''}${encodedParams || ''}'></iframe>`);
|
|
||||||
|
|
||||||
// clean up inner iframe references
|
// clean up inner iframe references
|
||||||
helper.padChrome$ = helper.padOuter$ = helper.padInner$ = null;
|
helper.padChrome$ = helper.padOuter$ = helper.padInner$ = null;
|
||||||
|
@ -121,7 +130,7 @@ const helper = {};
|
||||||
$('#iframe-container iframe').remove();
|
$('#iframe-container iframe').remove();
|
||||||
// set new iframe
|
// set new iframe
|
||||||
$('#iframe-container').append($iframe);
|
$('#iframe-container').append($iframe);
|
||||||
$iframe.one('load', () => {
|
await new Promise((resolve) => $iframe.one('load', resolve));
|
||||||
helper.padChrome$ = getFrameJQuery($('#iframe-container iframe'));
|
helper.padChrome$ = getFrameJQuery($('#iframe-container iframe'));
|
||||||
if (opts.clearCookies) {
|
if (opts.clearCookies) {
|
||||||
helper.clearPadPrefCookie();
|
helper.clearPadPrefCookie();
|
||||||
|
@ -129,8 +138,13 @@ const helper = {};
|
||||||
if (opts.padPrefs) {
|
if (opts.padPrefs) {
|
||||||
helper.setPadPrefCookie(opts.padPrefs);
|
helper.setPadPrefCookie(opts.padPrefs);
|
||||||
}
|
}
|
||||||
helper.waitFor(() => !$iframe.contents().find('#editorloadingbox')
|
try {
|
||||||
.is(':visible'), 10000).done(() => {
|
await helper.waitForPromise(
|
||||||
|
() => !$iframe.contents().find('#editorloadingbox').is(':visible'), 10000);
|
||||||
|
} catch (err) {
|
||||||
|
if (opts._retry++ >= 4) throw new Error('Pad never loaded');
|
||||||
|
return await helper.aNewPad(opts);
|
||||||
|
}
|
||||||
helper.padOuter$ = getFrameJQuery(helper.padChrome$('iframe[name="ace_outer"]'));
|
helper.padOuter$ = getFrameJQuery(helper.padChrome$('iframe[name="ace_outer"]'));
|
||||||
helper.padInner$ = getFrameJQuery(helper.padOuter$('iframe[name="ace_inner"]'));
|
helper.padInner$ = getFrameJQuery(helper.padOuter$('iframe[name="ace_inner"]'));
|
||||||
|
|
||||||
|
@ -159,14 +173,8 @@ const helper = {};
|
||||||
|
|
||||||
// listen for server messages
|
// listen for server messages
|
||||||
helper.spyOnSocketIO();
|
helper.spyOnSocketIO();
|
||||||
opts.cb();
|
|
||||||
}).fail(() => {
|
|
||||||
if (opts._retry++ >= 4) throw new Error('Pad never loaded');
|
|
||||||
helper.newPad(opts, padName);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return padName;
|
return opts.id;
|
||||||
};
|
};
|
||||||
|
|
||||||
helper.newAdmin = async (page) => {
|
helper.newAdmin = async (page) => {
|
||||||
|
|
Loading…
Reference in New Issue