Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Tab): 유닛 테스트 코드를 작성합니다. #156

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions apps/docs/src/stories/Tab.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import type { Meta, StoryObj } from "@storybook/react";
import { Tab } from "@sopt-makers/ui";
import type { Meta, StoryObj } from '@storybook/react';
import { Tab } from '@sopt-makers/ui';

const meta = {
title: "Components/Tab",
title: 'Components/Tab',
component: Tab,
tags: ["autodocs"],
tags: ['autodocs'],
args: {
tabItems: ['Tab1', 'Tab2', 'Tab3'],
selectedInitial: 'Tab1',
translator: { Tab1: '탭1', Tab2: '탭2', Tab3: '탭3' },
},
argTypes: {
style: { control: 'radio', options: ['primary', 'secondary'] },
size: { control: 'radio', options: ['sm', 'md', 'lg'] },
selectedInitial: { control: 'select', options: ['Tab1', 'Tab2', 'Tab3'] },
}
},
} as Meta<typeof Tab>;

export default meta;
Expand Down
28 changes: 28 additions & 0 deletions packages/ui/Tab/test/Tab.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { render, screen, fireEvent } from '@testing-library/react';
import { describe, it, expect, vi } from 'vitest';
import Tab from '../Tab';

describe('Tab 컴포넌트는', () => {
const mockOnChange = vi.fn();
const tabItems = ['Tab1', 'Tab2', 'Tab3'];

function renderTab() {
render(<Tab onChange={mockOnChange} size='md' style='primary' tabItems={tabItems} />);
}

it('정상적으로 렌더링이 됩니다.', () => {
renderTab();

tabItems.forEach((item) => {
expect(screen.getByText(item)).toBeInTheDocument();
});
});

it('탭을 클릭하면 onChange 핸들러가 호출됩니다.', () => {
renderTab();

fireEvent.click(screen.getByText('Tab2'));

expect(mockOnChange).toHaveBeenCalledWith('Tab2');
});
});
Loading