Skip to content

Todo作成機能の実装#3

Open
gekko555 wants to merge 2 commits into
feature/pnpm-migrationfrom
feature/todo-create
Open

Todo作成機能の実装#3
gekko555 wants to merge 2 commits into
feature/pnpm-migrationfrom
feature/todo-create

Conversation

@gekko555
Copy link
Copy Markdown
Owner

@gekko555 gekko555 commented May 3, 2026

概要

Todoを新規作成するためのReactコンポーネントを追加しました。

ユーザーがタイトルを入力して「作成」ボタンを押すと、Todoオブジェクトを生成し、親コンポーネントへ onTodoCreate で渡します。

また、CodeRabbitの指摘を反映し、入力時のUX改善・テストの型チェック強化・Vitest設定のESM対応を行いました。あわせて、今後のレビューを日本語かつ初学者向けにするための .coderabbit.yaml も追加しています。

このPRで追加・変更したもの

Todo作成機能

  • Todo作成フォームコンポーネント TodoCreate を追加
  • Todoデータの型定義 Todo を追加
  • MUIを使った入力欄、ボタン、エラー表示を追加
  • 空文字・空白のみ入力のバリデーションを追加
  • Todo作成処理のテストを追加
  • Vitest / Testing Library のテスト設定を追加

CodeRabbit指摘対応

  • 入力中に既存エラーをクリアするように変更
  • idcreatedAt のテストを toBeDefined() から型を確認する検証へ変更
  • vitest.config.ts__dirname 利用をやめ、ESM環境でも安全な import.meta.url ベースの書き方へ変更

CodeRabbit設定

  • .coderabbit.yaml を追加
  • レビュー言語を日本語に設定
  • 初学者向けに「一般人向けの説明」と「エンジニア向けの説明」を分けるよう指示
  • main 以外をbaseにしたPRもレビュー対象にするため base_branches: [".*"] を設定
  • React / TypeScript / テスト / Vite・Vitest設定ごとのレビュー方針を追加

使い方のイメージ

<TodoCreate onTodoCreate={(todo) => {
  // ここで作成されたTodoを受け取る
  console.log(todo);
}} />

TodoCreate 自体はTodo一覧を管理せず、「作成されたTodoを親へ渡す」ところまでを担当します。
一覧への追加や保存処理は、親コンポーネント側で行う想定です。

主な処理の流れ

  1. ユーザーがタイトルを入力する
  2. useState で入力値を保持する
  3. 作成ボタン押下時に入力内容をチェックする
  4. タイトルが空の場合はエラーメッセージを表示する
  5. 入力し直した場合はエラーメッセージをクリアする
  6. 有効なタイトルの場合はTodoオブジェクトを作成する
  7. onTodoCreate(newTodo) で親コンポーネントへ渡す
  8. 入力欄とエラー状態をリセットする

Todoオブジェクトの形

interface Todo {
  id: string;
  title: string;
  completed: boolean;
  createdAt: Date;
}

テストしたこと

  • タイトルを入力して送信するとTodoが作成されること
  • 空のタイトルではTodoが作成されず、エラーが表示されること
  • 空白のみのタイトルでもエラーが表示されること
  • 作成後に入力欄がクリアされること
  • 作成されたTodoの id が文字列であること
  • 作成されたTodoの createdAtDate であること

確認コマンド

pnpm test -- --run
pnpm build

どちらも成功しています。

補足

このPRでは、学習目的としてTodo作成機能を最小構成で実装しています。
現時点では TodoCreate コンポーネントの追加が中心で、App.tsx への本格的な組み込みやTodo一覧表示は次のステップで対応する想定です。

Summary by CodeRabbit

リリースノート

  • 新機能

    • Todo作成フォームが追加されました。ユーザーはタイトルを入力してTodoを新規作成できるようになりました。バリデーション機能により、空のタイトルは拒否されます。
  • テスト

    • Todo作成機能に対するテストスイートが追加されました。

