diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2023-09-03 09:49:01 +0200 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2023-09-03 09:49:01 +0200 |
commit | ca8ac554bfafe6b4d7985fe3130ff3dffa6029ca (patch) | |
tree | 5dcecd8f32564fb3fb95e8846344b0b26c05dc24 /spec | |
parent | d66be92f19e1004fd250ba1d020db2436f9eb65b (diff) | |
download | svg.js-ca8ac554bfafe6b4d7985fe3130ff3dffa6029ca.tar.gz svg.js-ca8ac554bfafe6b4d7985fe3130ff3dffa6029ca.zip |
doscontinue use of svgjs:data in favor of data-svg
Diffstat (limited to 'spec')
-rw-r--r-- | spec/spec/elements/Dom.js | 22 | ||||
-rw-r--r-- | spec/spec/elements/Element.js | 25 | ||||
-rw-r--r-- | spec/spec/elements/Svg.js | 8 |
3 files changed, 22 insertions, 33 deletions
diff --git a/spec/spec/elements/Dom.js b/spec/spec/elements/Dom.js index 11ce9e0..00879d0 100644 --- a/spec/spec/elements/Dom.js +++ b/spec/spec/elements/Dom.js @@ -10,8 +10,7 @@ import { Fragment, Circle, Tspan, - create, - Text + create } from '../../../src/main.js' import { getWindow } from '../../../src/utils/window.js' import { svg, html } from '../../../src/modules/core/namespaces.js' @@ -658,25 +657,6 @@ describe('Dom.js', function () { }) }) - describe('writeDataToDom()', () => { - it('writes the data to the dom', () => { - const node = new Rect() - node.setData({ foo: 'bar' }) - node.writeDataToDom() - expect(node.node.getAttribute('svgjs:data')).toBe('{"foo":"bar"}') - }) - - it('filters out default data', () => { - const node1 = new Text() - const node2 = new Text() - node2.dom.foo = 'bar' - node1.writeDataToDom() - node2.writeDataToDom() - expect(node1.node.getAttribute('svgjs:data')).toBe(null) - expect(node2.node.getAttribute('svgjs:data')).toBe('{"foo":"bar"}') - }) - }) - describe('xml()', () => { describe('as setter', () => { it('returns itself', () => { diff --git a/spec/spec/elements/Element.js b/spec/spec/elements/Element.js index c89f7aa..93cee3b 100644 --- a/spec/spec/elements/Element.js +++ b/spec/spec/elements/Element.js @@ -1,6 +1,6 @@ /* globals describe, expect, it, beforeEach, spyOn, jasmine, container */ -import { Element, create, Rect, G, SVG } from '../../../src/main.js' +import { Element, create, Rect, G, SVG, Text } from '../../../src/main.js' const { any, objectContaining } = jasmine describe('Element.js', function () { @@ -34,9 +34,14 @@ describe('Element.js', function () { }) it('falls back to empty object when attribute is null', () => { - element.node.setAttribute('svgjs:data', 'null') + element.node.setAttribute('data-svg', 'null') expect(new Element(element.node).dom).toEqual({}) }) + + it('uses old svgjs:data attribute if present', () => { + element.node.setAttribute('svgjs:data', '{"foo":"bar"}') + expect(new Element(element.node).dom).toEqual({ foo: 'bar' }) + }) }) describe('center()', () => { @@ -265,15 +270,15 @@ describe('Element.js', function () { describe('writeDataToDom()', () => { it('removes previously set data', () => { - element.node.setAttribute('svgjs:data', JSON.stringify({ foo: 'bar' })) + element.node.setAttribute('data-svgjs', JSON.stringify({ foo: 'bar' })) element.writeDataToDom() - expect(element.node.getAttribute('svgjs:data')).toBe(null) + expect(element.node.getAttribute('data-svgjs')).toBe(null) }) it('writes data from the dom property into the dom', () => { element.dom = { foo: 'bar' } element.writeDataToDom() - expect(element.node.getAttribute('svgjs:data')).toBe( + expect(element.node.getAttribute('data-svgjs')).toBe( JSON.stringify({ foo: 'bar' }) ) }) @@ -285,6 +290,16 @@ describe('Element.js', function () { g.writeDataToDom() expect(spy).toHaveBeenCalled() }) + + it('filters out default data', () => { + const node1 = new Text() + const node2 = new Text() + node2.dom.foo = 'bar' + node1.writeDataToDom() + node2.writeDataToDom() + expect(node1.node.getAttribute('data-svgjs')).toBe(null) + expect(node2.node.getAttribute('data-svgjs')).toBe('{"foo":"bar"}') + }) }) describe('x()', () => { diff --git a/spec/spec/elements/Svg.js b/spec/spec/elements/Svg.js index 6da7729..ebe3b52 100644 --- a/spec/spec/elements/Svg.js +++ b/spec/spec/elements/Svg.js @@ -1,11 +1,7 @@ /* globals describe, expect, it, jasmine, container */ import { Svg, SVG, Defs } from '../../../src/main.js' -import { - svg as ns, - xlink, - svgjs -} from '../../../src/modules/core/namespaces.js' +import { svg as ns, xlink } from '../../../src/modules/core/namespaces.js' import { getWindow } from '../../../src/utils/window.js' const { any } = jasmine @@ -26,7 +22,6 @@ describe('Svg.js', () => { expect(svg.attr('xmlns')).toBe(ns) expect(svg.attr('version')).toBe(1.1) expect(svg.attr('xmlns:xlink')).toBe(xlink) - expect(svg.attr('xmlns:svgjs')).toBe(svgjs) }) }) @@ -71,7 +66,6 @@ describe('Svg.js', () => { expect(svg.attr('xmlns')).toBe(ns) expect(svg.attr('version')).toBe(1.1) expect(svg.attr('xmlns:xlink')).toBe(xlink) - expect(svg.attr('xmlns:svgjs')).toBe(svgjs) }) }) |