From 372f1dfeb433dd431b4c4ddc2f827059cd71632a Mon Sep 17 00:00:00 2001 From: Paul Libbrecht Date: Fri, 11 May 2018 09:06:22 +0200 Subject: [PATCH 1/3] First anchor test and restore of the CKEditor anchor function. --- customize.dist/ckeditor-config.js | 2 +- www/pad/inner.js | 57 +++++++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/customize.dist/ckeditor-config.js b/customize.dist/ckeditor-config.js index 36cac87f0..882c5e0fc 100644 --- a/customize.dist/ckeditor-config.js +++ b/customize.dist/ckeditor-config.js @@ -5,7 +5,7 @@ CKEDITOR.editorConfig = function( config ) { config.needsBrFiller= fixThings; config.needsNbspFiller= fixThings; - config.removeButtons= 'Source,Maximize,Anchor'; + config.removeButtons= 'Source,Maximize'; // magicline plugin inserts html crap into the document which is not part of the // document itself and causes problems when it's sent across the wire and reflected back config.removePlugins= 'resize,elementspath'; diff --git a/www/pad/inner.js b/www/pad/inner.js index 88d9f5011..21919c1a2 100644 --- a/www/pad/inner.js +++ b/www/pad/inner.js @@ -32,6 +32,7 @@ define([ '/common/common-util.js', '/bower_components/chainpad/chainpad.dist.js', '/customize/application_config.js', + '/common/test.js', '/bower_components/diff-dom/diffDOM.js', @@ -52,7 +53,9 @@ define([ Hash, Util, ChainPad, - AppConfig) + AppConfig, + Test +) { var DiffDom = window.diffDOM; @@ -160,7 +163,12 @@ define([ ]; var getHTML = function (inner) { - return ('\n' + '\n' + inner.innerHTML); + return ('\n' + '\n' + + ' \n ' + + inner.innerHTML.replace(/]*class="cke_anchor"[^>]*data-cke-realelement="([^"]*)"[^>]*>/, + function(match,realElt){ return unescape(realElt); }) + + ' \n' + ); }; var CKEDITOR_CHECK_INTERVAL = 100; @@ -752,6 +760,51 @@ define([ }).nThen(waitFor()); }).nThen(function (/*waitFor*/) { + function launchAnchorTest(test) { + // -------- anchor test: make sure the exported anchor contains ------- + console.log('---- anchor test: make sure the exported anchor contains -----.'); + + // TODO: cleanup fixme, too much ---, and removed tests + // TODO: any other unwanted changes (sframe-app?)? + // TODO: upgrade to latest of master, create branch + // TODO: any way to make sure that content contains anchors? Seems to need selenium-driven clicks and inputs + function tryAndTestExport() { + // window.setContent("This goes before the anchor"); + var anchors = CKEDITOR.plugins["link"].getEditorAnchors(editor); + if(!anchors || anchors.length===0) { + test.fail("No anchors found. Please adjust document"); + } else { + console.log(anchors.length + " anchors found."); + var exported = getHTML(inner); + console.log("Obtained exported: " + exported); + var allFound = true; + for(var i=0; i=0; + console.log("Found " + expected + " " + found + "."); + allFound = allFound && found; + } + console.log("Finished anchor test."); + if(allFound) {test.pass();} + else + {test.fail("Not all expected a elements found.");} + } + } + var intervalHandle = window.setInterval(function() { + if(editor.status==="ready") { + window.clearInterval(intervalHandle); + tryAndTestExport(); + } else { + console.log("Waiting for editor to be ready."); + } + }, 100); + } + Test(function(test) { + + launchAnchorTest(test); + }); andThen2(editor, Ckeditor, framework); }); }; From 0dc1500784051226a6bf464b08035ade66958a8d Mon Sep 17 00:00:00 2001 From: Paul Libbrecht Date: Mon, 13 Aug 2018 21:04:24 +0200 Subject: [PATCH 2/3] This should solve issue #169: The test now completes with the insertion of a random anchor (menu-driven) and some text, the export is then checked to contain as expected, then cleans up. paul --- www/pad/inner.js | 84 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 57 insertions(+), 27 deletions(-) diff --git a/www/pad/inner.js b/www/pad/inner.js index 21919c1a2..fe8d5dcc9 100644 --- a/www/pad/inner.js +++ b/www/pad/inner.js @@ -165,8 +165,10 @@ define([ var getHTML = function (inner) { return ('\n' + '\n' + ' \n ' + - inner.innerHTML.replace(/]*class="cke_anchor"[^>]*data-cke-realelement="([^"]*)"[^>]*>/, - function(match,realElt){ return unescape(realElt); }) + + inner.innerHTML.replace(/]*class="cke_anchor"[^>]*data-cke-realelement="([^"]*)"[^>]*>/g, + function(match,realElt){ + //console.log("returning realElt \"" + unescape(realElt)+ "\"."); + return unescape(realElt); }) + ' \n' ); }; @@ -764,37 +766,65 @@ define([ // -------- anchor test: make sure the exported anchor contains ------- console.log('---- anchor test: make sure the exported anchor contains -----.'); - // TODO: cleanup fixme, too much ---, and removed tests - // TODO: any other unwanted changes (sframe-app?)? - // TODO: upgrade to latest of master, create branch - // TODO: any way to make sure that content contains anchors? Seems to need selenium-driven clicks and inputs function tryAndTestExport() { - // window.setContent("This goes before the anchor"); - var anchors = CKEDITOR.plugins["link"].getEditorAnchors(editor); - if(!anchors || anchors.length===0) { - test.fail("No anchors found. Please adjust document"); - } else { - console.log(anchors.length + " anchors found."); - var exported = getHTML(inner); - console.log("Obtained exported: " + exported); - var allFound = true; - for(var i=0; i=0; - console.log("Found " + expected + " " + found + "."); - allFound = allFound && found; + console.log("Starting tryAndTestExport."); + editor.on( 'dialogShow', function( evt ) { + console.log("Anchor dialog detected."); + var dialog = evt.data; + $(dialog.parts.contents.$).find("input").val('xx-' + Math.round(Math.random()*1000)); + dialog.click(CKEDITOR.dialog.okButton(editor).id); + } ); + var existingText = editor.getData(); + editor.insertText("A bit of text"); + console.log("Launching anchor command."); + editor.execCommand(editor.ui.get('Anchor').command); + console.log("Anchor command launched."); + + var waitH = window.setInterval(function() { + console.log("Waited 2s for the dialog to appear"); + var anchors = CKEDITOR.plugins["link"].getEditorAnchors(editor); + if(!anchors || anchors.length===0) { + test.fail("No anchors found. Please adjust document"); + } else { + console.log(anchors.length + " anchors found."); + var exported = getHTML(inner); + console.log("Obtained exported: " + exported); + var allFound = true; + for(var i=0; i=0; + console.log("Found " + expected + " " + found + "."); + allFound = allFound && found; + } + + console.log("Cleaning up."); + if(allFound) { + // clean-up + editor.execCommand('undo'); + editor.execCommand('undo'); + var nint = window.setInterval(function(){ + console.log("Waiting for undo to yield same result.") + if(existingText === editor.getData()) { + window.clearInterval(nint); + test.pass(); + } + }, 500); + } else + { + test.fail("Not all expected a elements found for document at " + window.top.location + "."); + } } - console.log("Finished anchor test."); - if(allFound) {test.pass();} - else - {test.fail("Not all expected a elements found.");} - } + window.clearInterval(waitH); + },2000); + + } var intervalHandle = window.setInterval(function() { if(editor.status==="ready") { window.clearInterval(intervalHandle); + console.log("Editor is ready."); tryAndTestExport(); } else { console.log("Waiting for editor to be ready."); From fb9cf2c81ea39ea5b1c24f1324206f5c2f3dd7f5 Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 14 Aug 2018 17:11:08 +0200 Subject: [PATCH 3/3] lint compliance --- www/pad/inner.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/www/pad/inner.js b/www/pad/inner.js index fe8d5dcc9..70867cac0 100644 --- a/www/pad/inner.js +++ b/www/pad/inner.js @@ -168,7 +168,7 @@ define([ inner.innerHTML.replace(/]*class="cke_anchor"[^>]*data-cke-realelement="([^"]*)"[^>]*>/g, function(match,realElt){ //console.log("returning realElt \"" + unescape(realElt)+ "\"."); - return unescape(realElt); }) + + return decodeURIComponent(realElt); }) + ' \n' ); }; @@ -772,7 +772,7 @@ define([ console.log("Anchor dialog detected."); var dialog = evt.data; $(dialog.parts.contents.$).find("input").val('xx-' + Math.round(Math.random()*1000)); - dialog.click(CKEDITOR.dialog.okButton(editor).id); + dialog.click(window.CKEDITOR.dialog.okButton(editor).id); } ); var existingText = editor.getData(); editor.insertText("A bit of text"); @@ -782,12 +782,12 @@ define([ var waitH = window.setInterval(function() { console.log("Waited 2s for the dialog to appear"); - var anchors = CKEDITOR.plugins["link"].getEditorAnchors(editor); + var anchors = window.CKEDITOR.plugins["link"].getEditorAnchors(editor); if(!anchors || anchors.length===0) { test.fail("No anchors found. Please adjust document"); } else { console.log(anchors.length + " anchors found."); - var exported = getHTML(inner); + var exported = getHTML(window.inner); console.log("Obtained exported: " + exported); var allFound = true; for(var i=0; i