feat: add concat-css-classes helper method

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2023-05-19 17:57:15 +02:00
parent d7663e3090
commit 4eb341308a
19 changed files with 129 additions and 41 deletions

View file

@ -0,0 +1,32 @@
/*
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { concatCssClasses } from './concat-css-classes'
describe('concat css classes', () => {
it('works with a map', () => {
expect(concatCssClasses({ a: true, b: false, c: true })).toBe('a c')
})
it('works with a string array ', () => {
expect(concatCssClasses('a', 'b', 'c')).toBe('a b c')
})
it('works with a string array and map', () => {
expect(concatCssClasses('a', 'b', 'c', { d: true, e: false, f: true })).toBe('a b c d f')
})
it("doesn't include undefined and null", () => {
expect(concatCssClasses(undefined, null)).toBe('')
})
it("doesn't include duplicates", () => {
expect(concatCssClasses('a', 'a', { a: true })).toBe('a')
})
it("doesn't include empty class names", () => {
expect(concatCssClasses('a', '', { '': true })).toBe('a')
})
})