tests: Refine frontend tests

* Switch from `helper.newPad()` to `helper.aNewPad()`.
  * Promisify.
  * Delete redundant logic.
  * Lint fixes.
This commit is contained in:
Richard Hansen 2021-03-31 21:14:02 -04:00 committed by webzwo0i
parent 3790c0e41c
commit bbf89dfcf9
35 changed files with 697 additions and 842 deletions

View file

@ -5,9 +5,9 @@ describe('select formatting buttons when selection has style applied', function
const SHORTCUT_KEYS = ['I', 'B', 'U', '5']; // italic, bold, underline, strikethrough
const FIRST_LINE = 0;
before(function (cb) {
helper.newPad(cb);
before(async function () {
this.timeout(60000);
await helper.aNewPad();
});
const applyStyleOnLine = function (style, line) {
@ -43,45 +43,42 @@ describe('select formatting buttons when selection has style applied', function
};
const testIfFormattingButtonIsDeselected = function (style) {
it(`deselects the ${style} button`, function (done) {
it(`deselects the ${style} button`, async function () {
this.timeout(100);
helper.waitFor(() => isButtonSelected(style) === false).done(done);
await helper.waitForPromise(() => !isButtonSelected(style));
});
};
const testIfFormattingButtonIsSelected = function (style) {
it(`selects the ${style} button`, function (done) {
it(`selects the ${style} button`, async function () {
this.timeout(100);
helper.waitFor(() => isButtonSelected(style)).done(done);
await helper.waitForPromise(() => isButtonSelected(style));
});
};
const applyStyleOnLineAndSelectIt = function (line, style, cb) {
applyStyleOnLineOnFullLineAndRemoveSelection(line, style, selectLine, cb);
const applyStyleOnLineAndSelectIt = async function (line, style) {
await applyStyleOnLineOnFullLineAndRemoveSelection(line, style, selectLine);
};
const applyStyleOnLineAndPlaceCaretOnit = function (line, style, cb) {
applyStyleOnLineOnFullLineAndRemoveSelection(line, style, placeCaretOnLine, cb);
const applyStyleOnLineAndPlaceCaretOnit = async function (line, style) {
await applyStyleOnLineOnFullLineAndRemoveSelection(line, style, placeCaretOnLine);
};
const applyStyleOnLineOnFullLineAndRemoveSelection = function (line, style, selectTarget, cb) {
const applyStyleOnLineOnFullLineAndRemoveSelection = async function (line, style, selectTarget) {
// see if line html has changed
const inner$ = helper.padInner$;
const oldLineHTML = inner$.find('div')[line];
applyStyleOnLine(style, line);
helper.waitFor(() => {
await helper.waitForPromise(() => {
const lineHTML = inner$.find('div')[line];
return lineHTML !== oldLineHTML;
});
// remove selection from previous line
selectLine(line + 1);
// setTimeout(function() {
// select the text or place the caret on a position that
// has the formatting text applied previously
selectTarget(line);
cb();
// }, 1000);
};
const pressFormattingShortcutOnSelection = async function (key) {
@ -103,9 +100,9 @@ describe('select formatting buttons when selection has style applied', function
STYLES.forEach((style) => {
context(`when selection is in a text with ${style} applied`, function () {
before(function (done) {
before(async function () {
this.timeout(4000);
applyStyleOnLineAndSelectIt(FIRST_LINE, style, done);
await applyStyleOnLineAndSelectIt(FIRST_LINE, style);
});
after(async function () {
@ -116,9 +113,9 @@ describe('select formatting buttons when selection has style applied', function
});
context(`when caret is in a position with ${style} applied`, function () {
before(function (done) {
before(async function () {
this.timeout(4000);
applyStyleOnLineAndPlaceCaretOnit(FIRST_LINE, style, done);
await applyStyleOnLineAndPlaceCaretOnit(FIRST_LINE, style);
});
after(async function () {