tests: Don't rely on global pad variable

This commit is contained in:
Richard Hansen 2021-08-14 00:09:31 -04:00
parent e99eb6366c
commit f5c2ea853c
4 changed files with 9 additions and 5 deletions

View file

@ -278,7 +278,7 @@ const helper = {};
helper.withFastCommit = async (fn) => {
const incorp = () => helper.padChrome$.padeditor.ace.callWithAce(
(ace) => ace.ace_inCallStackIfNecessary('helper.edit', () => ace.ace_fastIncorp()));
const cc = helper.padChrome$.window.pad.collabClient;
const cc = helper.padChrome$.window.require('ep_etherpad-lite/static/js/pad').pad.collabClient;
const {commitDelay} = cc;
cc.commitDelay = 0;
try {

View file

@ -5,7 +5,8 @@
* that are visible in tests
*/
helper.spyOnSocketIO = () => {
helper.contentWindow().pad.socket.on('message', (msg) => {
const {pad} = helper.contentWindow().require('ep_etherpad-lite/static/js/pad');
pad.socket.on('message', (msg) => {
if (msg.type !== 'COLLABROOM') return;
if (msg.data.type === 'ACCEPT_COMMIT') {
helper.commits.push(msg);

View file

@ -4,6 +4,8 @@ describe('Messages in the COLLABROOM', function () {
const user1Text = 'text created by user 1';
const user2Text = 'text created by user 2';
const getPadObj = () => helper.padChrome$.window.require('ep_etherpad-lite/static/js/pad').pad;
const triggerEvent = (eventName) => {
const event = new helper.padInner$.Event(eventName);
helper.padInner$('#innerdocbody').trigger(event);
@ -36,7 +38,7 @@ describe('Messages in the COLLABROOM', function () {
// User 1 starts sending a change to the server.
let sendStarted;
const finishSend = (() => {
const socketJsonObj = helper.padChrome$.window.pad.socket.json;
const socketJsonObj = getPadObj().socket.json;
const sendBackup = socketJsonObj.send;
let startSend;
sendStarted = new Promise((resolve) => { startSend = resolve; });
@ -60,7 +62,7 @@ describe('Messages in the COLLABROOM', function () {
// User 1 receives a change from user 2. (User 1 will not incorporate the change until the
// composition is completed.)
const user2ChangeArrivedAtUser1 = new Promise((resolve) => {
const cc = helper.padChrome$.window.pad.collabClient;
const cc = getPadObj().collabClient;
const origHM = cc.handleMessageFromServer;
cc.handleMessageFromServer = (evt) => {
if (evt.type === 'COLLABROOM' && evt.data.type === 'NEW_CHANGES') {

View file

@ -8,7 +8,8 @@ describe('Pad modal', function () {
await helper.aNewPad();
// force a "slowcommit" error
helper.padChrome$.window.pad.handleChannelStateChange('DISCONNECTED', 'slowcommit');
const {pad} = helper.padChrome$.window.require('ep_etherpad-lite/static/js/pad');
pad.handleChannelStateChange('DISCONNECTED', 'slowcommit');
// wait for modal to be displayed
const $modal = helper.padChrome$(MODAL_SELECTOR);