- Create TypeScript type definitions for Todo
- Implement TodoCreate component using MUI
- Add tests for TodoCreate component
- Configure Vitest for testing
- Add test script to package.json
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: a3f729b2-8f60-4615-a4f4-3e74cad8eb65

📥 Commits

Reviewing files that changed from the base of the PR and between 1d57876 and 95e0c05.

📒 Files selected for processing (4)
  • .coderabbit.yaml
  • src/components/TodoCreate.tsx
  • src/components/__tests__/TodoCreate.test.tsx
  • vitest.config.ts
✅ Files skipped from review due to trivial changes (1)
  • vitest.config.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/components/tests/TodoCreate.test.tsx
  • src/components/TodoCreate.tsx
📜 Recent review details
🔇 Additional comments (3)
.coderabbit.yaml (3)

1-5: グローバル設定は問題なく整っています。

  • 一般人向けの説明: 言語やトーンの設定が正しく入り、レビューの出力方針が安定します。
  • エンジニア向けの説明: language, tone_instructions, early_access は型・値ともにスキーマと整合しており、このセグメントでの不整合はありません。

6-26: レビュー運用設定は一貫しており、実運用しやすいです。

  • 一般人向けの説明: 自動レビューの対象や停止条件が明確で、レビューの抜け漏れを防ぎつつ運用ルールも保てます。
  • エンジニア向けの説明: reviewsauto_review 配下のキー構成・型が妥当で、profile: "chill"drafts: truebase_branches などの組み合わせも設定意図として自然です。

27-48: パス別ガイダンスとチャット設定の方向性が良いです。

  • 一般人向けの説明: ファイル種類ごとにレビューの見方が分かれていて、学習しやすいフィードバックを受けやすくなっています。
  • エンジニア向けの説明: path_instructions は React/TS・テスト・Vite/Vitest で観点を分離できており、chat.auto_reply: true で対話性も確保できています。

Walkthrough

テスト基盤を整備し、TodoアイテムをUIで作成するためのTypeScript型定義とReactコンポーネントを導入。Vitest・React Testing Library・MUIをセットアップし、フォーム検証とコンポーネント動作をカバーするテストを追加。

Changes

Todoアプリケーション テスト基盤とコンポーネント追加

Layer / File(s) Summary
型定義
src/types/todo.ts
TodoCreateTodoInputインターフェースを定義。Todoid(UUID)、titlecompletedフラグ、createdAtタイムスタンプを持つ。
テスト環境セットアップ
package.json, vitest.config.ts, src/test/setup.ts
Vitest・React Testing Library・jsdomをdevDependenciesに追加。MUIコンポーネントを依存関係に追加。Vistestをglobals環境でjsdomを用い、@エイリアスで./srcを参照する設定。Testing Library Jest DOMマッチャーを有効化。
コンポーネント実装
src/components/TodoCreate.tsx
MUIのBoxAlertTextFieldButtonを用いたTodo作成フォーム。入力検証(空白チェック)、UUID生成、フォーム送信時のコールバック呼び出し、フォーム初期化を実装。
コンポーネントテスト
src/components/__tests__/TodoCreate.test.tsx
有効な入力での正常な作成フロー、空白入力での検証エラー表示、送信後のフォーム初期化を確認するテストスイート。
コードレビュー設定
.coderabbit.yaml
日本語レビュー、React/TypeScript学習向けガイダンス、ESM安全性チェック、自動レビュー設定を定義。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🧪 テスト駆動の芽が育ち
型安全で形作られた世界
Vistestの光が照らす
TodoCreate、ようこそ!
検証と確認の調べ♪

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PRタイトル「Todo作成機能の実装」は、プルリクエストの主な変更内容(TodoCreate コンポーネントの新規実装)を明確かつ正確に要約しており、チェンジセット全体を適切に代表しています。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/todo-create

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Review rate limit: 9/10 reviews remaining, refill in 6 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/components/TodoCreate.tsx (1)

