lint: lint and various fixes of frontend test specs

This commit is contained in:
John McLear 2021-02-07 06:39:03 +00:00 committed by GitHub
parent da10d42183
commit f8a19c4527
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 261 additions and 240 deletions

View file

@ -297,7 +297,7 @@ console.log(inner$);
}); });
*/ */
}); });
/*
// generates a random document with random content on n lines // generates a random document with random content on n lines
const prepareDocument = (n, target) => { const prepareDocument = (n, target) => {
let i = 0; let i = 0;
@ -350,3 +350,4 @@ const caretPosition = ($) => {
pos.x = pos.anchorNode.parentElement.offsetLeft; pos.x = pos.anchorNode.parentElement.offsetLeft;
return pos; return pos;
}; };
*/

View file

@ -23,9 +23,13 @@ describe('drag and drop', function () {
}); });
context('and user triggers UNDO', function () { context('and user triggers UNDO', function () {
before(function () { before(async function () {
const originalHTML = helper.padInner$('body').html();
const $undoButton = helper.padChrome$('.buttonicon-undo'); const $undoButton = helper.padChrome$('.buttonicon-undo');
$undoButton.click(); $undoButton.click();
await helper.waitForPromise(
() => originalHTML !== helper.padInner$('body').html()
);
}); });
it('moves text back to its original place', function (done) { it('moves text back to its original place', function (done) {
@ -58,9 +62,13 @@ describe('drag and drop', function () {
}); });
context('and user triggers UNDO', function () { context('and user triggers UNDO', function () {
before(function () { before(async function () {
const originalHTML = helper.padInner$('body').html();
const $undoButton = helper.padChrome$('.buttonicon-undo'); const $undoButton = helper.padChrome$('.buttonicon-undo');
$undoButton.click(); $undoButton.click();
await helper.waitForPromise(
() => originalHTML !== helper.padInner$('body').html()
);
}); });
it('moves text back to its original place', function (done) { it('moves text back to its original place', function (done) {

View file

@ -19,9 +19,12 @@ describe('assign ordered list', function () {
context('when user presses Ctrl+Shift+N', function () { context('when user presses Ctrl+Shift+N', function () {
context('and pad shortcut is enabled', function () { context('and pad shortcut is enabled', function () {
beforeEach(function () { beforeEach(async function () {
const originalHTML = helper.padInner$('body').html();
makeSureShortcutIsEnabled('cmdShiftN'); makeSureShortcutIsEnabled('cmdShiftN');
triggerCtrlShiftShortcut('N'); triggerCtrlShiftShortcut('N');
await helper.waitForPromise(
() => helper.padInner$('body').html !== originalHTML);
}); });
it('inserts unordered list', function (done) { it('inserts unordered list', function (done) {
@ -30,9 +33,12 @@ describe('assign ordered list', function () {
}); });
context('and pad shortcut is disabled', function () { context('and pad shortcut is disabled', function () {
beforeEach(function () { beforeEach(async function () {
const originalHTML = helper.padInner$('body').html();
makeSureShortcutIsDisabled('cmdShiftN'); makeSureShortcutIsDisabled('cmdShiftN');
triggerCtrlShiftShortcut('N'); triggerCtrlShiftShortcut('N');
await helper.waitForPromise(
() => helper.padInner$('body').html !== originalHTML);
}); });
it('does not insert unordered list', function (done) { it('does not insert unordered list', function (done) {
@ -48,9 +54,12 @@ describe('assign ordered list', function () {
context('when user presses Ctrl+Shift+1', function () { context('when user presses Ctrl+Shift+1', function () {
context('and pad shortcut is enabled', function () { context('and pad shortcut is enabled', function () {
beforeEach(function () { beforeEach(async function () {
const originalHTML = helper.padInner$('body').html();
makeSureShortcutIsEnabled('cmdShift1'); makeSureShortcutIsEnabled('cmdShift1');
triggerCtrlShiftShortcut('1'); triggerCtrlShiftShortcut('1');
await helper.waitForPromise(
() => helper.padInner$('body').html !== originalHTML);
}); });
it('inserts unordered list', function (done) { it('inserts unordered list', function (done) {
@ -59,9 +68,12 @@ describe('assign ordered list', function () {
}); });
context('and pad shortcut is disabled', function () { context('and pad shortcut is disabled', function () {
beforeEach(function () { beforeEach(async function () {
const originalHTML = helper.padInner$('body').html();
makeSureShortcutIsDisabled('cmdShift1'); makeSureShortcutIsDisabled('cmdShift1');
triggerCtrlShiftShortcut('1'); triggerCtrlShiftShortcut('1');
await helper.waitForPromise(
() => helper.padInner$('body').html !== originalHTML);
}); });
it('does not insert unordered list', function (done) { it('does not insert unordered list', function (done) {
@ -117,7 +129,6 @@ describe('assign ordered list', function () {
const makeSureShortcutIsEnabled = (shortcut) => { const makeSureShortcutIsEnabled = (shortcut) => {
helper.padChrome$.window.clientVars.padShortcutEnabled[shortcut] = true; helper.padChrome$.window.clientVars.padShortcutEnabled[shortcut] = true;
}; };
});
describe('Pressing Tab in an OL increases and decreases indentation', function () { describe('Pressing Tab in an OL increases and decreases indentation', function () {
// create a new pad before each test run // create a new pad before each test run
@ -185,3 +196,4 @@ describe('Pressing indent/outdent button in an OL increases and ' +
helper.waitFor(() => inner$('div').first().find('.list-number1').length === 1).done(done); helper.waitFor(() => inner$('div').first().find('.list-number1').length === 1).done(done);
}); });
}); });
});

View file

@ -24,14 +24,11 @@ describe('Pad modal', function () {
}); });
context('and user clicks on editor', function () { context('and user clicks on editor', function () {
beforeEach(function () {
clickOnPadInner();
});
it('does not close the modal', function (done) { it('does not close the modal', function (done) {
clickOnPadInner();
const $modal = helper.padChrome$(MODAL_SELECTOR); const $modal = helper.padChrome$(MODAL_SELECTOR);
const modalIsVisible = $modal.hasClass('popup-show'); const modalIsVisible = $modal.hasClass('popup-show');
helper.waitForPromise(() => $modal.hasClass('popup-show') === true);
expect(modalIsVisible).to.be(true); expect(modalIsVisible).to.be(true);
done(); done();
@ -39,14 +36,13 @@ describe('Pad modal', function () {
}); });
context('and user clicks on pad outer', function () { context('and user clicks on pad outer', function () {
beforeEach(function () {
clickOnPadOuter();
});
it('does not close the modal', function (done) { it('does not close the modal', function (done) {
const $modal = helper.padChrome$(MODAL_SELECTOR); const $modal = helper.padChrome$(MODAL_SELECTOR);
const modalIsVisible = $modal.hasClass('popup-show'); const modalIsVisible = $modal.hasClass('popup-show');
clickOnPadOuter();
helper.waitForPromise(() => $modal.hasClass('popup-show') === true);
expect(modalIsVisible).to.be(true); expect(modalIsVisible).to.be(true);
done(); done();
@ -73,22 +69,18 @@ describe('Pad modal', function () {
}); });
*/ */
context('and user clicks on editor', function () { context('and user clicks on editor', function () {
beforeEach(function () {
clickOnPadInner();
});
it('closes the modal', function (done) { it('closes the modal', function (done) {
clickOnPadInner();
helper.waitForPromise(() => isModalOpened(MODAL_SELECTOR) === false);
expect(isModalOpened(MODAL_SELECTOR)).to.be(false); expect(isModalOpened(MODAL_SELECTOR)).to.be(false);
done(); done();
}); });
}); });
context('and user clicks on pad outer', function () { context('and user clicks on pad outer', function () {
beforeEach(function () {
clickOnPadOuter();
});
it('closes the modal', function (done) { it('closes the modal', function (done) {
clickOnPadOuter();
helper.waitForPromise(() => isModalOpened(MODAL_SELECTOR) === false);
expect(isModalOpened(MODAL_SELECTOR)).to.be(false); expect(isModalOpened(MODAL_SELECTOR)).to.be(false);
done(); done();
}); });

View file

@ -45,12 +45,12 @@ describe('undo button then redo button', function () {
const modifiedValue = $firstTextElement.text(); // get the modified value const modifiedValue = $firstTextElement.text(); // get the modified value
expect(modifiedValue).not.to.be(originalValue); // expect the value to change expect(modifiedValue).not.to.be(originalValue); // expect the value to change
let e = inner$.Event(helper.evtType); let e = new inner$.Event(helper.evtType);
e.ctrlKey = true; // Control key e.ctrlKey = true; // Control key
e.which = 90; // z e.which = 90; // z
inner$('#innerdocbody').trigger(e); inner$('#innerdocbody').trigger(e);
e = inner$.Event(helper.evtType); e = new inner$.Event(helper.evtType);
e.ctrlKey = true; // Control key e.ctrlKey = true; // Control key
e.which = 121; // y e.which = 121; // y
inner$('#innerdocbody').trigger(e); inner$('#innerdocbody').trigger(e);

View file

@ -2,12 +2,15 @@
describe('scrolls to line', function () { describe('scrolls to line', function () {
// create a new pad with URL hash set before each test run // create a new pad with URL hash set before each test run
beforeEach(function (cb) { before(async function () {
helper.newPad({ this.timeout(60000);
await new Promise((resolve, reject) => helper.newPad({
cb: (err) => {
if (err != null) return reject(err);
resolve();
},
hash: 'L4', hash: 'L4',
cb, }));
});
this.timeout(10000);
}); });
it('Scrolls down to Line 4', async function () { it('Scrolls down to Line 4', async function () {
@ -19,16 +22,18 @@ describe('scrolls to line', function () {
return (topOffset >= 100); return (topOffset >= 100);
}); });
}); });
});
describe('doesnt break on weird hash input', function () { describe('doesnt break on weird hash input', function () {
// create a new pad with URL hash set before each test run // create a new pad with URL hash set before each test run
beforeEach(function (cb) { before(async function () {
helper.newPad({ this.timeout(60000);
await new Promise((resolve, reject) => helper.newPad({
cb: (err) => {
if (err != null) return reject(err);
resolve();
},
hash: '#DEEZ123123NUTS', hash: '#DEEZ123123NUTS',
cb, }));
});
this.timeout(10000);
}); });
it('Does NOT change scroll', async function () { it('Does NOT change scroll', async function () {
@ -41,3 +46,4 @@ describe('doesnt break on weird hash input', function () {
}); });
}); });
}); });
});

View file

@ -35,9 +35,11 @@ describe('select formatting buttons when selection has style applied', function
$line.sendkeys('{leftarrow}'); $line.sendkeys('{leftarrow}');
}; };
const undo = function () { const undo = async function () {
const originalHTML = helper.padInner$('body').html();
const $undoButton = helper.padChrome$('.buttonicon-undo'); const $undoButton = helper.padChrome$('.buttonicon-undo');
$undoButton.click(); $undoButton.click();
await helper.waitFor(() => originalHTML !== helper.padInner$('body').html());
}; };
const testIfFormattingButtonIsDeselected = function (style) { const testIfFormattingButtonIsDeselected = function (style) {
@ -80,9 +82,11 @@ describe('select formatting buttons when selection has style applied', function
// }, 1000); // }, 1000);
}; };
const pressFormattingShortcutOnSelection = function (key) { const pressFormattingShortcutOnSelection = async function (key) {
const inner$ = helper.padInner$; const inner$ = helper.padInner$;
const originalHTML = helper.padInner$('body').html();
helper.waitFor(() => originalHTML !== helper.padInner$('body').html());
// get the first text element out of the inner iframe // get the first text element out of the inner iframe
const $firstTextElement = inner$('div').first(); const $firstTextElement = inner$('div').first();
@ -93,6 +97,8 @@ describe('select formatting buttons when selection has style applied', function
e.ctrlKey = true; // Control key e.ctrlKey = true; // Control key
e.which = key.charCodeAt(0); // I, U, B, 5 e.which = key.charCodeAt(0); // I, U, B, 5
inner$('#innerdocbody').trigger(e); inner$('#innerdocbody').trigger(e);
await helper.waitForPromise(
() => originalHTML !== helper.padInner$('body').html());
}; };
STYLES.forEach((style) => { STYLES.forEach((style) => {
@ -102,8 +108,8 @@ describe('select formatting buttons when selection has style applied', function
applyStyleOnLineAndSelectIt(FIRST_LINE, style, done); applyStyleOnLineAndSelectIt(FIRST_LINE, style, done);
}); });
after(function () { after(async function () {
undo(); await undo();
}); });
testIfFormattingButtonIsSelected(style); testIfFormattingButtonIsSelected(style);
@ -115,8 +121,8 @@ describe('select formatting buttons when selection has style applied', function
applyStyleOnLineAndPlaceCaretOnit(FIRST_LINE, style, done); applyStyleOnLineAndPlaceCaretOnit(FIRST_LINE, style, done);
}); });
after(function () { after(async function () {
undo(); await undo();
}); });
testIfFormattingButtonIsSelected(style); testIfFormattingButtonIsSelected(style);
@ -125,33 +131,27 @@ describe('select formatting buttons when selection has style applied', function
context('when user applies a style and the selection does not change', function () { context('when user applies a style and the selection does not change', function () {
const style = STYLES[0]; // italic const style = STYLES[0]; // italic
before(function () {
applyStyleOnLine(style, FIRST_LINE);
});
// clean the style applied it('selects the style button', async function () {
after(function () {
applyStyleOnLine(style, FIRST_LINE); applyStyleOnLine(style, FIRST_LINE);
}); await helper.waitForPromise(() => isButtonSelected(style) === true);
it('selects the style button', function (done) {
expect(isButtonSelected(style)).to.be(true); expect(isButtonSelected(style)).to.be(true);
done(); applyStyleOnLine(style, FIRST_LINE);
}); });
}); });
SHORTCUT_KEYS.forEach((key, index) => { SHORTCUT_KEYS.forEach((key, index) => {
const styleOfTheShortcut = STYLES[index]; // italic, bold, ... const styleOfTheShortcut = STYLES[index]; // italic, bold, ...
context(`when user presses CMD + ${key}`, function () { context(`when user presses CMD + ${key}`, function () {
before(function () { before(async function () {
pressFormattingShortcutOnSelection(key); await pressFormattingShortcutOnSelection(key);
}); });
testIfFormattingButtonIsSelected(styleOfTheShortcut); testIfFormattingButtonIsSelected(styleOfTheShortcut);
context(`and user presses CMD + ${key} again`, function () { context(`and user presses CMD + ${key} again`, function () {
before(function () { before(async function () {
pressFormattingShortcutOnSelection(key); await pressFormattingShortcutOnSelection(key);
}); });
testIfFormattingButtonIsDeselected(styleOfTheShortcut); testIfFormattingButtonIsDeselected(styleOfTheShortcut);

View file

@ -31,7 +31,6 @@ describe('assign unordered list', function () {
}); });
}); });
}); });
});
describe('unassign unordered list', function () { describe('unassign unordered list', function () {
// create a new pad before each test run // create a new pad before each test run
@ -119,7 +118,7 @@ describe('Pressing Tab in an UL increases and decreases indentation', function (
const $insertorderedlistButton = chrome$('.buttonicon-insertunorderedlist'); const $insertorderedlistButton = chrome$('.buttonicon-insertunorderedlist');
$insertorderedlistButton.click(); $insertorderedlistButton.click();
const e = inner$.Event(helper.evtType); const e = new inner$.Event(helper.evtType);
e.keyCode = 9; // tab e.keyCode = 9; // tab
inner$('#innerdocbody').trigger(e); inner$('#innerdocbody').trigger(e);
@ -163,3 +162,4 @@ describe('Pressing indent/outdent button in an UL increases and decreases indent
helper.waitFor(() => inner$('div').first().find('.list-bullet1').length === 1).done(done); helper.waitFor(() => inner$('div').first().find('.list-bullet1').length === 1).done(done);
}); });
}); });
});

View file

@ -34,9 +34,11 @@ describe('Automatic pad reload on Force Reconnect message', function () {
}); });
context('and user clicks on Cancel', function () { context('and user clicks on Cancel', function () {
beforeEach(function () { beforeEach(async function () {
const $errorMessageModal = helper.padChrome$('#connectivity .userdup'); const $errorMessageModal = helper.padChrome$('#connectivity .userdup');
$errorMessageModal.find('#cancelreconnect').click(); $errorMessageModal.find('#cancelreconnect').click();
await helper.waitForPromise(
() => helper.padChrome$('#connectivity .userdup').is(':visible') === true);
}); });
it('does not show Cancel button nor timer anymore', function (done) { it('does not show Cancel button nor timer anymore', function (done) {
@ -54,16 +56,16 @@ describe('Automatic pad reload on Force Reconnect message', function () {
context('and user does not click on Cancel until timer expires', function () { context('and user does not click on Cancel until timer expires', function () {
let padWasReloaded = false; let padWasReloaded = false;
beforeEach(function () { beforeEach(async function () {
$originalPadFrame.one('load', () => { $originalPadFrame.one('load', () => {
padWasReloaded = true; padWasReloaded = true;
}); });
}); });
it('reloads the pad', function (done) { it('reloads the pad', function (done) {
helper.waitFor(() => padWasReloaded, 5000).done(done); helper.waitFor(() => padWasReloaded, 10000).done(done);
this.timeout(5000); this.timeout(10000);
}); });
}); });
}); });