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" }); + }); +});