summaryrefslogtreecommitdiff
path: root/src/components/ui
diff options
context:
space:
mode:
authorBertrand Yuan <189593334+bertyuan@users.noreply.github.com>2026-04-07 11:25:10 +0800
committerGitHub <noreply@github.com>2026-04-07 11:25:10 +0800
commitede83fe814b50a33e619737363e6d0cfbba73d16 (patch)
treecb562a3146445b3fa80e8f2c66674061a816701d /src/components/ui
parent2ef9e56c390508f52d8734ba36fa4a23bec3558e (diff)
parenta3c86dbdff661303a5b3e1957f485eca2eae2414 (diff)
Merge pull request #17 from bertyuan/revert-15-tast
Revert "A small portion of newly added unit testing code"
Diffstat (limited to 'src/components/ui')
-rw-r--r--src/components/ui/button.test.tsx36
-rw-r--r--src/components/ui/card.test.tsx24
-rw-r--r--src/components/ui/input.test.tsx16
3 files changed, 0 insertions, 76 deletions
diff --git a/src/components/ui/button.test.tsx b/src/components/ui/button.test.tsx
index a15e0a0..f8bd3a9 100644
--- a/src/components/ui/button.test.tsx
+++ b/src/components/ui/button.test.tsx
@@ -66,40 +66,4 @@ 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');
- });
});
diff --git a/src/components/ui/card.test.tsx b/src/components/ui/card.test.tsx
index 0c29c5d..aba3d00 100644
--- a/src/components/ui/card.test.tsx
+++ b/src/components/ui/card.test.tsx
@@ -36,29 +36,5 @@ describe('Card', () => {
expect(screen.getByText('Content')).toHaveAttribute('data-slot', 'card-content');
expect(screen.getByText('Footer')).toHaveAttribute('data-slot', 'card-footer');
});
-
- test('appends custom class names correctly', () => {
- render(
- <Card className="my-custom-card-class">
- <CardContent className="my-custom-content-class">Content</CardContent>
- </Card>
- );
-
- const cardElement = screen.getByText('Content').parentElement; // 或者直接给 Card 加个 data-testid
- expect(cardElement).toHaveClass('my-custom-card-class');
- expect(screen.getByText('Content')).toHaveClass('my-custom-content-class');
- });
-
- test('passes standard HTML attributes to the DOM node', () => {
- render(
- <Card id="test-card" aria-label="Test Card">
- <CardContent data-testid="content-id">Content</CardContent>
- </Card>
- );
-
- const cardElement = screen.getByLabelText('Test Card');
- expect(cardElement).toHaveAttribute('id', 'test-card');
- expect(screen.getByTestId('content-id')).toBeInTheDocument();
- });
});
diff --git a/src/components/ui/input.test.tsx b/src/components/ui/input.test.tsx
index 036352b..aabe76f 100644
--- a/src/components/ui/input.test.tsx
+++ b/src/components/ui/input.test.tsx
@@ -1,8 +1,6 @@
import { render, screen } from '@testing-library/react';
import { describe, expect, test } from 'vitest';
import { Input } from './input';
-import userEvent from '@testing-library/user-event';
-import { vi } from 'vitest';
describe('Input', () => {
test('renders an input with the expected slot attribute', () => {
@@ -20,19 +18,5 @@ describe('Input', () => {
expect(input).toHaveAttribute('type', 'password');
expect(input).toBeDisabled();
});
-
- test('handles user typing and triggers onChange event', async () => {
- const user = userEvent.setup();
- const handleChange = vi.fn();
-
- render(<Input aria-label="Username" onChange={handleChange} />);
- const input = screen.getByLabelText('Username');
-
- await user.type(input, 'hello world');
-
- expect(input).toHaveValue('hello world');
- expect(handleChange).toHaveBeenCalled();
- expect(handleChange).toHaveBeenCalledTimes(11);
- });
});