etherpad-lite/src/tests/frontend/specs/select_formatting_buttons.js

158 lines
5 KiB
JavaScript
Raw Normal View History

Low hanging lint frontend tests (#4695) * lint: low hanging specs/alphabet.js * lint: low hanging specs/authorship_of_editions.js * lint: low hanging specs/bold.js * lint: low hanging specs/caret.js * lint: low hanging specs/change_user_color.js * lint: low hanging specs/change_user_name.js * lint: low hanging specs/chat.js * lint: low hanging specs/chat_load_messages.js * lint: low hanging specs/clear_authorship_colors.js * lint: low hanging specs/delete.js * lint: low hanging specs/drag_and_drop.js * lint: low hanging specs/embed_value.js * lint: low hanging specs/enter.js * lint: low hanging specs/font_type.js * lint: low hanging specs/helper.js * lint: low hanging specs/importexport.js * lint: low hanging specs/importindents.js * lint: low hanging specs/indentation.js * lint: low hanging specs/italic.js * lint: low hanging specs/language.js * lint: low hanging specs/multiple_authors_clear_authorship_colors.js * lint: low hanging specs/ordered_list.js * lint: low hanging specs/pad_modal.js * lint: low hanging specs/redo.js * lint: low hanging specs/responsiveness.js * lint: low hanging specs/select_formatting_buttons.js * lint: low hanging specs/strikethrough.js * lint: low hanging specs/timeslider.js * lint: low hanging specs/timeslider_labels.js * lint: low hanging specs/timeslider_numeric_padID.js * lint: low hanging specs/timeslider_revisions.js * lint: low hanging specs/undo.js * lint: low hanging specs/unordered_list.js * lint: low hanging specs/xxauto_reconnect.js * lint: attempt to do remote_runner.js * lint: helper linting * lint: rate limit linting * use constructor for Event to make eslint happier * for squash: lint fix refinements * for squash: lint fix refinements Co-authored-by: Richard Hansen <rhansen@rhansen.org>
2021-02-01 20:23:14 +00:00
'use strict';
describe('select formatting buttons when selection has style applied', function () {
const STYLES = ['italic', 'bold', 'underline', 'strikethrough'];
const SHORTCUT_KEYS = ['I', 'B', 'U', '5']; // italic, bold, underline, strikethrough
const FIRST_LINE = 0;
before(async function () {
this.timeout(60000);
await helper.aNewPad();
});
const applyStyleOnLine = function (style, line) {
const chrome$ = helper.padChrome$;
selectLine(line);
const $formattingButton = chrome$(`.buttonicon-${style}`);
$formattingButton.click();
};
const isButtonSelected = function (style) {
const chrome$ = helper.padChrome$;
const $formattingButton = chrome$(`.buttonicon-${style}`);
return $formattingButton.parent().hasClass('selected');
};
Low hanging lint frontend tests (#4695) * lint: low hanging specs/alphabet.js * lint: low hanging specs/authorship_of_editions.js * lint: low hanging specs/bold.js * lint: low hanging specs/caret.js * lint: low hanging specs/change_user_color.js * lint: low hanging specs/change_user_name.js * lint: low hanging specs/chat.js * lint: low hanging specs/chat_load_messages.js * lint: low hanging specs/clear_authorship_colors.js * lint: low hanging specs/delete.js * lint: low hanging specs/drag_and_drop.js * lint: low hanging specs/embed_value.js * lint: low hanging specs/enter.js * lint: low hanging specs/font_type.js * lint: low hanging specs/helper.js * lint: low hanging specs/importexport.js * lint: low hanging specs/importindents.js * lint: low hanging specs/indentation.js * lint: low hanging specs/italic.js * lint: low hanging specs/language.js * lint: low hanging specs/multiple_authors_clear_authorship_colors.js * lint: low hanging specs/ordered_list.js * lint: low hanging specs/pad_modal.js * lint: low hanging specs/redo.js * lint: low hanging specs/responsiveness.js * lint: low hanging specs/select_formatting_buttons.js * lint: low hanging specs/strikethrough.js * lint: low hanging specs/timeslider.js * lint: low hanging specs/timeslider_labels.js * lint: low hanging specs/timeslider_numeric_padID.js * lint: low hanging specs/timeslider_revisions.js * lint: low hanging specs/undo.js * lint: low hanging specs/unordered_list.js * lint: low hanging specs/xxauto_reconnect.js * lint: attempt to do remote_runner.js * lint: helper linting * lint: rate limit linting * use constructor for Event to make eslint happier * for squash: lint fix refinements * for squash: lint fix refinements Co-authored-by: Richard Hansen <rhansen@rhansen.org>
2021-02-01 20:23:14 +00:00
const selectLine = function (lineNumber, offsetStart, offsetEnd) {
const inner$ = helper.padInner$;
const $line = inner$('div').eq(lineNumber);
helper.selectLines($line, $line, offsetStart, offsetEnd);
};
const placeCaretOnLine = function (lineNumber) {
const inner$ = helper.padInner$;
const $line = inner$('div').eq(lineNumber);
$line.sendkeys('{leftarrow}');
};
const undo = async function () {
const originalHTML = helper.padInner$('body').html();
const $undoButton = helper.padChrome$('.buttonicon-undo');
$undoButton.click();
await helper.waitForPromise(() => helper.padInner$('body').html() !== originalHTML);
};
const testIfFormattingButtonIsDeselected = function (style) {
it(`deselects the ${style} button`, async function () {
this.timeout(100);
await helper.waitForPromise(() => !isButtonSelected(style));
});
};
const testIfFormattingButtonIsSelected = function (style) {
it(`selects the ${style} button`, async function () {
this.timeout(100);
await helper.waitForPromise(() => isButtonSelected(style));
});
};
const applyStyleOnLineAndSelectIt = async function (line, style) {
await applyStyleOnLineOnFullLineAndRemoveSelection(line, style, selectLine);
};
const applyStyleOnLineAndPlaceCaretOnit = async function (line, style) {
await applyStyleOnLineOnFullLineAndRemoveSelection(line, style, placeCaretOnLine);
};
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);
await helper.waitForPromise(() => {
const lineHTML = inner$.find('div')[line];
return lineHTML !== oldLineHTML;
});
// remove selection from previous line
selectLine(line + 1);
// select the text or place the caret on a position that
// has the formatting text applied previously
selectTarget(line);
};
const pressFormattingShortcutOnSelection = async function (key) {
const inner$ = helper.padInner$;
const originalHTML = helper.padInner$('body').html();
// get the first text element out of the inner iframe
const $firstTextElement = inner$('div').first();
// select this text element
$firstTextElement.sendkeys('{selectall}');
Low hanging lint frontend tests (#4695) * lint: low hanging specs/alphabet.js * lint: low hanging specs/authorship_of_editions.js * lint: low hanging specs/bold.js * lint: low hanging specs/caret.js * lint: low hanging specs/change_user_color.js * lint: low hanging specs/change_user_name.js * lint: low hanging specs/chat.js * lint: low hanging specs/chat_load_messages.js * lint: low hanging specs/clear_authorship_colors.js * lint: low hanging specs/delete.js * lint: low hanging specs/drag_and_drop.js * lint: low hanging specs/embed_value.js * lint: low hanging specs/enter.js * lint: low hanging specs/font_type.js * lint: low hanging specs/helper.js * lint: low hanging specs/importexport.js * lint: low hanging specs/importindents.js * lint: low hanging specs/indentation.js * lint: low hanging specs/italic.js * lint: low hanging specs/language.js * lint: low hanging specs/multiple_authors_clear_authorship_colors.js * lint: low hanging specs/ordered_list.js * lint: low hanging specs/pad_modal.js * lint: low hanging specs/redo.js * lint: low hanging specs/responsiveness.js * lint: low hanging specs/select_formatting_buttons.js * lint: low hanging specs/strikethrough.js * lint: low hanging specs/timeslider.js * lint: low hanging specs/timeslider_labels.js * lint: low hanging specs/timeslider_numeric_padID.js * lint: low hanging specs/timeslider_revisions.js * lint: low hanging specs/undo.js * lint: low hanging specs/unordered_list.js * lint: low hanging specs/xxauto_reconnect.js * lint: attempt to do remote_runner.js * lint: helper linting * lint: rate limit linting * use constructor for Event to make eslint happier * for squash: lint fix refinements * for squash: lint fix refinements Co-authored-by: Richard Hansen <rhansen@rhansen.org>
2021-02-01 20:23:14 +00:00
const e = new inner$.Event(helper.evtType);
e.ctrlKey = true; // Control key
e.which = key.charCodeAt(0); // I, U, B, 5
inner$('#innerdocbody').trigger(e);
await helper.waitForPromise(() => helper.padInner$('body').html() !== originalHTML);
};
STYLES.forEach((style) => {
context(`when selection is in a text with ${style} applied`, function () {
before(async function () {
this.timeout(4000);
await applyStyleOnLineAndSelectIt(FIRST_LINE, style);
});
after(async function () {
await undo();
});
testIfFormattingButtonIsSelected(style);
});
context(`when caret is in a position with ${style} applied`, function () {
before(async function () {
this.timeout(4000);
await applyStyleOnLineAndPlaceCaretOnit(FIRST_LINE, style);
});
after(async function () {
await undo();
});
testIfFormattingButtonIsSelected(style);
});
});
context('when user applies a style and the selection does not change', function () {
it('selects the style button', async function () {
this.timeout(100);
const style = STYLES[0]; // italic
applyStyleOnLine(style, FIRST_LINE);
await helper.waitForPromise(() => isButtonSelected(style) === true);
applyStyleOnLine(style, FIRST_LINE);
});
});
SHORTCUT_KEYS.forEach((key, index) => {
const styleOfTheShortcut = STYLES[index]; // italic, bold, ...
context(`when user presses CMD + ${key}`, function () {
before(async function () {
await pressFormattingShortcutOnSelection(key);
});
testIfFormattingButtonIsSelected(styleOfTheShortcut);
context(`and user presses CMD + ${key} again`, function () {
before(async function () {
await pressFormattingShortcutOnSelection(key);
});
testIfFormattingButtonIsDeselected(styleOfTheShortcut);
});
});
});
});