+
+ describe('Hiding metadata nodes from document api', function() {
+ it('hides metadata nodes from document api', function() {
+ var doc = getDocumentFromXML('<section><div></div><metadata><dc:key>value</dc:key></metadata><div></div></section>'),
+ rootContents = doc.root.contents();
+ expect(rootContents).to.have.length(2);
+ expect(rootContents[0].getTagName()).to.equal('div');
+ expect(rootContents[1].getTagName()).to.equal('div');
+ expect(rootContents[0].next().sameNode(rootContents[1])).to.equal(true);
+ expect(rootContents[1].prev().sameNode(rootContents[0])).to.equal(true);
+ });
+
+ it('merges adjacent text nodes', function() {
+ var doc = getDocumentFromXML('<section>Alice<metadata></metadata> has a cat</section>'),
+ contents = doc.root.contents();
+ expect(contents.length).to.equal(1);
+ expect(contents[0].getText()).to.equal('Alice has a cat');
+ });
+ });
+
+ describe('undo', function() {
+ it('undoes adding metadata', function() {
+ var doc = getDocumentFromXML('<section></section>'),
+ metadata = doc.root.getMetadata();
+ metadata.add({key: 'k', value: 'v'});
+ doc.undo();
+ expect(metadata.length).to.equal(0);
+ doc.redo();
+ expect(metadata.length).to.equal(1);
+ expect(metadata.at(0).getValue()).to.equal('v');
+ });
+ it('undoes changing metadata key', function() {
+ var doc = getDocumentFromXML('<section><metadata><dc:key>value</dc:key></metadata></section>'),
+ metadata = doc.root.getMetadata(),
+ row = metadata.at(0);
+
+ row.setKey('key2');
+ doc.undo();
+ expect(row.getKey()).to.equal('key');
+ doc.redo();
+ expect(row.getKey()).to.equal('key2');
+ });
+ it('undoes changing metadata value', function() {
+ var doc = getDocumentFromXML('<section><metadata><dc:key>value</dc:key></metadata></section>'),
+ metadata = doc.root.getMetadata(),
+ row = metadata.at(0);
+
+ row.setValue('value2');
+ doc.undo();
+ expect(row.getValue()).to.equal('value');
+ doc.redo();
+ expect(row.getValue()).to.equal('value2');
+ });
+ it('undoes removing metadata', function() {
+ var doc = getDocumentFromXML('<section><metadata><dc:key>value</dc:key></metadata></section>'),
+ metadata = doc.root.getMetadata(),
+ row = metadata.at(0);
+
+ row.remove();
+ doc.undo();
+ expect(metadata.length).to.equal(1, 'undo brought back metadata');
+ doc.redo();
+ expect(metadata.length).to.equal(0, 'redo removed metadata');
+ });