Skip to content

Commit

Permalink
feat(panel-page): 질문 생성 모달 열기 버튼 누르면 모달 보여준다 (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
leegwae committed Aug 23, 2023
1 parent 6c413a2 commit d72091a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/pages/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import {

import { InfiniteQuestionList } from '@/components/panel/InfiniteQuestionList';
import { PanelHeader } from '@/components/panel/PanelHeader';
import { Logo } from '@/components/vectors';
import { ModalController } from '@/components/system/ModalController';
import { Send, Logo } from '@/components/vectors';
import { useOverlay } from '@/hooks/useOverlay';
import { getPanel } from '@/lib/api/panel';
import { ApiError } from '@/lib/apiClient';
// [NOTE] 로더 성공 반환값은 any 혹은 null로 고정한다
Expand Down Expand Up @@ -44,13 +46,33 @@ export const panelLoader: LoaderFunction = async ({ params }) => {

export function Panel(): JSX.Element {
const panel = useLoaderData() as PanelData;
const overlay = useOverlay();

function handleOpenModal(): void {
overlay.open(({ close }) => (
<ModalController close={close} aria-label="질문 생성 모달">
질문 생성 모달
</ModalController>
));
}
return (
<main>
<PanelHeader panel={panel} />
<div className="container flex flex-col h-full max-w-2xl px-5 py-7">
<InfiniteQuestionList panelId={panel.id} />
</div>
<button
className={clsx(
'fixed bottom-0 right-0 m-7 p-3',
'rounded-full bg-primary shadow-3xl',
'hover:bg-primary-hover',
)}
type="button"
onClick={handleOpenModal}
>
<Send className="w-9 h-9 fill-white" />
<span className="sr-only">질문 생성 모달 열기</span>
</button>
</main>
);
}
Expand Down
16 changes: 16 additions & 0 deletions src/pages/__tests__/Panel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { Panel as PanelData } from '@/lib/api/panel';
import React from 'react';

import { screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import { OverlayProvider } from '@/contexts/OverlayContext';
import { renderWithQueryClient } from '@/lib/test-utils';
Expand Down Expand Up @@ -41,4 +42,19 @@ describe('패널 페이지', () => {
).toBeInTheDocument();
});
});

it('질문 생성 모달 열기 버튼을 누르면 질문 생성 모달을 보여준다', async () => {
renderWithQueryClient(
<OverlayProvider>
<Panel />
</OverlayProvider>,
);

const openButton = screen.getByRole('button', {
name: /질문 생성 모달 열기/,
});
await userEvent.click(openButton);

expect(screen.getByRole('dialog', { name: /질문 생성 모달/ }));
});
});

0 comments on commit d72091a

Please sign in to comment.