From 2bc7b66324d6fbf9d0d04f1f96cbebdd65c97fb4 Mon Sep 17 00:00:00 2001 From: Gani Date: Mon, 25 Mar 2024 11:53:23 +0300 Subject: [PATCH] Testing: add tests to roosterjs-react --- .../colorPicker/utils/backgroundColorsTest.ts | 25 +++++++++++++++++++ .../test/colorPicker/utils/textColorsTest.ts | 24 ++++++++++++++++++ packages/roosterjs-react/test/emptyTest.ts | 2 -- 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 packages/roosterjs-react/test/colorPicker/utils/backgroundColorsTest.ts create mode 100644 packages/roosterjs-react/test/colorPicker/utils/textColorsTest.ts delete mode 100644 packages/roosterjs-react/test/emptyTest.ts diff --git a/packages/roosterjs-react/test/colorPicker/utils/backgroundColorsTest.ts b/packages/roosterjs-react/test/colorPicker/utils/backgroundColorsTest.ts new file mode 100644 index 00000000000..20422d14023 --- /dev/null +++ b/packages/roosterjs-react/test/colorPicker/utils/backgroundColorsTest.ts @@ -0,0 +1,25 @@ +import { BackgroundColorKeys } from 'roosterjs-react'; +import { + BackgroundColorDropDownItems, + BackgroundColors, + getBackgroundColorValue, +} from '../../../lib/colorPicker/utils/backgroundColors'; + +describe('getBackgroundColorValue', () => { + it('returns the value of each key in TextColors', () => { + Object.keys(BackgroundColorDropDownItems).forEach(key => { + const output = getBackgroundColorValue(key as BackgroundColorKeys); + const expectedOutput = BackgroundColors[key]; + + expect(output.lightModeColor).toBe(expectedOutput.lightModeColor); + expect(output.darkModeColor).toBe(expectedOutput.darkModeColor); + }); + }); + + it('throws an error for none existing key', () => { + const invalidKey = 'invalidKey'; + const output = getBackgroundColorValue(invalidKey as BackgroundColorKeys); + + expect(output).toBeUndefined(); + }); +}); diff --git a/packages/roosterjs-react/test/colorPicker/utils/textColorsTest.ts b/packages/roosterjs-react/test/colorPicker/utils/textColorsTest.ts new file mode 100644 index 00000000000..6f4a821ca0a --- /dev/null +++ b/packages/roosterjs-react/test/colorPicker/utils/textColorsTest.ts @@ -0,0 +1,24 @@ +import { TextColorKeys } from 'roosterjs-react'; +import { + getTextColorValue, + TextColorDropDownItems, + TextColors, +} from '../../../lib/colorPicker/utils/textColors'; + +describe('getTextColorValue', () => { + it('returns the value of each key in TextColors', () => { + Object.keys(TextColorDropDownItems).forEach(key => { + const output = getTextColorValue(key as TextColorKeys); + const expectedOutput = TextColors[key]; + + expect(output.lightModeColor).toBe(expectedOutput.lightModeColor); + expect(output.darkModeColor).toBe(expectedOutput.darkModeColor); + }); + }); + + it('throws an error for none existing key', () => { + const invalidKey = 'invalidKey'; + const output = getTextColorValue(invalidKey as TextColorKeys); + expect(output).toBeUndefined(); + }); +}); diff --git a/packages/roosterjs-react/test/emptyTest.ts b/packages/roosterjs-react/test/emptyTest.ts deleted file mode 100644 index 155e460769f..00000000000 --- a/packages/roosterjs-react/test/emptyTest.ts +++ /dev/null @@ -1,2 +0,0 @@ -// Add this empty test file for now to pass the build -describe('roosterjs-react', () => {});