From 0dc1500784051226a6bf464b08035ade66958a8d Mon Sep 17 00:00:00 2001 From: Paul Libbrecht Date: Mon, 13 Aug 2018 21:04:24 +0200 Subject: [PATCH] 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.");