Add test for ChangeElementCommand
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1869 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
e75b51e182
commit
304d83f0ed
|
@ -272,7 +272,9 @@ svgedit.history.ChangeElementCommand.prototype.apply = function(handler) {
|
||||||
else this.elem.setAttribute(attr, this.newValues[attr]);
|
else this.elem.setAttribute(attr, this.newValues[attr]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (attr == "#text") this.elem.textContent = "";
|
if (attr == "#text") {
|
||||||
|
this.elem.textContent = "";
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
this.elem.setAttribute(attr, "");
|
this.elem.setAttribute(attr, "");
|
||||||
this.elem.removeAttribute(attr);
|
this.elem.removeAttribute(attr);
|
||||||
|
@ -318,7 +320,9 @@ svgedit.history.ChangeElementCommand.prototype.unapply = function(handler) {
|
||||||
else this.elem.setAttribute(attr, this.oldValues[attr]);
|
else this.elem.setAttribute(attr, this.oldValues[attr]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (attr == "#text") this.elem.textContent = "";
|
if (attr == "#text") {
|
||||||
|
this.elem.textContent = "";
|
||||||
|
}
|
||||||
else this.elem.removeAttribute(attr);
|
else this.elem.removeAttribute(attr);
|
||||||
}
|
}
|
||||||
if (attr == "transform") { bChangedTransform = true; }
|
if (attr == "transform") { bChangedTransform = true; }
|
||||||
|
|
|
@ -3,15 +3,18 @@
|
||||||
<head>
|
<head>
|
||||||
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
|
<link rel='stylesheet' href='qunit/qunit.css' type='text/css'/>
|
||||||
<script src='../editor/jquery.js'></script>
|
<script src='../editor/jquery.js'></script>
|
||||||
<script type='text/javascript' src='../editor/svgutils.js'></script>
|
|
||||||
<script type='text/javascript' src='../editor/history.js'></script>
|
<script type='text/javascript' src='../editor/history.js'></script>
|
||||||
<script type='text/javascript' src='qunit/qunit.js'></script>
|
<script type='text/javascript' src='qunit/qunit.js'></script>
|
||||||
<script type='text/javascript'>
|
<script type='text/javascript'>
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|
||||||
// Mocked out method.
|
// Mocked out methods.
|
||||||
svgedit.transformlist = {};
|
svgedit.transformlist = {};
|
||||||
svgedit.transformlist.removeElementFromListMap = function(elem) {};
|
svgedit.transformlist.removeElementFromListMap = function(elem) {};
|
||||||
|
svgedit.utilities = {};
|
||||||
|
svgedit.utilities.getHref = function(elem) { return '#foo'; };
|
||||||
|
svgedit.utilities.setHref = function(elem, val) {};
|
||||||
|
svgedit.utilities.getRotationAngle = function(elem) { return 0; };
|
||||||
|
|
||||||
// log function
|
// log function
|
||||||
QUnit.log = function(result, message) {
|
QUnit.log = function(result, message) {
|
||||||
|
@ -444,6 +447,81 @@
|
||||||
tearDown();
|
tearDown();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Test ChangeElementCommand', function() {
|
||||||
|
expect(20);
|
||||||
|
|
||||||
|
setUp();
|
||||||
|
|
||||||
|
div1.setAttribute('title', 'new title');
|
||||||
|
var change = new svgedit.history.ChangeElementCommand(div1,
|
||||||
|
{'title': 'old title', 'class': 'foo'});
|
||||||
|
ok(change.unapply);
|
||||||
|
ok(change.apply);
|
||||||
|
equals(typeof change.unapply, typeof function(){});
|
||||||
|
equals(typeof change.apply, typeof function(){});
|
||||||
|
|
||||||
|
change.unapply();
|
||||||
|
equals(div1.getAttribute('title'), 'old title');
|
||||||
|
equals(div1.getAttribute('class'), 'foo');
|
||||||
|
|
||||||
|
change.apply();
|
||||||
|
equals(div1.getAttribute('title'), 'new title');
|
||||||
|
ok(!div1.getAttribute('class'));
|
||||||
|
|
||||||
|
div1.textContent = 'inner text';
|
||||||
|
change = new svgedit.history.ChangeElementCommand(div1,
|
||||||
|
{'#text': null});
|
||||||
|
|
||||||
|
change.unapply();
|
||||||
|
ok(!div1.textContent);
|
||||||
|
|
||||||
|
change.apply();
|
||||||
|
equals(div1.textContent, 'inner text');
|
||||||
|
|
||||||
|
div1.textContent = '';
|
||||||
|
change = new svgedit.history.ChangeElementCommand(div1,
|
||||||
|
{'#text': 'old text'});
|
||||||
|
|
||||||
|
change.unapply();
|
||||||
|
equals(div1.textContent, 'old text');
|
||||||
|
|
||||||
|
change.apply();
|
||||||
|
ok(!div1.textContent);
|
||||||
|
|
||||||
|
// TODO(codedread): Refactor this #href stuff in history.js and svgcanvas.js
|
||||||
|
var rect = document.createElementNS(svgns, 'rect');
|
||||||
|
var justCalled = null;
|
||||||
|
var gethrefvalue = null;
|
||||||
|
var sethrefvalue = null;
|
||||||
|
svgedit.utilities.getHref = function(elem) {
|
||||||
|
equals(elem, rect);
|
||||||
|
justCalled = 'getHref';
|
||||||
|
return gethrefvalue;
|
||||||
|
};
|
||||||
|
svgedit.utilities.setHref = function(elem, val) {
|
||||||
|
equals(elem, rect);
|
||||||
|
equals(val, sethrefvalue);
|
||||||
|
justCalled = 'setHref';
|
||||||
|
};
|
||||||
|
|
||||||
|
gethrefvalue = '#newhref';
|
||||||
|
change = new svgedit.history.ChangeElementCommand(rect,
|
||||||
|
{'#href': '#oldhref'});
|
||||||
|
equals(justCalled, 'getHref');
|
||||||
|
|
||||||
|
justCalled = null;
|
||||||
|
sethrefvalue = '#oldhref';
|
||||||
|
change.unapply();
|
||||||
|
equals(justCalled, 'setHref');
|
||||||
|
|
||||||
|
justCalled = null;
|
||||||
|
sethrefvalue = '#newhref';
|
||||||
|
change.apply();
|
||||||
|
equals(justCalled, 'setHref');
|
||||||
|
|
||||||
|
tearDown();
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
Loading…
Reference in New Issue