Skip to content

Commit

Permalink
feat(answer-list): 질문 목록 컴포넌트를 분리한다 (#471)
Browse files Browse the repository at this point in the history
  • Loading branch information
leegwae authored and github-actions[bot] committed Sep 28, 2023
1 parent 5b69de9 commit ae45831
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/components/panel/AnswerList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { Answer } from '@/lib/api/answer';

import React from 'react';

import { Account } from '@/components/vectors';
import { formatDistance } from '@/lib/format-date';

interface Props {
nickname: string;
answers: Answer[];
now: Date;
}
export function AnswerList({ nickname, answers, now }: Props): JSX.Element {
return (
<ul>
{answers.map((answer) => (
<li
key={answer.id}
className="flex flex-col gap-3 p-5 w-full border-y border-grey-light"
>
<div className="flex items-center justify-between">
<div className="flex justify-start items-center gap-1 overflow-hidden">
<div role="img" aria-hidden>
<Account className="fill-grey-darkest" />
</div>
<div className="font-bold whitespace-nowrap">{nickname}</div>
<div className="text-grey-dark">
{formatDistance(now, new Date(answer.createdAt))}
</div>
</div>
</div>
<div className="whitespace-pre-wrap">{answer.content}</div>
</li>
))}
</ul>
);
}
25 changes: 25 additions & 0 deletions src/components/panel/__tests__/AnswerList.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { Answer } from '@/lib/api/answer';

import React from 'react';

import { render, screen } from '@testing-library/react';

import { createMockAnswer } from '@/mocks/data/answer';

import { AnswerList } from '../AnswerList';

describe('AnswerList', () => {
it('답변 내용과 답변자 닉네임을 보여준다', () => {
const answers: Answer[] = [
{ ...createMockAnswer(), content: '안녕하세요' },
{ ...createMockAnswer(), content: '반가워요' },
];
render(
<AnswerList nickname={'닉네임'} answers={answers} now={new Date()} />,
);

expect(screen.getByText(/안녕하세요/)).toBeInTheDocument();
expect(screen.getByText(/반가워요/)).toBeInTheDocument();
expect(screen.getByText(/닉네임/)).toBeInTheDocument();
});
});

0 comments on commit ae45831

Please sign in to comment.