From 4455a789b65027a53f9f1e610de14570a8f06891 Mon Sep 17 00:00:00 2001 From: Ulrich-Matthias Schäfer Date: Tue, 25 Apr 2017 13:22:58 +0200 Subject: added tests, make replacement for all elements using href --- spec/spec/element.js | 40 ++++++++++++++++++++++++++++++++++++++++ spec/spec/use.js | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) (limited to 'spec') diff --git a/spec/spec/element.js b/spec/spec/element.js index 18343d2..2bcc531 100644 --- a/spec/spec/element.js +++ b/spec/spec/element.js @@ -861,6 +861,46 @@ describe('Element', function() { || toBeTested === '' ).toBeTruthy() }) + it('correctly removes the current location from urls on export', function() { + var rect2, rect1 = draw.rect(100,100).clipWith(rect2 = draw.rect(100,100)) + expect(rect1.attr('clip-path')).toBe('url(' + window.location + '#' + rect2.parent().id() + ')') + + var doc = document.createElement('svg') + doc.innerHTML = rect1.svg() + + expect(doc.firstChild.getAttribute('clip-path')).toBe('url(#' + rect2.parent().id() + ')') + + rect1.attr('clip-path', 'url(http://someUrl.com/with/path/and#Hash)') + + doc.innerHTML = rect1.svg() + expect(doc.firstChild.getAttribute('clip-path')).toBe('url(http://someUrl.com/with/path/and#Hash)') + }) + it('correctly removes the current location from href on export', function() { + var link = draw.link('#somewhere') + expect(link.to()).toBe(window.location + '#somewhere') + + var doc = document.createElement('svg') + doc.innerHTML = link.svg() + expect(doc.firstChild.getAttribute('xlink:href')).toBe('#somewhere') + + link.to('http://someUrl.com/with/path/and#Hash') + doc.innerHTML = link.svg() + expect(doc.firstChild.getAttribute('xlink:href')).toBe('http://someUrl.com/with/path/and#Hash') + }) + it('correctly adds the current location to urls on import', function() { + draw.svg('') + expect(SVG.get('someId').attr('clip-path')).toBe('url(' + window.location + '#something)') + + draw.clear().svg('') + expect(SVG.get('someId').attr('clip-path')).toBe('url(http://someUrl.com/with/path/and#Hash)') + }) + it('correctly adds the current location to href on import', function() { + draw.svg('') + expect(SVG.get('someId').attr('href')).toBe(window.location + '#something') + + draw.clear().svg('') + expect(SVG.get('someId').attr('href')).toBe('http://someUrl.com/with/path/and#Hash') + }) }) describe('with raw svg given', function() { it('imports a full svg document', function() { diff --git a/spec/spec/use.js b/spec/spec/use.js index 0de5b39..b173f4f 100644 --- a/spec/spec/use.js +++ b/spec/spec/use.js @@ -14,7 +14,7 @@ describe('Use', function() { }) it('sets the target element id to its href attribute', function() { - expect(use.node.getAttributeNS(SVG.xlink, 'href')).toBe('#' + rect) + expect(use.node.getAttributeNS(SVG.xlink, 'href')).toBe(window.location + '#' + rect) }) it('adopts the geometry of the target element', function() { -- cgit v1.2.3