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

[홈 페이지] 패널 삭제 버튼 #326

Merged
merged 1 commit into from
Aug 14, 2023
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
9 changes: 9 additions & 0 deletions src/components/home/PanelActionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import React from 'react';

type Props = CreateOverlayContentProps & {
onUpdatePanelButtonClick: () => void;
onDeleteButtonClick: () => void;
};

export function PanelActionMenu({
close,
onUpdatePanelButtonClick,
onDeleteButtonClick,
}: Props): JSX.Element {
return (
<div className="flex flex-col">
Expand All @@ -20,6 +22,13 @@ export function PanelActionMenu({
>
패널 수정하기
</button>
<button
className="px-5 py-2 hover:bg-grey-lighter text-left"
type="button"
onClick={onDeleteButtonClick}
>
패널 삭제하기
</button>
</div>
</div>
);
Expand Down
15 changes: 14 additions & 1 deletion src/components/home/PanelGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ export function PanelGrid({ panelPages }: Props): JSX.Element {
[overlay],
);

const handleOpenDeletePanelModal = useCallback(
(panel: Panel) => {
overlay.open(({ close }) => (
<ModalController close={close}>패널 삭제 모달</ModalController>
));
},
[overlay],
);

const handleOpenPanelActionMenu = useCallback(
(panel: Panel) =>
({ close }: CreateOverlayContentProps) =>
Expand All @@ -40,9 +49,13 @@ export function PanelGrid({ panelPages }: Props): JSX.Element {
handleOpenUpdatePanelModal(panel);
close();
}}
onDeleteButtonClick={() => {
handleOpenDeletePanelModal(panel);
close();
}}
/>
),
[handleOpenUpdatePanelModal],
[handleOpenUpdatePanelModal, handleOpenDeletePanelModal],
);

if (panelPages.length === 0)
Expand Down
15 changes: 14 additions & 1 deletion src/components/home/__tests__/PanelActionMenu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { PanelActionMenu } from '@/components/home/PanelActionMenu';

const handleClose = vi.fn();
const handleUpdatePanel = vi.fn();
const handleDeletePanelButtonClick = vi.fn();

describe('PanelActionMenu', () => {
it('패널 수정하기 버튼을 누르면 onUpdatePanelButtonClick을 호출한다', async () => {
Expand All @@ -15,21 +16,33 @@ describe('PanelActionMenu', () => {

expect(handleUpdatePanel).toHaveBeenCalled();
});

it('패널 삭제 버튼을 누르면 onDeletePanelButtonClick을 호출한다', async () => {
const { deleteButton } = setup();
await userEvent.click(deleteButton);

expect(handleDeletePanelButtonClick).toHaveBeenCalled();
});
});

function setup(): {
updateButton: HTMLElement;
deleteButton: HTMLElement;
} {
render(
<PanelActionMenu
close={handleClose}
onUpdatePanelButtonClick={handleUpdatePanel}
onDeleteButtonClick={handleDeletePanelButtonClick}
/>,
);

const updateButton = screen.getByRole('button', {
name: /패널 수정하기/,
});
const deleteButton = screen.getByRole('button', {
name: /패널 삭제하기/,
});

return { updateButton };
return { updateButton, deleteButton };
}