summaryrefslogtreecommitdiff
path: root/src/components/ui/button.test.tsx
diff options
context:
space:
mode:
authorNorton <2773923088@qq。>2026-04-06 14:32:33 +0800
committerNorton <2773923088@qq。>2026-04-06 14:32:33 +0800
commit18fc18761dbefc2ab2fbaf93e1fe433eb0b47b37 (patch)
tree8c5c83f9e45387123e79f3431d1eb1ab66a020ea /src/components/ui/button.test.tsx
parentf247a8c4a863ec430f4a705b5c493d652c8429bd (diff)
A small portion of newly added unit testing code
Diffstat (limited to 'src/components/ui/button.test.tsx')
-rw-r--r--src/components/ui/button.test.tsx36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/components/ui/button.test.tsx b/src/components/ui/button.test.tsx
index f8bd3a9..a15e0a0 100644
--- a/src/components/ui/button.test.tsx
+++ b/src/components/ui/button.test.tsx
@@ -66,4 +66,40 @@ describe('Button', () => {
expect(link).toBeInTheDocument();
expect(link.tagName).toBe('A');
});
+
+ // Test custom className merging
+ test('merges custom className correctly', () => {
+ render(<Button className="my-custom-test-class">Custom Class</Button>);
+ const button = screen.getByText('Custom Class');
+
+ // It should have the newly added class
+ expect(button).toHaveClass('my-custom-test-class');
+ // It should also retain the base classes defined in cva
+ expect(button).toHaveClass('inline-flex', 'items-center');
+ });
+
+ // Test native HTML props forwarding
+ test('passes native HTML attributes correctly', () => {
+ render(
+ <Button type="submit" aria-label="Submit Form" data-testid="submit-btn">
+ Submit
+ </Button>
+ );
+ const button = screen.getByTestId('submit-btn');
+
+ expect(button).toHaveAttribute('type', 'submit');
+ expect(button).toHaveAttribute('aria-label', 'Submit Form');
+ });
+
+ // Optimized: Test buttons with different variants by checking classes
+ test('applies specific classes for different variants', () => {
+ render(<Button variant="destructive">Destructive</Button>);
+ const destructiveButton = screen.getByText('Destructive');
+ // Verify that the specific Tailwind class from cva is applied
+ expect(destructiveButton).toHaveClass('bg-destructive', 'text-white');
+
+ render(<Button variant="outline">Outline</Button>);
+ const outlineButton = screen.getByText('Outline');
+ expect(outlineButton).toHaveClass('border', 'bg-background');
+ });
});