Skip to content

Commit b69ce5f

Browse files
committed
コメントモデルのcontentフィールドをtextフィールドに変更し、関連するコンポーネントとテストを更新しました。
1 parent 2bf12ee commit b69ce5f

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

web/app/routes/resources+/comment/components/CommentForm.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function CommentForm({
2121
shouldValidate: "onInput",
2222
defaultValue: {
2323
pageId: pageId,
24-
content: "",
24+
text: "",
2525
},
2626
});
2727

@@ -36,7 +36,7 @@ export function CommentForm({
3636
<input type="hidden" name="pageId" value={pageId} />
3737
<input type="hidden" name="intent" value="create" />
3838
<Textarea
39-
{...getTextareaProps(fields.content)}
39+
{...getTextareaProps(fields.text)}
4040
placeholder="comment"
4141
className={`min-h-[100px] ${!currentUserName && "bg-muted"}`}
4242
disabled={!currentUserName}
@@ -52,10 +52,8 @@ export function CommentForm({
5252
{fetcher.state !== "idle" ? "posting" : "post"}
5353
</Button>
5454
</fetcher.Form>
55-
{fields.content.errors && (
56-
<p className="text-sm text-red-500">
57-
{fields.content.errors?.join(", ")}
58-
</p>
55+
{fields.text.errors && (
56+
<p className="text-sm text-red-500">{fields.text.errors?.join(", ")}</p>
5957
)}
6058
</>
6159
);

web/app/routes/resources+/comment/components/CommentList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export function CommentList({
7272
</div>
7373
</div>
7474
</div>
75-
<div className="mt-2 whitespace-pre-wrap">{comment.content}</div>
75+
<div className="mt-2 whitespace-pre-wrap">{comment.text}</div>
7676
</div>
7777
))}
7878
</div>

web/app/routes/resources+/comment/route.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe("resource+/comment/route.ts action", () => {
3636
// prisma.create の返り値モック
3737
const mockComment = {
3838
id: 1,
39-
content: "Hello",
39+
text: "Hello",
4040
pageId: 1,
4141
userId: 123,
4242
createdAt: new Date(),
@@ -52,7 +52,7 @@ describe("resource+/comment/route.ts action", () => {
5252
const formData = new FormData();
5353
formData.append("intent", "create");
5454
formData.append("pageId", "1");
55-
formData.append("content", "Hello");
55+
formData.append("text", "Hello");
5656

5757
const request = new Request("http://test.com/comment", {
5858
method: "POST",
@@ -64,7 +64,7 @@ describe("resource+/comment/route.ts action", () => {
6464
// 正しい引数で create が呼ばれたか
6565
expect(prisma.comment.create).toHaveBeenCalledWith({
6666
data: {
67-
content: "Hello",
67+
text: "Hello",
6868
pageId: 1,
6969
userId: 123,
7070
},
@@ -129,7 +129,7 @@ describe("resource+/comment/route.ts action", () => {
129129
vi.mocked(prisma.comment.findUnique).mockResolvedValueOnce({
130130
id: 10,
131131
userId: 999,
132-
content: "Hello",
132+
text: "Hello",
133133
pageId: 1,
134134
createdAt: new Date(),
135135
updatedAt: new Date(),
@@ -171,7 +171,7 @@ describe("resource+/comment/route.ts action", () => {
171171
vi.mocked(prisma.comment.findUnique).mockResolvedValueOnce({
172172
id: 10,
173173
userId: 123,
174-
content: "Hello",
174+
text: "Hello",
175175
pageId: 1,
176176
createdAt: new Date(),
177177
updatedAt: new Date(),

web/app/routes/resources+/comment/route.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { prisma } from "~/utils/prisma";
66

77
export const createCommentSchema = z.object({
88
pageId: z.number(),
9-
content: z.string().min(1, "Comment cannot be empty"),
9+
text: z.string().min(1, "Comment cannot be empty"),
1010
intent: z.literal("create"),
1111
});
1212

@@ -38,7 +38,7 @@ export async function action({ request }: ActionFunctionArgs) {
3838
case "create": {
3939
const comment = await prisma.comment.create({
4040
data: {
41-
content: submission.value.content,
41+
text: submission.value.text,
4242
pageId: submission.value.pageId,
4343
userId: currentUser.id,
4444
},

0 commit comments

Comments
 (0)