Reacting to wlxml class change in helper modules properly
[fnpeditor.git] / modules / documentCanvas / canvas / canvas.test3.js
index 43c9083..c4dc610 100644 (file)
@@ -118,14 +118,43 @@ describe('Canvas', function() {
             });
 
             it('knows WLXML class of a WLXML tag it renders', function(){
-                var c = canvas.fromXML('<section class="some.class"></section>'),
+                var c = canvas.fromXML('<section class="some.class.A"></section>'),
                     section = c.doc();
-                expect(section.getWlxmlClass()).to.equal('some.class');
-                section.setWlxmlClass('some.other.class');
-                expect(section.getWlxmlClass()).to.equal('some.other.class');
+                expect(section.getWlxmlClass()).to.equal('some.class.A');
+                section.setWlxmlClass('some.class.B');
+                expect(section.getWlxmlClass()).to.equal('some.class.B');
                 section.setWlxmlClass(null);
                 expect(section.getWlxmlClass()).to.be.undefined;
             });
+
+
+
+            describe('element has meta attributes', function() {
+                it('can change its meta attributes', function() {
+                    var c = canvas.fromXML('<section><span class="uri" meta-uri="someuri"></span></section>'),
+                    span = c.doc().children()[0];
+                    
+                    expect(span.getWlxmlMetaAttr('uri')).to.equal('someuri');
+                    span.setWlxmlMetaAttr('uri', 'otheruri');
+                    expect(span.getWlxmlMetaAttr('uri')).to.equal('otheruri');
+                });
+
+                it('changes its meta attributes with class change', function() {
+                    var c = canvas.fromXML('<section><span class="uri" meta-uri="someuri"></span></section>'),
+                    span = c.doc().children()[0];
+                    
+                    expect(span.getWlxmlMetaAttr('uri')).to.equal('someuri');
+                    span.setWlxmlClass('author');
+                    expect(span.getWlxmlMetaAttr('uri')).to.be.undefined;
+                });
+
+                it('keeps meta attribute value on class change if a new class has this attribute', function() {
+                    var c = canvas.fromXML('<section><span class="uri" meta-uri="someuri"></span></section>'),
+                    span = c.doc().children()[0];
+                    span.setWlxmlClass('uri.some.subclass');
+                    expect(span.getWlxmlMetaAttr('uri')).to.equal('someuri');
+                });
+            });
         });
 
         it('returns DocumentNodeElement instance from HTMLElement', function() {
@@ -980,6 +1009,17 @@ describe('Canvas', function() {
             expect(cursor.isSelecting()).to.equal(false, 'cursor is not selecting anything');
             expect(position.element.getText()).to.equal('Alice has a cat');
             expect(position.offset).to.equal(5);
+            expect(position.offsetAtEnd).to.equal(false, 'offset is not at end');
+
+            getSelection.returns({
+                anchorNode: text,
+                focusNode: text,
+                anchorOffset: 15,
+                focusOffset: 15,
+                isCollapsed: true
+            });
+
+            expect(cursor.getPosition().offsetAtEnd).to.equal(true, 'offset at end');
         });
 
         it('returns boundries of selection when browser selection not collapsed', function() {