Skip to content

Commit

Permalink
[refactor] test code 작성 #402
Browse files Browse the repository at this point in the history
  • Loading branch information
Kisun Park committed Apr 2, 2024
1 parent 418c927 commit 1b0c1e8
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 6 deletions.
51 changes: 45 additions & 6 deletions __tests__/page.test.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,52 @@
import Page from '../src/app/page';
import { OwnerButtonLayer } from '@/component/Personal';
import { themeObj } from '@/types/theme';
import '@testing-library/jest-dom';
import { render, screen } from '@testing-library/react';

describe('Page', () => {
it('renders a heading', () => {
render(<Page />);
describe('OwnerButtonLayer 컴포넌트 테스트', () => {
it('isEdit가 false일 때 편집, 공유하기, 글쓰기 버튼이 정상적으로 렌더링되는지 확인', () => {
render(
<OwnerButtonLayer
handleClickEdit={() => {}}
handleClickShare={() => {}}
handleClickWrite={() => {}}
theme={themeObj.chris}
isEdit={false}
handleClickDelete={() => {}}
/>,
);

const heading = screen.getByRole('heading', { level: 1 });
// "편집" 버튼을 기준으로 컴포넌트가 렌더링되었는지 확인합니다.
const editButton = screen.getByRole('button', { name: '편집' });
expect(editButton).toBeInTheDocument();

expect(heading).toBeInTheDocument();
// "공유하기" 버튼이 렌더링되었는지 확인합니다.
const shareButton = screen.getByRole('button', { name: '공유하기' });
expect(shareButton).toBeInTheDocument();

// "글쓰기" 버튼이 렌더링되었는지 확인합니다.
const writeButton = screen.getByRole('button', { name: '글쓰기' });
expect(writeButton).toBeInTheDocument();
});

it('isEdit가 true일 때 "선택 삭제" 및 "취소" 버튼이 정상적으로 렌더링되는지 확인', () => {
render(
<OwnerButtonLayer
handleClickEdit={() => {}}
handleClickShare={() => {}}
handleClickWrite={() => {}}
theme={themeObj.chris}
isEdit={true}
handleClickDelete={() => {}}
/>,
);

// "선택 삭제" 버튼을 기준으로 컴포넌트가 렌더링되었는지 확인합니다.
const deleteButton = screen.getByRole('button', { name: '선택 삭제' });
expect(deleteButton).toBeInTheDocument();

// "취소" 버튼이 렌더링되었는지 확인합니다.
const cancelButton = screen.getByRole('button', { name: '취소' });
expect(cancelButton).toBeInTheDocument();
});
});
132 changes: 132 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"prettier-plugin-tailwindcss": "^0.5.9",
"tailwind-scrollbar": "^3.0.5",
"tailwindcss": "^3.3.3",
"ts-node": "^10.9.2",
"typescript": "^5"
}
}

0 comments on commit 1b0c1e8

Please sign in to comment.