|
| 1 | +/** |
| 2 | + * Copyright 2025 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE/2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import { describe, it, expect } from "vitest"; |
| 18 | +import { buttonVariant, type ButtonVariant } from "./index"; |
| 19 | + |
| 20 | +describe("buttonVariant", () => { |
| 21 | + it("should return base class when no variant is provided", () => { |
| 22 | + const result = buttonVariant(); |
| 23 | + expect(result).toBe("fui-button"); |
| 24 | + }); |
| 25 | + |
| 26 | + it("should return base class with primary variant (default)", () => { |
| 27 | + const result = buttonVariant({ variant: "primary" }); |
| 28 | + expect(result).toBe("fui-button"); |
| 29 | + }); |
| 30 | + |
| 31 | + it("should return base class with secondary variant", () => { |
| 32 | + const result = buttonVariant({ variant: "secondary" }); |
| 33 | + expect(result).toBe("fui-button fui-button--secondary"); |
| 34 | + }); |
| 35 | + |
| 36 | + it("should handle empty variant object", () => { |
| 37 | + const result = buttonVariant({}); |
| 38 | + expect(result).toBe("fui-button"); |
| 39 | + }); |
| 40 | + |
| 41 | + it("should handle undefined variant", () => { |
| 42 | + const result = buttonVariant({ variant: undefined }); |
| 43 | + expect(result).toBe("fui-button"); |
| 44 | + }); |
| 45 | +}); |
| 46 | + |
| 47 | +describe("ButtonVariant type", () => { |
| 48 | + it("should accept valid variant values", () => { |
| 49 | + const primaryVariant: ButtonVariant = "primary"; |
| 50 | + const secondaryVariant: ButtonVariant = "secondary"; |
| 51 | + |
| 52 | + expect(primaryVariant).toBe("primary"); |
| 53 | + expect(secondaryVariant).toBe("secondary"); |
| 54 | + }); |
| 55 | + |
| 56 | + it("should work with buttonVariant function", () => { |
| 57 | + const variants: ButtonVariant[] = ["primary", "secondary"]; |
| 58 | + |
| 59 | + variants.forEach((variant) => { |
| 60 | + const result = buttonVariant({ variant }); |
| 61 | + expect(typeof result).toBe("string"); |
| 62 | + expect(result).toContain("fui-button"); |
| 63 | + }); |
| 64 | + }); |
| 65 | +}); |
0 commit comments