73-73: ⚡ Quick win

入力中にエラー状態をクリアするとUXが改善します。

一度バリデーションエラーになると、Line 73 の入力変更中もエラー表示が残り続けるため、onChangeerror をクリアするのが自然です。

💡 提案差分
-          onChange={(e) => setTitle(e.target.value)}
+          onChange={(e) => {
+            setTitle(e.target.value);
+            if (error) setError('');
+          }}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/TodoCreate.tsx` at line 73, When the title input changes in
the TodoCreate component the onChange handler only calls setTitle, so any
validation error state persists; update the onChange handler (the one that
currently calls setTitle(e.target.value)) to also clear the error state (call
the error setter such as setError('') or setError(null)) so typing removes the
error message immediately.
src/components/__tests__/TodoCreate.test.tsx (1)

35-39: ⚡ Quick win

生成Todoの型保証をもう一段強めると回帰耐性が上がります。

toBeDefined() だけだと createdAt が文字列化されても通るため、型に寄せた検証にすると安全です。

✅ 提案差分
-    expect(createdTodo.id).toBeDefined();
-    expect(createdTodo.createdAt).toBeDefined();
+    expect(createdTodo.id).toEqual(expect.any(String));
+    expect(createdTodo.createdAt).toBeInstanceOf(Date);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/components/__tests__/TodoCreate.test.tsx` around lines 35 - 39, The test
currently only uses toBeDefined() for createdTodo.id and createdTodo.createdAt
which lets incorrect types slip through; update the assertions for createdTodo
(from mockOnTodoCreate) to assert types/shape: ensure createdTodo.id is a string
(or UUID format if applicable) and assert createdTodo.createdAt is a Date
instance or a valid ISO timestamp (e.g., Date.parse(createdTodo.createdAt) is
not NaN) so the createdAt field matches the Todo type rather than just being
defined.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@vitest.config.ts`:
- Line 3: The config currently uses path.resolve(__dirname, ...) which breaks in
ESM contexts; change the module to use the ESM-safe pattern: import {
fileURLToPath } from 'url' and compute a __dirname equivalent with
fileURLToPath(new URL('.', import.meta.url)) (or call fileURLToPath(new
URL('<relative>', import.meta.url)) inline) and then replace all occurrences of
path.resolve(__dirname, ...) in the file (e.g., where path.resolve is used in
vitest.config.ts) with path.resolve(or direct path joins) based on that
fileURLToPath result so the config works under "type": "module".

---

Nitpick comments:
In `@src/components/__tests__/TodoCreate.test.tsx`:
- Around line 35-39: The test currently only uses toBeDefined() for
createdTodo.id and createdTodo.createdAt which lets incorrect types slip
through; update the assertions for createdTodo (from mockOnTodoCreate) to assert
types/shape: ensure createdTodo.id is a string (or UUID format if applicable)
and assert createdTodo.createdAt is a Date instance or a valid ISO timestamp
(e.g., Date.parse(createdTodo.createdAt) is not NaN) so the createdAt field
matches the Todo type rather than just being defined.

In `@src/components/TodoCreate.tsx`:
- Line 73: When the title input changes in the TodoCreate component the onChange
handler only calls setTitle, so any validation error state persists; update the
onChange handler (the one that currently calls setTitle(e.target.value)) to also
clear the error state (call the error setter such as setError('') or
setError(null)) so typing removes the error message immediately.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 856c9e7a-a24f-44ec-ae5c-ce6574634eb1

📥 Commits

Reviewing files that changed from the base of the PR and between 72198da and 1d57876.

📒 Files selected for processing (6)
  • package.json
  • src/components/TodoCreate.tsx
  • src/components/__tests__/TodoCreate.test.tsx
  • src/test/setup.ts
  • src/types/todo.ts
  • vitest.config.ts

Comment thread vitest.config.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant