-
Notifications
You must be signed in to change notification settings - Fork 0
🧹 fix: remove any type usage in LayoutEditor.test.tsx #282
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,17 @@ import LayoutEditor from "../LayoutEditor"; | |||||||||||||||
| import { CardLayout } from "@/lib/types"; | ||||||||||||||||
| import "@testing-library/jest-dom"; | ||||||||||||||||
|
|
||||||||||||||||
| type MockDragEvent = { | ||||||||||||||||
| active: { id: string }; | ||||||||||||||||
| over: { id: string } | null; | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| interface MockWindow { | ||||||||||||||||
| triggerDragEnd?: (event: MockDragEvent) => void; | ||||||||||||||||
| mockIsOverId?: string; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| // Mock dnd-kit components | ||||||||||||||||
| vi.mock("@dnd-kit/core", async (importOriginal) => { | ||||||||||||||||
| const actual = await importOriginal<typeof import("@dnd-kit/core")>(); | ||||||||||||||||
|
|
@@ -13,7 +24,7 @@ vi.mock("@dnd-kit/core", async (importOriginal) => { | |||||||||||||||
| <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 unknown as MockWindow).triggerDragEnd = onDragEnd as (event: MockDragEvent) => void; | ||||||||||||||||
| }}> | ||||||||||||||||
| {children} | ||||||||||||||||
| </div> | ||||||||||||||||
|
|
@@ -22,8 +33,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 unknown as MockWindow).mockIsOverId === id, | ||||||||||||||||
|
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.
ランタイムで評価されるようにゲッターを使用してください。 🔧 ゲッターを使った修正案 useDroppable: ({ id }: { id: string }) => ({
setNodeRef: vi.fn(),
- isOver: (window as unknown as MockWindow).mockIsOverId === id,
+ get isOver() {
+ return (window as unknown as MockWindow).mockIsOverId === id;
+ },
}),📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| }), | ||||||||||||||||
| PointerSensor: vi.fn(), | ||||||||||||||||
| KeyboardSensor: vi.fn(), | ||||||||||||||||
|
|
@@ -64,10 +74,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 unknown as MockWindow).triggerDragEnd = undefined; | ||||||||||||||||
| (window as unknown as MockWindow).mockIsOverId = undefined; | ||||||||||||||||
| }); | ||||||||||||||||
|
|
||||||||||||||||
| it("renders blocks in their respective columns", () => { | ||||||||||||||||
|
|
@@ -119,8 +127,7 @@ 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 unknown as MockWindow).triggerDragEnd!; | ||||||||||||||||
| expect(triggerDragEnd).toBeDefined(); | ||||||||||||||||
|
|
||||||||||||||||
| // Drag 'avatar' to 'right' column | ||||||||||||||||
|
|
@@ -149,8 +156,7 @@ 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 unknown as MockWindow).triggerDragEnd!; | ||||||||||||||||
|
|
||||||||||||||||
| // Drag 'avatar' over 'topLanguages' | ||||||||||||||||
| triggerDragEnd({ | ||||||||||||||||
|
|
@@ -178,8 +184,7 @@ 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 unknown as MockWindow).triggerDragEnd!; | ||||||||||||||||
| triggerDragEnd({ | ||||||||||||||||
| active: { id: "avatar" }, | ||||||||||||||||
| over: null, | ||||||||||||||||
|
|
@@ -200,8 +205,7 @@ 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 unknown as MockWindow).triggerDragEnd!; | ||||||||||||||||
| triggerDragEnd({ | ||||||||||||||||
| active: { id: "avatar" }, | ||||||||||||||||
| over: { id: "avatar" }, | ||||||||||||||||
|
|
@@ -222,8 +226,7 @@ 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 unknown as MockWindow).triggerDragEnd!; | ||||||||||||||||
| triggerDragEnd({ | ||||||||||||||||
| active: { id: "avatar" }, | ||||||||||||||||
| over: { id: "non-existent-block" }, | ||||||||||||||||
|
|
@@ -250,8 +253,7 @@ 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 unknown as MockWindow).triggerDragEnd!; | ||||||||||||||||
|
|
||||||||||||||||
| // Drag 'avatar' over 'stats' (downwards) | ||||||||||||||||
| triggerDragEnd({ | ||||||||||||||||
|
|
@@ -278,8 +280,7 @@ 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 unknown as MockWindow).triggerDragEnd!; | ||||||||||||||||
|
|
||||||||||||||||
| // Drag 'avatar' to empty column 'right' | ||||||||||||||||
| triggerDragEnd({ | ||||||||||||||||
|
|
||||||||||||||||
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.
MockWindowインターフェース定義の後に空行が2行連続しています。1行に統一するとスタイルが揃います。Prompt To Fix With AI
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!