Skip to content

Commit

Permalink
TASK: Render CKE with headings
Browse files Browse the repository at this point in the history
  • Loading branch information
markusguenther committed Dec 5, 2024
1 parent 0aed581 commit e6152f0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ test('Can create content node from inside InlineUI', async t => {
subSection('Type something inside of it');
await Page.waitForIframeLoading(t);

await typeTextInline(t, '.test-headline:last-child [contenteditable="true"]', headlineTitle);
await typeTextInline(t, '.test-headline:last-child [contenteditable="true"]', headlineTitle, 'heading1');
await t
// .selectEditableContent(lastEditableElement, lastEditableElement)
// .pressKey(headlineTitle.split('').join(' '))
Expand All @@ -189,7 +189,7 @@ test('Can create content node from inside InlineUI', async t => {
.expect(ReactSelector('InlineValidationTooltips').exists).ok('Validation tooltip appeared');
await t
.expect(changeRequestLogger.count(() => true)).eql(0, 'No requests were fired with invalid state');
await typeTextInline(t, '.test-headline:last-child [contenteditable="true"]', 'Some text');
await typeTextInline(t, '.test-headline:last-child [contenteditable="true"]', 'Some text', 'heading1');
await t
.wait(1600)
.switchToMainWindow();
Expand Down
23 changes: 20 additions & 3 deletions Tests/IntegrationTests/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,25 @@ export async function beforeEach(t) {

// This is a workaround for the fact that the contenteditable element is not directly selectable
// for more information see https://testcafe.io/documentation/402688/reference/test-api/testcontroller/selecteditablecontent
export async function typeTextInline(t, selector, text, switchToIframe = true) {
export async function typeTextInline(t, selector, text, textType, switchToIframe = true) {
await waitForReact(30000);
await Page.waitForIframeLoading();

const textTypeToTagMap = {
paragraph: 'p',
heading1: 'h1',
heading2: 'h2',
heading3: 'h3',
heading4: 'h4'
};

if (!Object.keys(textTypeToTagMap).includes(textType)) {
console.warn('Invalid textType, defaulting to "paragraph".');
textType = 'paragraph';
}

const tagName = textTypeToTagMap[textType] || '';

try {
const contentIframeSelector = Selector('[name="neos-content-main"]', {timeout: 2000});

Expand All @@ -86,9 +101,11 @@ export async function typeTextInline(t, selector, text, switchToIframe = true) {
await t.eval(() => {
const element = window.document.querySelector(selector);
const editor = element.closest('.ck-editor__editable');
editor.ckeditorInstance.data.set(text);
const content = tagName !== '' ? `<${tagName}>${text}</${tagName}>` : text;
console.log('content', content);
editor.ckeditorInstance.data.set(content);
},
{dependencies: {selector, text}}
{dependencies: {selector, text, tagName}}
);
} catch (e) {
// console.log(e);
Expand Down

0 comments on commit e6152f0

Please sign in to comment.