Skip to content

Commit

Permalink
コメントモデルのcontentフィールドをtextフィールドに変更し、関連するコンポーネントとテストを更新しました。
Browse files Browse the repository at this point in the history
  • Loading branch information
ttizze committed Jan 19, 2025
1 parent 2bf12ee commit b69ce5f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
10 changes: 4 additions & 6 deletions web/app/routes/resources+/comment/components/CommentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function CommentForm({
shouldValidate: "onInput",
defaultValue: {
pageId: pageId,
content: "",
text: "",
},
});

Expand All @@ -36,7 +36,7 @@ export function CommentForm({
<input type="hidden" name="pageId" value={pageId} />
<input type="hidden" name="intent" value="create" />
<Textarea
{...getTextareaProps(fields.content)}
{...getTextareaProps(fields.text)}
placeholder="comment"
className={`min-h-[100px] ${!currentUserName && "bg-muted"}`}
disabled={!currentUserName}
Expand All @@ -52,10 +52,8 @@ export function CommentForm({
{fetcher.state !== "idle" ? "posting" : "post"}
</Button>
</fetcher.Form>
{fields.content.errors && (
<p className="text-sm text-red-500">
{fields.content.errors?.join(", ")}
</p>
{fields.text.errors && (
<p className="text-sm text-red-500">{fields.text.errors?.join(", ")}</p>
)}
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function CommentList({
</div>
</div>
</div>
<div className="mt-2 whitespace-pre-wrap">{comment.content}</div>
<div className="mt-2 whitespace-pre-wrap">{comment.text}</div>
</div>
))}
</div>
Expand Down
10 changes: 5 additions & 5 deletions web/app/routes/resources+/comment/route.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe("resource+/comment/route.ts action", () => {
// prisma.create の返り値モック
const mockComment = {
id: 1,
content: "Hello",
text: "Hello",
pageId: 1,
userId: 123,
createdAt: new Date(),
Expand All @@ -52,7 +52,7 @@ describe("resource+/comment/route.ts action", () => {
const formData = new FormData();
formData.append("intent", "create");
formData.append("pageId", "1");
formData.append("content", "Hello");
formData.append("text", "Hello");

const request = new Request("http://test.com/comment", {
method: "POST",
Expand All @@ -64,7 +64,7 @@ describe("resource+/comment/route.ts action", () => {
// 正しい引数で create が呼ばれたか
expect(prisma.comment.create).toHaveBeenCalledWith({
data: {
content: "Hello",
text: "Hello",
pageId: 1,
userId: 123,
},
Expand Down Expand Up @@ -129,7 +129,7 @@ describe("resource+/comment/route.ts action", () => {
vi.mocked(prisma.comment.findUnique).mockResolvedValueOnce({
id: 10,
userId: 999,
content: "Hello",
text: "Hello",
pageId: 1,
createdAt: new Date(),
updatedAt: new Date(),
Expand Down Expand Up @@ -171,7 +171,7 @@ describe("resource+/comment/route.ts action", () => {
vi.mocked(prisma.comment.findUnique).mockResolvedValueOnce({
id: 10,
userId: 123,
content: "Hello",
text: "Hello",
pageId: 1,
createdAt: new Date(),
updatedAt: new Date(),
Expand Down
4 changes: 2 additions & 2 deletions web/app/routes/resources+/comment/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { prisma } from "~/utils/prisma";

export const createCommentSchema = z.object({
pageId: z.number(),
content: z.string().min(1, "Comment cannot be empty"),
text: z.string().min(1, "Comment cannot be empty"),
intent: z.literal("create"),
});

Expand Down Expand Up @@ -38,7 +38,7 @@ export async function action({ request }: ActionFunctionArgs) {
case "create": {
const comment = await prisma.comment.create({
data: {
content: submission.value.content,
text: submission.value.text,
pageId: submission.value.pageId,
userId: currentUser.id,
},
Expand Down

0 comments on commit b69ce5f

Please sign in to comment.