-
Notifications
You must be signed in to change notification settings - Fork 0
🧹 [code health improvement] Remove any type and eslint-disable comments in LayoutEditor.test.tsx #291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
is0692vs
wants to merge
1
commit into
main
from
jules-fix-layout-editor-test-types-14731531611365481821
Closed
🧹 [code health improvement] Remove any type and eslint-disable comments in LayoutEditor.test.tsx #291
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,18 +2,23 @@ import { render, screen, fireEvent } from "@testing-library/react"; | |||||||||||||||||||||||
| import { describe, it, expect, vi, beforeEach } from "vitest"; | ||||||||||||||||||||||||
| import LayoutEditor from "../LayoutEditor"; | ||||||||||||||||||||||||
| import { CardLayout } from "@/lib/types"; | ||||||||||||||||||||||||
| import "@testing-library/jest-dom"; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| type WindowWithMock = Window & typeof globalThis & { | ||||||||||||||||||||||||
| triggerDragEnd?: (event: { active: { id: string }, over: { id: string } | null }) => void; | ||||||||||||||||||||||||
| mockIsOverId?: string; | ||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Mock dnd-kit components | ||||||||||||||||||||||||
| vi.mock("@dnd-kit/core", async (importOriginal) => { | ||||||||||||||||||||||||
| const actual = await importOriginal<typeof import("@dnd-kit/core")>(); | ||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||
| ...actual, | ||||||||||||||||||||||||
| DndContext: ({ children, onDragEnd }: { children: React.ReactNode; onDragEnd: (event: unknown) => void }) => ( | ||||||||||||||||||||||||
| DndContext: ({ children, onDragEnd }: { children: React.ReactNode; onDragEnd: (event: { active: { id: string }, over: { id: string } | null }) => void }) => ( | ||||||||||||||||||||||||
| <div data-testid="dnd-context" onClick={() => { | ||||||||||||||||||||||||
| // Expose a way to trigger onDragEnd via a synthetic event or global for testing | ||||||||||||||||||||||||
| // We'll attach it to window for easy triggering | ||||||||||||||||||||||||
| (window as unknown as { triggerDragEnd: (event: unknown) => void }).triggerDragEnd = onDragEnd; | ||||||||||||||||||||||||
| (window as WindowWithMock).triggerDragEnd = onDragEnd; | ||||||||||||||||||||||||
| }}> | ||||||||||||||||||||||||
| {children} | ||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||
|
|
@@ -22,8 +27,7 @@ vi.mock("@dnd-kit/core", async (importOriginal) => { | |||||||||||||||||||||||
| useSensor: vi.fn(() => ({})), | ||||||||||||||||||||||||
| useDroppable: ({ id }: { id: string }) => ({ | ||||||||||||||||||||||||
| setNodeRef: vi.fn(), | ||||||||||||||||||||||||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||||||||||||||||||||||||
| isOver: (window as any).mockIsOverId === id, | ||||||||||||||||||||||||
| isOver: (window as WindowWithMock).mockIsOverId === id, | ||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||
| PointerSensor: vi.fn(), | ||||||||||||||||||||||||
| KeyboardSensor: vi.fn(), | ||||||||||||||||||||||||
|
|
@@ -64,10 +68,8 @@ describe("LayoutEditor", () => { | |||||||||||||||||||||||
| beforeEach(() => { | ||||||||||||||||||||||||
| mockOnLayoutChange = vi.fn(); | ||||||||||||||||||||||||
| mockOnToggleVisibility = vi.fn(); | ||||||||||||||||||||||||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||||||||||||||||||||||||
| (window as any).triggerDragEnd = undefined; | ||||||||||||||||||||||||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||||||||||||||||||||||||
| (window as any).mockIsOverId = undefined; | ||||||||||||||||||||||||
| (window as WindowWithMock).triggerDragEnd = undefined; | ||||||||||||||||||||||||
| (window as WindowWithMock).mockIsOverId = undefined; | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| it("renders blocks in their respective columns", () => { | ||||||||||||||||||||||||
|
|
@@ -119,12 +121,11 @@ describe("LayoutEditor", () => { | |||||||||||||||||||||||
| const dndContext = screen.getByTestId("dnd-context"); | ||||||||||||||||||||||||
| fireEvent.click(dndContext); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||||||||||||||||||||||||
| const triggerDragEnd = (window as any).triggerDragEnd; | ||||||||||||||||||||||||
| const triggerDragEnd = (window as WindowWithMock).triggerDragEnd; | ||||||||||||||||||||||||
| expect(triggerDragEnd).toBeDefined(); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Drag 'avatar' to 'right' column | ||||||||||||||||||||||||
| triggerDragEnd({ | ||||||||||||||||||||||||
| triggerDragEnd?.({ | ||||||||||||||||||||||||
|
Comment on lines
+124
to
+128
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: src/components/__tests__/LayoutEditor.test.tsx
Line: 124-128
Comment:
`expect(triggerDragEnd).toBeDefined()` でその場で定義済みであることを確認済みにもかかわらず、直後で `?.` のオプショナルチェーンを使っています。定義済みが保証された変数に対して不要な `?.` を使うと、将来的に `expect` ガードが削除された場合でも `?.` が残り、呼び出しがサイレントにスキップされるリスクがあります。
```suggestion
const triggerDragEnd = (window as WindowWithMock).triggerDragEnd;
expect(triggerDragEnd).toBeDefined();
// Drag 'avatar' to 'right' column
triggerDragEnd!({
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||||||||||||
| active: { id: "avatar" }, | ||||||||||||||||||||||||
| over: { id: "right" }, | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
@@ -149,11 +150,10 @@ describe("LayoutEditor", () => { | |||||||||||||||||||||||
| const dndContext = screen.getByTestId("dnd-context"); | ||||||||||||||||||||||||
| fireEvent.click(dndContext); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||||||||||||||||||||||||
| const triggerDragEnd = (window as any).triggerDragEnd; | ||||||||||||||||||||||||
| const triggerDragEnd = (window as WindowWithMock).triggerDragEnd; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Drag 'avatar' over 'topLanguages' | ||||||||||||||||||||||||
| triggerDragEnd({ | ||||||||||||||||||||||||
| triggerDragEnd?.({ | ||||||||||||||||||||||||
| active: { id: "avatar" }, | ||||||||||||||||||||||||
| over: { id: "topLanguages" }, | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
@@ -178,9 +178,8 @@ describe("LayoutEditor", () => { | |||||||||||||||||||||||
| const dndContext = screen.getByTestId("dnd-context"); | ||||||||||||||||||||||||
| fireEvent.click(dndContext); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||||||||||||||||||||||||
| const triggerDragEnd = (window as any).triggerDragEnd; | ||||||||||||||||||||||||
| triggerDragEnd({ | ||||||||||||||||||||||||
| const triggerDragEnd = (window as WindowWithMock).triggerDragEnd; | ||||||||||||||||||||||||
| triggerDragEnd?.({ | ||||||||||||||||||||||||
| active: { id: "avatar" }, | ||||||||||||||||||||||||
| over: null, | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
@@ -200,9 +199,8 @@ describe("LayoutEditor", () => { | |||||||||||||||||||||||
| const dndContext = screen.getByTestId("dnd-context"); | ||||||||||||||||||||||||
| fireEvent.click(dndContext); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||||||||||||||||||||||||
| const triggerDragEnd = (window as any).triggerDragEnd; | ||||||||||||||||||||||||
| triggerDragEnd({ | ||||||||||||||||||||||||
| const triggerDragEnd = (window as WindowWithMock).triggerDragEnd; | ||||||||||||||||||||||||
| triggerDragEnd?.({ | ||||||||||||||||||||||||
| active: { id: "avatar" }, | ||||||||||||||||||||||||
| over: { id: "avatar" }, | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
@@ -222,9 +220,8 @@ describe("LayoutEditor", () => { | |||||||||||||||||||||||
| const dndContext = screen.getByTestId("dnd-context"); | ||||||||||||||||||||||||
| fireEvent.click(dndContext); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||||||||||||||||||||||||
| const triggerDragEnd = (window as any).triggerDragEnd; | ||||||||||||||||||||||||
| triggerDragEnd({ | ||||||||||||||||||||||||
| const triggerDragEnd = (window as WindowWithMock).triggerDragEnd; | ||||||||||||||||||||||||
| triggerDragEnd?.({ | ||||||||||||||||||||||||
| active: { id: "avatar" }, | ||||||||||||||||||||||||
| over: { id: "non-existent-block" }, | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
@@ -250,11 +247,10 @@ describe("LayoutEditor", () => { | |||||||||||||||||||||||
| const dndContext = screen.getByTestId("dnd-context"); | ||||||||||||||||||||||||
| fireEvent.click(dndContext); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||||||||||||||||||||||||
| const triggerDragEnd = (window as any).triggerDragEnd; | ||||||||||||||||||||||||
| const triggerDragEnd = (window as WindowWithMock).triggerDragEnd; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Drag 'avatar' over 'stats' (downwards) | ||||||||||||||||||||||||
| triggerDragEnd({ | ||||||||||||||||||||||||
| triggerDragEnd?.({ | ||||||||||||||||||||||||
| active: { id: "avatar" }, | ||||||||||||||||||||||||
| over: { id: "stats" }, | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
@@ -278,11 +274,10 @@ describe("LayoutEditor", () => { | |||||||||||||||||||||||
| const dndContext = screen.getByTestId("dnd-context"); | ||||||||||||||||||||||||
| fireEvent.click(dndContext); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||||||||||||||||||||||||
| const triggerDragEnd = (window as any).triggerDragEnd; | ||||||||||||||||||||||||
| const triggerDragEnd = (window as WindowWithMock).triggerDragEnd; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Drag 'avatar' to empty column 'right' | ||||||||||||||||||||||||
| triggerDragEnd({ | ||||||||||||||||||||||||
| triggerDragEnd?.({ | ||||||||||||||||||||||||
| active: { id: "avatar" }, | ||||||||||||||||||||||||
| over: { id: "right" }, | ||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The import of @testing-library/jest-dom was removed, but the tests still use custom matchers like toBeInTheDocument() (e.g., line 85). According to the repository's general rules, this import is the standard way to extend expect with these matchers in this project.
References