Merge pull request #2469 from ether/new-sethtml-tests
I need to do some more work on this at some point.. Leaving herepull/2477/head
commit
84638a39b7
|
@ -410,11 +410,16 @@ exports.setHTML = function(padID, html, callback)
|
|||
if(ERR(err, callback)) return;
|
||||
|
||||
// add a new changeset with the new html to the pad
|
||||
importHtml.setPadHTML(pad, cleanText(html), callback);
|
||||
|
||||
//update the clients on the pad
|
||||
padMessageHandler.updatePadClients(pad, callback);
|
||||
|
||||
importHtml.setPadHTML(pad, cleanText(html), function(e){
|
||||
if(e){
|
||||
callback(new customError("HTML is malformed","apierror"));
|
||||
return;
|
||||
}else{
|
||||
//update the clients on the pad
|
||||
padMessageHandler.updatePadClients(pad, callback);
|
||||
return;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -232,11 +232,9 @@ exports.doImport = function(req, res, padId)
|
|||
if(!directDatabaseAccess){
|
||||
var fileEnding = path.extname(srcFile).toLowerCase();
|
||||
if (abiword || fileEnding == ".htm" || fileEnding == ".html") {
|
||||
try{
|
||||
importHtml.setPadHTML(pad, text);
|
||||
}catch(e){
|
||||
apiLogger.warn("Error importing, possibly caused by malformed HTML");
|
||||
}
|
||||
importHtml.setPadHTML(pad, text, function(e){
|
||||
if(e) apiLogger.warn("Error importing, possibly caused by malformed HTML");
|
||||
});
|
||||
} else {
|
||||
pad.setText(text);
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ function setPadHTML(pad, html, callback)
|
|||
cc.collectContent(doc);
|
||||
}catch(e){
|
||||
apiLogger.warn("HTML was not properly formed", e);
|
||||
return; // We don't process the HTML because it was bad..
|
||||
return callback(e); // We don't process the HTML because it was bad..
|
||||
}
|
||||
|
||||
var result = cc.finish();
|
||||
|
@ -91,6 +91,7 @@ function setPadHTML(pad, html, callback)
|
|||
apiLogger.debug('The changeset: ' + theChangeset);
|
||||
pad.setText("");
|
||||
pad.appendRevision(theChangeset);
|
||||
callback(null);
|
||||
}
|
||||
|
||||
exports.setPadHTML = setPadHTML;
|
||||
|
|
|
@ -12,6 +12,7 @@ var apiVersion = 1;
|
|||
var testPadId = makeid();
|
||||
var lastEdited = "";
|
||||
var text = generateLongText();
|
||||
var ULhtml = '<!DOCTYPE html><html><body><ul class="bullet"><li>one</li><li>2</li></ul><br><ul><ul class="bullet"><li>UL2</li></ul></ul></body></html>';
|
||||
|
||||
describe('Connectivity', function(){
|
||||
it('errors if can not connect', function(done) {
|
||||
|
@ -71,6 +72,9 @@ describe('Permission', function(){
|
|||
-> movePad(newPadID, originalPadId) -- Should provide consistant pad data
|
||||
-> getText(originalPadId) -- Should be "hello world"
|
||||
-> getLastEdited(padID) -- Should not be 0
|
||||
-> setHTML(padID) -- Should fail on invalid HTML
|
||||
-> setHTML(padID) *3 -- Should fail on invalid HTML
|
||||
-> getHTML(padID) -- Should return HTML close to posted HTML
|
||||
|
||||
*/
|
||||
|
||||
|
@ -390,6 +394,44 @@ describe('getLastEdited', function(){
|
|||
});
|
||||
})
|
||||
|
||||
describe('setHTML', function(){
|
||||
it('Sets the HTML of a Pad attempting to pass ugly HTML', function(done) {
|
||||
var html = "<div><b>Hello HTML</title></head></div>";
|
||||
api.get(endPoint('setHTML')+"&padID="+testPadId+"&html="+html)
|
||||
.expect(function(res){
|
||||
console.log(res.body.code);
|
||||
if(res.body.code !== 1) throw new Error("Allowing crappy HTML to be imported")
|
||||
})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200, done)
|
||||
});
|
||||
})
|
||||
|
||||
describe('setHTML', function(){
|
||||
it('Sets the HTML of a Pad with a bunch of weird unordered lists inserted', function(done) {
|
||||
api.get(endPoint('setHTML')+"&padID="+testPadId+"&html="+ULhtml)
|
||||
.expect(function(res){
|
||||
if(res.body.code !== 0) throw new Error("List HTML cant be imported")
|
||||
})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200, done)
|
||||
});
|
||||
})
|
||||
|
||||
describe('getHTML', function(){
|
||||
it('Gets the HTML of a Pad with a bunch of weird unordered lists inserted', function(done) {
|
||||
api.get(endPoint('getHTML')+"&padID="+testPadId)
|
||||
.expect(function(res){
|
||||
var ehtml = res.body.data.html.replace("<br></body>", "</body>").toLowerCase();
|
||||
var uhtml = ULhtml.toLowerCase();
|
||||
if(ehtml !== uhtml) throw new Error("Imported HTML does not match served HTML")
|
||||
})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200, done)
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
/*
|
||||
-> movePadForce Test
|
||||
|
||||
|
|
Loading…
Reference in New Issue