mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-02-01 03:12:42 +01:00
jshint and test
This commit is contained in:
parent
a2a7322226
commit
1956b29093
2 changed files with 41 additions and 11 deletions
|
@ -1,4 +1,5 @@
|
||||||
var helper = {};
|
'use strict';
|
||||||
|
const helper = {}; // eslint-disable-line
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
let $iframe; const
|
let $iframe; const
|
||||||
|
@ -29,10 +30,9 @@ var helper = {};
|
||||||
|
|
||||||
const getFrameJQuery = function ($iframe) {
|
const getFrameJQuery = function ($iframe) {
|
||||||
/*
|
/*
|
||||||
I tried over 9000 ways to inject javascript into iframes.
|
I tried over 9001 ways to inject javascript into iframes.
|
||||||
This is the only way I found that worked in IE 7+8+9, FF and Chrome
|
This is the only way I found that worked in IE 7+8+9, FF and Chrome
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const win = $iframe[0].contentWindow;
|
const win = $iframe[0].contentWindow;
|
||||||
const doc = win.document;
|
const doc = win.document;
|
||||||
|
|
||||||
|
@ -68,7 +68,8 @@ var helper = {};
|
||||||
// I don't fully understand it, but this function seems to properly simulate
|
// I don't fully understand it, but this function seems to properly simulate
|
||||||
// padCookie.setPref in the client code
|
// padCookie.setPref in the client code
|
||||||
helper.setPadPrefCookie = function (prefs) {
|
helper.setPadPrefCookie = function (prefs) {
|
||||||
helper.padChrome$.document.cookie = (`prefsHttp=${escape(JSON.stringify(prefs))};expires=Thu, 01 Jan 3000 00:00:00 GMT`);
|
helper.padChrome$.document.cookie =
|
||||||
|
(`prefsHttp=${escape(JSON.stringify(prefs))};expires=Thu, 01 Jan 3000 00:00:00 GMT`);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Functionality for knowing what key event type is required for tests
|
// Functionality for knowing what key event type is required for tests
|
||||||
|
@ -102,8 +103,13 @@ var helper = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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;
|
||||||
if (opts.params) {
|
if (opts.params) {
|
||||||
var encodedParams = `?${$.param(opts.params)}`;
|
encodedParams = `?${$.param(opts.params)}`;
|
||||||
|
}
|
||||||
|
let hash;
|
||||||
|
if (opts.hash) {
|
||||||
|
hash = `#${opts.hash}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear cookies
|
// clear cookies
|
||||||
|
@ -112,8 +118,7 @@ var helper = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!padName) padName = `FRONTEND_TEST_${helper.randomString(20)}`;
|
if (!padName) padName = `FRONTEND_TEST_${helper.randomString(20)}`;
|
||||||
$iframe = $(`<iframe src='/p/${padName}${encodedParams || ''}'></iframe>`);
|
$iframe = $(`<iframe src='/p/${padName}${hash || ''}${encodedParams || ''}'></iframe>`);
|
||||||
|
|
||||||
// needed for retry
|
// needed for retry
|
||||||
const origPadName = padName;
|
const origPadName = padName;
|
||||||
|
|
||||||
|
@ -132,7 +137,8 @@ var helper = {};
|
||||||
if (opts.padPrefs) {
|
if (opts.padPrefs) {
|
||||||
helper.setPadPrefCookie(opts.padPrefs);
|
helper.setPadPrefCookie(opts.padPrefs);
|
||||||
}
|
}
|
||||||
helper.waitFor(() => !$iframe.contents().find('#editorloadingbox').is(':visible'), 10000).done(() => {
|
helper.waitFor(() => !$iframe.contents().find('#editorloadingbox')
|
||||||
|
.is(':visible'), 10000).done(() => {
|
||||||
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"]'));
|
||||||
|
|
||||||
|
@ -175,7 +181,7 @@ var helper = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
helper.waitFor = function (conditionFunc, timeoutTime = 1900, intervalTime = 10) {
|
helper.waitFor = function (conditionFunc, timeoutTime = 1900, intervalTime = 10) {
|
||||||
const deferred = $.Deferred();
|
const deferred = $.Deferred(); // eslint-disable-line
|
||||||
|
|
||||||
const _fail = deferred.fail.bind(deferred);
|
const _fail = deferred.fail.bind(deferred);
|
||||||
let listenForFail = false;
|
let listenForFail = false;
|
||||||
|
@ -245,7 +251,7 @@ var helper = {};
|
||||||
selection.addRange(range);
|
selection.addRange(range);
|
||||||
};
|
};
|
||||||
|
|
||||||
var getTextNodeAndOffsetOf = function ($targetLine, targetOffsetAtLine) {
|
const getTextNodeAndOffsetOf = function ($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;
|
||||||
});
|
});
|
||||||
|
@ -268,7 +274,7 @@ var helper = {};
|
||||||
});
|
});
|
||||||
|
|
||||||
// edge cases
|
// edge cases
|
||||||
if (textNodeWhereOffsetIs === null) {
|
if (textNodeWhereOffsetIs == null) {
|
||||||
// there was no text node inside $targetLine, so it is an empty line (<br>).
|
// there was no text node inside $targetLine, so it is an empty line (<br>).
|
||||||
// Use beginning of line
|
// Use beginning of line
|
||||||
textNodeWhereOffsetIs = $targetLine.get(0);
|
textNodeWhereOffsetIs = $targetLine.get(0);
|
||||||
|
|
24
tests/frontend/specs/scrollTo.js
Executable file
24
tests/frontend/specs/scrollTo.js
Executable file
|
@ -0,0 +1,24 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
describe('scrolls to line', function () {
|
||||||
|
// create a new pad with URL hash set before each test run
|
||||||
|
beforeEach(function (cb) {
|
||||||
|
helper.newPad({
|
||||||
|
hash: 'L4',
|
||||||
|
cb,
|
||||||
|
});
|
||||||
|
this.timeout(10000);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('Scrolls down to Line 4', function (done) {
|
||||||
|
this.timeout(10000);
|
||||||
|
const chrome$ = helper.padChrome$;
|
||||||
|
helper.waitFor(() => {
|
||||||
|
const topOffset = parseInt(chrome$('iframe').first('iframe')
|
||||||
|
.contents().find('#outerdocbody').css('top'));
|
||||||
|
return (topOffset >= 100);
|
||||||
|
});
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue