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
const prepareDocument = (n, target) => {
let i = 0;
@ -350,3 +350,4 @@ const caretPosition = ($) => {
pos.x = pos.anchorNode.parentElement.offsetLeft;
return pos;
};
*/

View file

@ -23,9 +23,13 @@ describe('drag and drop', function () {
});
context('and user triggers UNDO', function () {
before(function () {
before(async function () {
const originalHTML = helper.padInner$('body').html();
const $undoButton = helper.padChrome$('.buttonicon-undo');
$undoButton.click();
await helper.waitForPromise(
() => originalHTML !== helper.padInner$('body').html()
);
});
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 () {
before(function () {
before(async function () {
const originalHTML = helper.padInner$('body').html();
const $undoButton = helper.padChrome$('.buttonicon-undo');
$undoButton.click();
await helper.waitForPromise(
() => originalHTML !== helper.padInner$('body').html()
);
});
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('and pad shortcut is enabled', function () {
beforeEach(function () {
beforeEach(async function () {
const originalHTML = helper.padInner$('body').html();
makeSureShortcutIsEnabled('cmdShiftN');
triggerCtrlShiftShortcut('N');
await helper.waitForPromise(
() => helper.padInner$('body').html !== originalHTML);
});
it('inserts unordered list', function (done) {
@ -30,9 +33,12 @@ describe('assign ordered list', function () {
});
context('and pad shortcut is disabled', function () {
beforeEach(function () {
beforeEach(async function () {
const originalHTML = helper.padInner$('body').html();
makeSureShortcutIsDisabled('cmdShiftN');
triggerCtrlShiftShortcut('N');
await helper.waitForPromise(
() => helper.padInner$('body').html !== originalHTML);
});
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('and pad shortcut is enabled', function () {
beforeEach(function () {
beforeEach(async function () {
const originalHTML = helper.padInner$('body').html();
makeSureShortcutIsEnabled('cmdShift1');
triggerCtrlShiftShortcut('1');
await helper.waitForPromise(
() => helper.padInner$('body').html !== originalHTML);
});
it('inserts unordered list', function (done) {
@ -59,9 +68,12 @@ describe('assign ordered list', function () {
});
context('and pad shortcut is disabled', function () {
beforeEach(function () {
beforeEach(async function () {
const originalHTML = helper.padInner$('body').html();
makeSureShortcutIsDisabled('cmdShift1');
triggerCtrlShiftShortcut('1');
await helper.waitForPromise(
() => helper.padInner$('body').html !== originalHTML);
});
it('does not insert unordered list', function (done) {
@ -117,9 +129,8 @@ describe('assign ordered list', function () {
const makeSureShortcutIsEnabled = (shortcut) => {
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
beforeEach(function (cb) {
helper.newPad(cb);
@ -150,10 +161,10 @@ describe('Pressing Tab in an OL increases and decreases indentation', function (
helper.waitFor(() => inner$('div').first().find('.list-number1').length === 1).done(done);
});
});
});
describe('Pressing indent/outdent button in an OL increases and ' +
describe('Pressing indent/outdent button in an OL increases and ' +
'decreases indentation and bullet / ol formatting', function () {
// create a new pad before each test run
beforeEach(function (cb) {
@ -184,4 +195,5 @@ describe('Pressing indent/outdent button in an OL increases and ' +
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 () {
beforeEach(function () {
clickOnPadInner();
});
it('does not close the modal', function (done) {
clickOnPadInner();
const $modal = helper.padChrome$(MODAL_SELECTOR);
const modalIsVisible = $modal.hasClass('popup-show');
helper.waitForPromise(() => $modal.hasClass('popup-show') === true);
expect(modalIsVisible).to.be(true);
done();
@ -39,14 +36,13 @@ describe('Pad modal', function () {
});
context('and user clicks on pad outer', function () {
beforeEach(function () {
clickOnPadOuter();
});
it('does not close the modal', function (done) {
const $modal = helper.padChrome$(MODAL_SELECTOR);
const modalIsVisible = $modal.hasClass('popup-show');
clickOnPadOuter();
helper.waitForPromise(() => $modal.hasClass('popup-show') === true);
expect(modalIsVisible).to.be(true);
done();
@ -73,22 +69,18 @@ describe('Pad modal', function () {
});
*/
context('and user clicks on editor', function () {
beforeEach(function () {
clickOnPadInner();
});
it('closes the modal', function (done) {
clickOnPadInner();
helper.waitForPromise(() => isModalOpened(MODAL_SELECTOR) === false);
expect(isModalOpened(MODAL_SELECTOR)).to.be(false);
done();
});
});
context('and user clicks on pad outer', function () {
beforeEach(function () {
clickOnPadOuter();
});
it('closes the modal', function (done) {
clickOnPadOuter();
helper.waitForPromise(() => isModalOpened(MODAL_SELECTOR) === false);
expect(isModalOpened(MODAL_SELECTOR)).to.be(false);
done();
});

View file

@ -45,12 +45,12 @@ describe('undo button then redo button', function () {
const modifiedValue = $firstTextElement.text(); // get the modified value
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.which = 90; // z
inner$('#innerdocbody').trigger(e);
e = inner$.Event(helper.evtType);
e = new inner$.Event(helper.evtType);
e.ctrlKey = true; // Control key
e.which = 121; // y
inner$('#innerdocbody').trigger(e);

View file

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

View file

@ -35,9 +35,11 @@ describe('select formatting buttons when selection has style applied', function
$line.sendkeys('{leftarrow}');
};
const undo = function () {
const undo = async function () {
const originalHTML = helper.padInner$('body').html();
const $undoButton = helper.padChrome$('.buttonicon-undo');
$undoButton.click();
await helper.waitFor(() => originalHTML !== helper.padInner$('body').html());
};
const testIfFormattingButtonIsDeselected = function (style) {
@ -80,9 +82,11 @@ describe('select formatting buttons when selection has style applied', function
// }, 1000);
};
const pressFormattingShortcutOnSelection = function (key) {
const pressFormattingShortcutOnSelection = async function (key) {
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
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.which = key.charCodeAt(0); // I, U, B, 5
inner$('#innerdocbody').trigger(e);
await helper.waitForPromise(
() => originalHTML !== helper.padInner$('body').html());
};
STYLES.forEach((style) => {
@ -102,8 +108,8 @@ describe('select formatting buttons when selection has style applied', function
applyStyleOnLineAndSelectIt(FIRST_LINE, style, done);
});
after(function () {
undo();
after(async function () {
await undo();
});
testIfFormattingButtonIsSelected(style);
@ -115,8 +121,8 @@ describe('select formatting buttons when selection has style applied', function
applyStyleOnLineAndPlaceCaretOnit(FIRST_LINE, style, done);
});
after(function () {
undo();
after(async function () {
await undo();
});
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 () {
const style = STYLES[0]; // italic
before(function () {
applyStyleOnLine(style, FIRST_LINE);
});
// clean the style applied
after(function () {
it('selects the style button', async function () {
applyStyleOnLine(style, FIRST_LINE);
});
it('selects the style button', function (done) {
await helper.waitForPromise(() => isButtonSelected(style) === true);
expect(isButtonSelected(style)).to.be(true);
done();
applyStyleOnLine(style, FIRST_LINE);
});
});
SHORTCUT_KEYS.forEach((key, index) => {
const styleOfTheShortcut = STYLES[index]; // italic, bold, ...
context(`when user presses CMD + ${key}`, function () {
before(function () {
pressFormattingShortcutOnSelection(key);
before(async function () {
await pressFormattingShortcutOnSelection(key);
});
testIfFormattingButtonIsSelected(styleOfTheShortcut);
context(`and user presses CMD + ${key} again`, function () {
before(function () {
pressFormattingShortcutOnSelection(key);
before(async function () {
await pressFormattingShortcutOnSelection(key);
});
testIfFormattingButtonIsDeselected(styleOfTheShortcut);

View file

@ -31,9 +31,8 @@ describe('assign unordered list', function () {
});
});
});
});
describe('unassign unordered list', function () {
describe('unassign unordered list', function () {
// create a new pad before each test run
beforeEach(function (cb) {
helper.newPad(cb);
@ -65,10 +64,10 @@ describe('unassign unordered list', function () {
});
});
});
});
});
describe('keep unordered list on enter key', function () {
describe('keep unordered list on enter key', function () {
// create a new pad before each test run
beforeEach(function (cb) {
helper.newPad(cb);
@ -97,9 +96,9 @@ describe('keep unordered list on enter key', function () {
done();
});
});
});
});
describe('Pressing Tab in an UL increases and decreases indentation', function () {
describe('Pressing Tab in an UL increases and decreases indentation', function () {
// create a new pad before each test run
beforeEach(function (cb) {
helper.newPad(cb);
@ -119,7 +118,7 @@ describe('Pressing Tab in an UL increases and decreases indentation', function (
const $insertorderedlistButton = chrome$('.buttonicon-insertunorderedlist');
$insertorderedlistButton.click();
const e = inner$.Event(helper.evtType);
const e = new inner$.Event(helper.evtType);
e.keyCode = 9; // tab
inner$('#innerdocbody').trigger(e);
@ -130,9 +129,9 @@ describe('Pressing Tab in an UL increases and decreases indentation', function (
helper.waitFor(() => inner$('div').first().find('.list-bullet1').length === 1).done(done);
});
});
});
describe('Pressing indent/outdent button in an UL increases and decreases indentation ' +
describe('Pressing indent/outdent button in an UL increases and decreases indentation ' +
'and bullet / ol formatting', function () {
// create a new pad before each test run
beforeEach(function (cb) {
@ -162,4 +161,5 @@ describe('Pressing indent/outdent button in an UL increases and decreases indent
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 () {
beforeEach(function () {
beforeEach(async function () {
const $errorMessageModal = helper.padChrome$('#connectivity .userdup');
$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) {
@ -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 () {
let padWasReloaded = false;
beforeEach(function () {
beforeEach(async function () {
$originalPadFrame.one('load', () => {
padWasReloaded = true;
});
});
it('reloads the pad', function (done) {
helper.waitFor(() => padWasReloaded, 5000).done(done);
helper.waitFor(() => padWasReloaded, 10000).done(done);
this.timeout(5000);
this.timeout(10000);
});
});
});