From 55a2e8ebe262d4dcd6b7489df573f980d24554d0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ulrich-Matthias=20Sch=C3=A4fer?= Date: Thu, 16 Apr 2020 17:26:41 +1000 Subject: [PATCH] make tests svgdom ready --- .config/karma.conf.common.js | 3 +- spec/runSVGDomTest.js | 14 ++++----- spec/setupBrowser.js | 4 ++- spec/setupSVGDom.js | 11 ++++--- spec/spec/elements/Image.js | 2 +- spec/spec/elements/Pattern.js | 2 +- spec/spec/elements/Tspan.js | 4 +-- spec/spec/pattern.js | 56 +++++++++++++++++------------------ 8 files changed, 51 insertions(+), 45 deletions(-) diff --git a/.config/karma.conf.common.js b/.config/karma.conf.common.js index 62005bf..4808996 100644 --- a/.config/karma.conf.common.js +++ b/.config/karma.conf.common.js @@ -36,7 +36,8 @@ module.exports = function (config) { ], proxies: { - '/fixtures/': '/base/spec/fixtures/' + '/fixtures/': '/base/spec/fixtures/', + '/spec/': '/base/spec/' }, // web server port diff --git a/spec/runSVGDomTest.js b/spec/runSVGDomTest.js index 57055f4..3f2276e 100644 --- a/spec/runSVGDomTest.js +++ b/spec/runSVGDomTest.js @@ -9,14 +9,14 @@ import Jasmine from 'jasmine' const jasmine = new Jasmine() jasmine.loadConfig({ - "spec_dir": "spec/", - "spec_files": [ - "spec/types/*.js", - "spec/utils/*.js", - "spec/elements/*.js" + spec_dir: 'spec/', + spec_files: [ + 'spec/types/*.js', + 'spec/utils/*.js', + 'spec/elements/*.js' ], - "helpers": [ - "setupSVGDom.js" + helpers: [ + 'setupSVGDom.js' ] }) diff --git a/spec/setupBrowser.js b/spec/setupBrowser.js index fb68b07..b2441c1 100644 --- a/spec/setupBrowser.js +++ b/spec/setupBrowser.js @@ -1,6 +1,8 @@ -/* globals beforeEach, afterEach */ +/* globals beforeEach, afterEach, jasmine */ import { buildCanvas, clear } from './helpers.js' +jasmine.DEFAULT_TIMEOUT_INTERVAL = 200 + beforeEach(() => { // buildFixtures() buildCanvas() diff --git a/spec/setupSVGDom.js b/spec/setupSVGDom.js index 3da401d..1d9ff95 100644 --- a/spec/setupSVGDom.js +++ b/spec/setupSVGDom.js @@ -1,13 +1,16 @@ -import svgdom from 'svgdom' +import { createSVGWindow } from 'svgdom' -import { buildCanvas, buildFixtures, clear } from './helpers.js' +/* globals beforeEach, afterEach, jasmine */ +import { buildCanvas, clear } from './helpers.js' import { registerWindow } from '../src/main.js' +jasmine.DEFAULT_TIMEOUT_INTERVAL = 200 + function setup () { - let win = /*new*/ svgdom + const win = createSVGWindow() registerWindow(win, win.document) buildCanvas() - buildFixtures() + // buildFixtures() global.container = win.document.getElementById('canvas') } diff --git a/spec/spec/elements/Image.js b/spec/spec/elements/Image.js index 5f9b5f5..c7b91d2 100644 --- a/spec/spec/elements/Image.js +++ b/spec/spec/elements/Image.js @@ -5,7 +5,7 @@ import { getWindow } from '../../../src/utils/window.js' const { any, objectContaining, createSpy } = jasmine -const url = 'fixtures/pixel.png' +const url = 'spec/fixtures/pixel.png' describe('Image.js', () => { describe('()', () => { diff --git a/spec/spec/elements/Pattern.js b/spec/spec/elements/Pattern.js index 432a86e..9a4fcd5 100644 --- a/spec/spec/elements/Pattern.js +++ b/spec/spec/elements/Pattern.js @@ -37,7 +37,7 @@ describe('Pattern.js', () => { describe('targets()', () => { it('gets all targets of this pattern', () => { const canvas = SVG().addTo(container) - const pattern = canvas.pattern('linear') + const pattern = canvas.pattern() const rect = canvas.rect(100, 100).fill(pattern) expect(pattern.targets()).toEqual([ rect ]) }) diff --git a/spec/spec/elements/Tspan.js b/spec/spec/elements/Tspan.js index 5d2c0d5..a2e6620 100644 --- a/spec/spec/elements/Tspan.js +++ b/spec/spec/elements/Tspan.js @@ -68,7 +68,7 @@ describe('Tspan.js', () => { }) }) - describe('newLine', () => { + describe('newLine()', () => { it('works without text parent', () => { // should not fail const tspan = new Tspan().newLine() @@ -98,7 +98,7 @@ describe('Tspan.js', () => { text.tspan('Second Line').newLine() const third = text.tspan('Third Line').newLine() - const fontSize = getWindow().window.getComputedStyle(third.node).getPropertyValue('font-size') + const fontSize = getWindow().getComputedStyle(third.node).getPropertyValue('font-size') const dy = 2 * new SVGNumber(fontSize) expect(third.dy()).toBe(dy) }) diff --git a/spec/spec/pattern.js b/spec/spec/pattern.js index 41924f5..f51caf6 100644 --- a/spec/spec/pattern.js +++ b/spec/spec/pattern.js @@ -1,64 +1,64 @@ -describe('Pattern', function() { +describe('Pattern', function () { var rect, pattern - beforeEach(function() { - rect = draw.rect(100,100) - pattern = draw.pattern(20, 30, function(add) { - add.rect(10,10).move(10,10) + beforeEach(function () { + rect = draw.rect(100, 100) + pattern = draw.pattern(20, 30, function (add) { + add.rect(10, 10).move(10, 10) add.circle(30) }) }) - afterEach(function() { + afterEach(function () { rect.remove() pattern.remove() }) - it('is an instance of SVG.Pattern', function() { + it('is an instance of SVG.Pattern', function () { expect(pattern instanceof SVG.Pattern).toBe(true) }) - it('allows creation of a new gradient without block', function() { - pattern = draw.pattern(10,30) + it('allows creation of a new gradient without block', function () { + pattern = draw.pattern(10, 30) expect(pattern.children().length).toBe(0) }) - describe('url()', function() { - it('returns the id of the pattern wrapped in url()', function() { - expect(pattern.url()).toBe('url(#' + pattern.id() + ')') + describe('url()', function () { + it('returns the id of the pattern wrapped in url()', function () { + expect(pattern.url()).toBe('url("#' + pattern.id() + '")') }) }) - describe('attr()', function() { - it('will catch transform attribues and convert them to patternTransform', function() { - expect(pattern.translate(100,100).attr('patternTransform')).toBe('matrix(1,0,0,1,100,100)') + describe('attr()', function () { + it('will catch transform attribues and convert them to patternTransform', function () { + expect(pattern.translate(100, 100).attr('patternTransform')).toBe('matrix(1,0,0,1,100,100)') }) }) - describe('toString()', function() { - it('returns the id of the pattern wrapped in url()', function() { - expect(pattern + '').toBe('url(#' + pattern.id() + ')') + describe('toString()', function () { + it('returns the id of the pattern wrapped in url()', function () { + expect(pattern + '').toBe('url("#' + pattern.id() + '")') }) - it('is called when instance is passed as an attribute value', function() { + it('is called when instance is passed as an attribute value', function () { rect.attr('fill', pattern) - expect(rect.attr('fill')).toBe('url(#' + pattern.id() + ')') + expect(rect.attr('fill')).toBe('url("#' + pattern.id() + '")') }) - it('is called when instance is passed in a fill() method', function() { + it('is called when instance is passed in a fill() method', function () { rect.fill(pattern) - expect(rect.attr('fill')).toBe('url(#' + pattern.id() + ')') + expect(rect.attr('fill')).toBe('url("#' + pattern.id() + '")') }) }) - describe('update()', function() { + describe('update()', function () { - it('removes all existing children first', function() { - pattern = draw.pattern(30, 30, function(add) { - add.rect(10,10).move(10,10) + it('removes all existing children first', function () { + pattern = draw.pattern(30, 30, function (add) { + add.rect(10, 10).move(10, 10) add.circle(30) }) expect(pattern.children().length).toBe(2) - pattern.update(function(add) { - add.rect(10,10).move(10,10) + pattern.update(function (add) { + add.rect(10, 10).move(10, 10) add.circle(30) }) expect(pattern.children().length).toBe(2) -- 2.39.5