From 4c5d71d070f79ed0142f8c3f86f4915e901a0123 Mon Sep 17 00:00:00 2001 From: Rodney Leviton Date: Fri, 17 Nov 2023 19:25:13 +1100 Subject: [PATCH] Create getConditionalClasses.test.ts --- .../__tests__/getConditionalClasses.test.ts | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 packages/lib/src/utils/__tests__/getConditionalClasses.test.ts diff --git a/packages/lib/src/utils/__tests__/getConditionalClasses.test.ts b/packages/lib/src/utils/__tests__/getConditionalClasses.test.ts new file mode 100644 index 0000000..d5be7b8 --- /dev/null +++ b/packages/lib/src/utils/__tests__/getConditionalClasses.test.ts @@ -0,0 +1,47 @@ +import { getConditionalClasses } from "../getConditionalClasses"; + +describe("getConditionalClasses", () => { + it("should return an empty object if there are no conditions", () => { + const theme = { conditionals: undefined }; + + const result = getConditionalClasses({ theme }); + + expect(result).toEqual({}); + }); + + it("should return empty object if conditons are not met", () => { + const modifiers = ["floating"]; + const theme = { + conditionals: [ + { + modifiers: "block", // Modifier conditions match defaults above as a string + classes: { + root: "!bg-green-500", + }, + }, + ], + }; + + const result = getConditionalClasses({ theme, modifiers }); + + expect(result).toEqual({ root: "!bg-green-500" }); + }); + + it("should return correct classes if conditons are met", () => { + const modifiers = ["block"]; + const theme = { + conditionals: [ + { + modifiers: "block", // Modifier conditions match defaults above as a string + classes: { + root: "!bg-green-500", + }, + }, + ], + }; + + const result = getConditionalClasses({ theme, modifiers }); + + expect(result).toEqual({ root: "!bg-green-500" }); + }); +});