diff --git a/core/misc/cspell/dictionary.txt b/core/misc/cspell/dictionary.txt index 55be59f852..d060172c89 100644 --- a/core/misc/cspell/dictionary.txt +++ b/core/misc/cspell/dictionary.txt @@ -1101,6 +1101,7 @@ someschema somethinggeneric sortablejs sourcedir +sourceediting spacebar spagna specialchars diff --git a/core/modules/ckeditor5/tests/src/Nightwatch/Tests/ckEditor5EditorHeightTest.js b/core/modules/ckeditor5/tests/src/Nightwatch/Tests/ckEditor5EditorHeightTest.js new file mode 100644 index 0000000000..4c2be7676a --- /dev/null +++ b/core/modules/ckeditor5/tests/src/Nightwatch/Tests/ckEditor5EditorHeightTest.js @@ -0,0 +1,172 @@ +module.exports = { + '@tags': ['core', 'ckeditor5'], + before(browser) { + browser.drupalInstall({ installProfile: 'minimal' }); + }, + after(browser) { + browser.drupalUninstall(); + }, + 'Test page': (browser) => { + browser.drupalLoginAsAdmin(() => { + browser + // Enable required modules. + .drupalRelativeURL('/admin/modules') + .click('[name="modules[ckeditor5][enable]"]') + .click('[name="modules[field_ui][enable]"]') + .submitForm('input[type="submit"]') // Submit module form. + .waitForElementVisible( + '.system-modules-confirm-form input[value="Continue"]', + ) + .submitForm('input[value="Continue"]') // Confirm installation of dependencies. + .waitForElementVisible('.system-modules', 10000) + + // Create new input format. + .drupalRelativeURL('/admin/config/content/formats/add') + .waitForElementVisible('body') + .updateValue('[data-drupal-selector="edit-name"]', 'test') + .pause(500) // Wait for machine name to update. + .click( + '[data-drupal-selector="edit-editor-editor"] option[value=ckeditor5]', + ) + .waitForElementVisible( + '[data-drupal-selector="edit-editor-settings-toolbar"]', + ) // Wait for Ck5 settings to be visible. + .click('.ckeditor5-toolbar-button-sourceEditing') // Select the Source Editing button. + .keys(browser.Keys.DOWN) // Hit the down arrow key to move it to the toolbar. + .waitForElementVisible( + '[href*=edit-editor-settings-plugins-ckeditor5-sourceediting]', + ) // Wait for new source editing vertical tab to be present before continuing. + .submitForm('input[type="submit"]') + .waitForElementVisible('[data-drupal-messages]') + .assert.textContains('[data-drupal-messages]', 'Added text format') + + // Create new content type. + .drupalRelativeURL('/admin/structure/types/add') + .waitForElementVisible('body') + .updateValue('[data-drupal-selector="edit-name"]', 'test') + .pause(500) // Wait for machine name to update. + .submitForm('input[type="submit"]') + .waitForElementVisible('[data-drupal-messages]') + .assert.textContains( + '[data-drupal-messages]', + 'The content type test has been added', + ) + + // Navigate to the create content page and measure height of the editor. + .drupalRelativeURL('/node/add/test') + .waitForElementVisible('.ck-editor__editable') + .execute( + // eslint-disable-next-line func-names, prefer-arrow-callback, no-shadow + function () { + const height = document.querySelector( + '.ck-editor__editable', + ).clientHeight; + + // We expect height to be 320, but test to ensure that it's greater + // than 300. We want to ensure that we don't hard code a very specific + // value because tests might break if styles change (line-height, etc). + // Note that the default height for CKEditor5 is 47. + return height > 300; + }, + [], + (result) => { + browser.assert.ok( + result.value, + 'Editor height is set to 9 rows (default).', + ); + }, + ) + .click('.ck-source-editing-button') + .waitForElementVisible('.ck-source-editing-area') + .execute( + // eslint-disable-next-line func-names, prefer-arrow-callback, no-shadow + function () { + const height = document.querySelector( + '.ck-source-editing-area', + ).clientHeight; + + // We expect height to be 320, but test to ensure that it's greater + // than 300. We want to ensure that we don't hard code a very specific + // value because tests might break if styles change (line-height, etc). + // Note that the default height for CKEditor5 is 47px. + return height > 300; + }, + [], + (result) => { + browser.assert.ok( + result.value, + 'Source editing height is set to 9 rows (default).', + ); + }, + ) + + // Double the editor row count. + .drupalRelativeURL('/admin/structure/types/manage/test/form-display') + .waitForElementVisible('body') + .click('[data-drupal-selector="edit-fields-body-settings-edit"]') + .waitForElementVisible( + '[data-drupal-selector="edit-fields-body-settings-edit-form-settings-rows"]', + ) + .updateValue( + '[data-drupal-selector="edit-fields-body-settings-edit-form-settings-rows"]', + '18', + ) + .click( + '[data-drupal-selector="edit-fields-body-settings-edit-form-actions-save-settings"]', + ) // Save field settings. + .waitForElementVisible( + '[data-drupal-selector="edit-fields-body"] .field-plugin-summary', + ) + .click('[data-drupal-selector="edit-submit"]') + .waitForElementVisible('[data-drupal-messages]') + .assert.textContains( + '[data-drupal-messages]', + 'Your settings have been saved', + ) + + // Navigate to the create content page and measure height of the editor. + .drupalRelativeURL('/node/add/test') + .execute( + // eslint-disable-next-line func-names, prefer-arrow-callback, no-shadow + function () { + const height = document.querySelector( + '.ck-editor__editable', + ).clientHeight; + + // We expect height to be 640, but test to ensure that it's greater + // than 600. We want to ensure that we don't hard code a very specific + // value because tests might break if styles change (line-height, etc). + // Note that the default height for CKEditor5 is 47px. + return height > 600; + }, + [], + (result) => { + browser.assert.ok(result.value, 'Editor height is set to 18 rows.'); + }, + ) + .click('.ck-source-editing-button') + .waitForElementVisible('.ck-source-editing-area') + .execute( + // eslint-disable-next-line func-names, prefer-arrow-callback, no-shadow + function () { + const height = document.querySelector( + '.ck-source-editing-area', + ).clientHeight; + + // We expect height to be 640, but test to ensure that it's greater + // than 600. We want to ensure that we don't hard code a very specific + // value because tests might break if styles change (line-height, etc). + // Note that the default height for CKEditor5 is 47. + return height > 600; + }, + [], + (result) => { + browser.assert.ok( + result.value, + 'Source editing height is set to 18 rows (default).', + ); + }, + ); + }); + }, +};