X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/dc88a3110d5f44a8240cdd637b22716545763578..9e5d2dd07732d54da694d199c551b1818eeee3da:/src/smartxml/smartxml.test.js?ds=sidebyside diff --git a/src/smartxml/smartxml.test.js b/src/smartxml/smartxml.test.js index 8f7deb6..fb420db 100644 --- a/src/smartxml/smartxml.test.js +++ b/src/smartxml/smartxml.test.js @@ -1649,6 +1649,32 @@ describe('smartxml', function() { var transaction = doc.undoStack[0]; expect(transaction.metadata).to.equal(metadata); }); + + it('can be rolled back', function() { + var doc = getDocumentFromXML(''); + + doc.startTransaction(); + doc.root.append({tagName: 'div'}); + doc.rollbackTransaction(); + + expect(doc.undoStack.length).to.equal(0, 'nothing to undo'); + expect(doc.root.contents().length).to.equal(0); + }); + + it('rollbacks and calls error handleor if error gets thrown', function() { + var doc = getDocumentFromXML(''), + err = new Error(), + spy = sinon.spy(); + + doc.transaction(function() { + doc.root.append({tagName: 'div'}); + throw err; + }, {error: spy}); + + expect(spy.args[0][0]).to.equal(err); + expect(doc.root.contents().length).to.equal(0); + expect(doc.undoStack.length).to.equal(0); + }); }); describe('Regression tests', function() {