tests: Improve readability of `multipleUsers.js`

* Define utility functions above their use to silence lint warnings.
  * Use `.css()` instead of `.attr('style')` to manipulate style.
  * Pass an object to `.attr()` rather than call once per attribute.
  * Take advantage of chaining.
  * Inline unnecessary `padUrl` variable.
  * Delete some unnecessary comments.
pull/5133/head
Richard Hansen 2021-07-22 13:42:31 -04:00 committed by webzwo0i
parent ff39eeafca
commit d723270388
1 changed files with 21 additions and 27 deletions

View File

@ -1,5 +1,21 @@
'use strict'; 'use strict';
const getCookies =
() => helper.padChrome$.window.require('ep_etherpad-lite/static/js/pad_utils').Cookies;
const setToken = (token) => getCookies().set('token', token);
const getToken = () => getCookies().get('token');
const startActingLike = (user) => {
helper.padChrome$ = user.padChrome$;
helper.padOuter$ = user.padOuter$;
helper.padInner$ = user.padInner$;
if (helper.padChrome$) setToken(user.token);
};
const clearToken = () => getCookies().remove('token');
helper.multipleUsers = { helper.multipleUsers = {
_user0: null, _user0: null,
_user1: null, _user1: null,
@ -47,14 +63,11 @@ helper.multipleUsers = {
}, },
async _createUser1Frame() { async _createUser1Frame() {
// create the iframe this._user0.$frame.css({height: '50%'});
const padUrl = this._user0.$frame.attr('src'); this._user1.$frame = $('<iframe>')
this._user1.$frame = $('<iframe>').attr('id', 'user1_pad').attr('src', padUrl); .attr({id: 'user1_pad', src: this._user0.$frame.attr('src')})
.css({height: '50%', top: '50%'})
// place one iframe (visually) below the other .insertAfter(this._user0.$frame);
this._user0.$frame.attr('style', 'height: 50%');
this._user1.$frame.attr('style', 'height: 50%; top: 50%');
this._user1.$frame.insertAfter(this._user0.$frame);
// wait for user1 pad to load // wait for user1 pad to load
await new Promise((resolve) => this._user1.$frame.one('load', resolve)); await new Promise((resolve) => this._user1.$frame.one('load', resolve));
@ -78,22 +91,3 @@ helper.multipleUsers = {
} }
}, },
}; };
const getCookies =
() => helper.padChrome$.window.require('ep_etherpad-lite/static/js/pad_utils').Cookies;
const setToken = (token) => getCookies().set('token', token);
const getToken = () => getCookies().get('token');
const startActingLike = (user) => {
// update helper references, so other methods will act as if the main frame
// was the one we're using from now on
helper.padChrome$ = user.padChrome$;
helper.padOuter$ = user.padOuter$;
helper.padInner$ = user.padInner$;
if (helper.padChrome$) setToken(user.token);
};
const clearToken = () => getCookies().remove('token');