From 2d37411f5f2d764da41f93e65910b49f7f97d826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20M=C3=B8ller=20Jensen?= <26099018+JesmoDev@users.noreply.github.com> Date: Fri, 8 Dec 2023 13:18:43 +1300 Subject: [PATCH] add tests --- .../src/shared/utils/utils.test.ts | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/Umbraco.Web.UI.Client/src/shared/utils/utils.test.ts diff --git a/src/Umbraco.Web.UI.Client/src/shared/utils/utils.test.ts b/src/Umbraco.Web.UI.Client/src/shared/utils/utils.test.ts new file mode 100644 index 0000000000..b481c3d0da --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/shared/utils/utils.test.ts @@ -0,0 +1,39 @@ +import { expect } from '@open-wc/testing'; +import { splitStringToArray } from './split-string-to-array.js'; + +describe('splitStringToArray', () => { + it('splits and cleans a comma-separated string', () => { + const inputString = 'one, two, three, ,five'; + const result = splitStringToArray(inputString); + + expect(result).to.deep.equal(['one', 'two', 'three', 'five']); + }); + + it('handles custom delimiters', () => { + const inputString = 'apple | orange | banana'; + const result = splitStringToArray(inputString, ' | '); + + expect(result).to.deep.equal(['apple', 'orange', 'banana']); + }); + + it('handles strings with no non-empty elements', () => { + const inputString = ', , , , '; + const result = splitStringToArray(inputString); + + expect(result).to.deep.equal([]); + }); + + it('trims whitespace from each element', () => { + const inputString = ' one , two , three '; + const result = splitStringToArray(inputString); + + expect(result).to.deep.equal(['one', 'two', 'three']); + }); + + it('returns an empty array for an empty string', () => { + const inputString = ''; + const result = splitStringToArray(inputString); + + expect(result).to.deep.equal([]); + }); +});