-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create validateConditionalVariants.test.ts
- Loading branch information
1 parent
6357536
commit 1aa3a58
Showing
1 changed file
with
123 additions
and
0 deletions.
There are no files selected for viewing
123 changes: 123 additions & 0 deletions
123
packages/lib/src/utils/__tests__/validateConditionalVariants.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { validateConditionalVariants } from "../validateConditionalVariants"; | ||
|
||
describe("validateConditionalVariants", () => { | ||
it("should return `true` if there are variant conditions are undefined", () => { | ||
const variants = undefined; | ||
const defaults = undefined; | ||
|
||
const condition = { | ||
// Variant conditons are missing | ||
classes: { | ||
root: "!bg-green-500", | ||
}, | ||
}; | ||
|
||
const result = validateConditionalVariants({ | ||
condition, | ||
variants, | ||
defaults, | ||
}); | ||
|
||
expect(result).toEqual(true); | ||
}); | ||
|
||
it("should return `true` if there are no variant conditions", () => { | ||
const variants = undefined; | ||
const defaults = undefined; | ||
|
||
const condition = { | ||
variants: {}, // This is all that matters | ||
classes: { | ||
root: "!bg-green-500", | ||
}, | ||
}; | ||
|
||
const result = validateConditionalVariants({ | ||
condition, | ||
variants, | ||
defaults, | ||
}); | ||
|
||
expect(result).toEqual(true); | ||
}); | ||
|
||
it("should return `true` if variant conditions are met", () => { | ||
const variants = { intent: "default" }; | ||
const defaults = undefined; | ||
|
||
const condition = { | ||
variants: { intent: "default" }, // Variant conditions match above as a string | ||
classes: { | ||
root: "!bg-green-500", | ||
}, | ||
}; | ||
|
||
const result = validateConditionalVariants({ | ||
condition, | ||
variants, | ||
defaults, | ||
}); | ||
|
||
expect(result).toEqual(true); | ||
}); | ||
|
||
it("should return `true` if variant conditions are met with default variant", () => { | ||
const variants = undefined; | ||
const defaults = { intent: "default" }; | ||
|
||
const condition = { | ||
variants: { intent: "default" }, // Variant conditions match above as a string | ||
classes: { | ||
root: "!bg-green-500", | ||
}, | ||
}; | ||
|
||
const result = validateConditionalVariants({ | ||
condition, | ||
variants, | ||
defaults, | ||
}); | ||
|
||
expect(result).toEqual(true); | ||
}); | ||
|
||
it("should return `true` if variant conditions are met with default variants as an array", () => { | ||
const variants = undefined; | ||
const defaults = { intent: "outline" }; | ||
|
||
const condition = { | ||
variants: { intent: ["default", "outline"] }, // Variant conditions match defaults above | ||
classes: { | ||
root: "!bg-green-500", | ||
}, | ||
}; | ||
|
||
const result = validateConditionalVariants({ | ||
condition, | ||
variants, | ||
defaults, | ||
}); | ||
|
||
expect(result).toEqual(true); | ||
}); | ||
|
||
it("should return `true` if variant conditions are met within an array", () => { | ||
const variants = { intent: "outline" }; | ||
const defaults = undefined; | ||
|
||
const condition = { | ||
variants: { intent: ["default", "outline"] }, // Variant conditions match above | ||
classes: { | ||
root: "!bg-green-500", | ||
}, | ||
}; | ||
|
||
const result = validateConditionalVariants({ | ||
condition, | ||
variants, | ||
defaults, | ||
}); | ||
|
||
expect(result).toEqual(true); | ||
}); | ||
}); |