From a55eac74fcfe25d3ec7b9eb250adc18318629e7a Mon Sep 17 00:00:00 2001 From: Philip Molares Date: Fri, 1 Nov 2024 15:12:57 +0100 Subject: [PATCH] test: add tests for convertInlineStyleToMap With the new code added, it seemed like good opportunity to add some tests here. Signed-off-by: Philip Molares --- .../src/utils/convertInlineStyleToMap.spec.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 html-to-react/src/utils/convertInlineStyleToMap.spec.ts diff --git a/html-to-react/src/utils/convertInlineStyleToMap.spec.ts b/html-to-react/src/utils/convertInlineStyleToMap.spec.ts new file mode 100644 index 000000000..175d95a30 --- /dev/null +++ b/html-to-react/src/utils/convertInlineStyleToMap.spec.ts @@ -0,0 +1,29 @@ +/* + * SPDX-FileCopyrightText: 2024 The HedgeDoc developers (see AUTHORS file) + * + * SPDX-License-Identifier: AGPL-3.0-only + */ +import { convertInlineStyleToMap } from './convertInlineStyleToMap.js' + +describe('convertInlineStyleToMap', () => { + it('should split on normal ;', () => { + const styleObject = convertInlineStyleToMap('display: flex;flex-flow: row;') + expect(Object.keys(styleObject)).toHaveLength(2) + expect(styleObject.display).toEqual('flex') + expect(styleObject.flexFlow).toEqual('row') + }) + it('should not split on a ; in string', () => { + const styleObject = convertInlineStyleToMap( + "background-image: url('data:image/svg+xml;base64,...');" + ) + expect(Object.keys(styleObject)).toHaveLength(1) + expect(styleObject.backgroundImage).toEqual( + "url('data:image/svg+xml;base64,...')" + ) + }) + it('should not split on an escaped ;', () => { + const styleObject = convertInlineStyleToMap('content: \\;;') + expect(Object.keys(styleObject)).toHaveLength(1) + expect(styleObject.content).toEqual('\\;') + }) +})