From 6ce30b15f688423bd5c2a8e3a010bec7c0d7a5a9 Mon Sep 17 00:00:00 2001 From: Atul Varma Date: Wed, 3 Mar 2021 19:50:23 -0500 Subject: [PATCH] Ignore spec colors we don't recognize. --- .../vocabulary-builder.test.ts.snap | 18 +++++++++ lib/specs.ts | 6 ++- lib/vocabulary-builder.test.ts | 37 +++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/lib/__snapshots__/vocabulary-builder.test.ts.snap b/lib/__snapshots__/vocabulary-builder.test.ts.snap index 3ccddd8..0693b15 100644 --- a/lib/__snapshots__/vocabulary-builder.test.ts.snap +++ b/lib/__snapshots__/vocabulary-builder.test.ts.snap @@ -1,5 +1,23 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`convertSvgMarkupToSymbolData() processes specs 1`] = ` +Object { + "anchor": Array [ + Object { + "normal": Object { + "x": 0, + "y": -1, + }, + "point": Object { + "t": 0, + "x": 360, + "y": 701.804, + }, + }, + ], +} +`; + exports[`convertSvgMarkupToSymbolData() works with SVGs that just have a path and no specs 1`] = ` Object { "bbox": Object { diff --git a/lib/specs.ts b/lib/specs.ts index 9562a31..9bd52fe 100644 --- a/lib/specs.ts +++ b/lib/specs.ts @@ -141,7 +141,11 @@ function updateSpecs(fill: string, path: string, specs: Specs): Specs { }; } - throw new Error(`Not sure what to do with specs path with fill "${fill}"!`); + console.log( + `Not sure what to do with specs path with fill "${fill}", ignoring it.` + ); + + return specs; } function getSpecs(layers: SvgSymbolElement[]): Specs { diff --git a/lib/vocabulary-builder.test.ts b/lib/vocabulary-builder.test.ts index f1d36e4..71ae0ba 100644 --- a/lib/vocabulary-builder.test.ts +++ b/lib/vocabulary-builder.test.ts @@ -2,10 +2,47 @@ import { convertSvgMarkupToSymbolData } from "./vocabulary-builder"; const CIRCLE = ``; +function arrow(color: string) { + return ``; +} + +function withMockConsoleLog(fn: (mock: jest.Mock) => void) { + const originalLog = console.log; + const mockLog = jest.fn(); + console.log = mockLog; + try { + fn(mockLog); + } finally { + console.log = originalLog; + } +} + describe("convertSvgMarkupToSymbolData()", () => { it("works with SVGs that just have a path and no specs", () => { expect( convertSvgMarkupToSymbolData("blarg.svg", `${CIRCLE}`) ).toMatchSnapshot(); }); + + it("processes specs", () => { + const result = convertSvgMarkupToSymbolData( + "blarg.svg", + `${CIRCLE}${arrow("#ff0000")}` + ); + expect(result.specs?.anchor).toHaveLength(1); + expect(result.specs).toMatchSnapshot(); + }); + + it("ignores colors in specs it doesn't understand", () => { + withMockConsoleLog((mockLog) => { + const result = convertSvgMarkupToSymbolData( + "blarg.svg", + `${CIRCLE}${arrow("#f1f1f1")}` + ); + expect(result.specs).toEqual({}); + expect(mockLog).toHaveBeenCalledWith( + 'Not sure what to do with specs path with fill "#f1f1f1", ignoring it.' + ); + }); + }); });