refactor: remove as any from useMinimapGraph.test.ts

This commit is contained in:
Johnpaul
2026-01-22 20:08:28 +01:00
parent ea961f9128
commit 7e7971f96c

View File

@@ -1,6 +1,7 @@
import { useThrottleFn } from '@vueuse/core'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { ref } from 'vue'
import type { Ref } from 'vue'
import type { LGraph, LGraphNode } from '@/lib/litegraph/src/litegraph'
import { useMinimapGraph } from '@/renderer/extensions/minimap/composables/useMinimapGraph'
@@ -34,13 +35,13 @@ describe('useMinimapGraph', () => {
onNodeAdded: vi.fn(),
onNodeRemoved: vi.fn(),
onConnectionChange: vi.fn()
} as any
} as unknown as LGraph
onGraphChangedMock = vi.fn()
})
it('should initialize with empty state', () => {
const graphRef = ref(mockGraph as any)
const graphRef = ref(mockGraph) as unknown as Ref<LGraph | null>
const graphManager = useMinimapGraph(graphRef, onGraphChangedMock)
expect(graphManager.updateFlags.value).toEqual({
@@ -52,7 +53,7 @@ describe('useMinimapGraph', () => {
})
it('should setup event listeners on init', () => {
const graphRef = ref(mockGraph as any)
const graphRef = ref(mockGraph) as unknown as Ref<LGraph | null>
const graphManager = useMinimapGraph(graphRef, onGraphChangedMock)
graphManager.init()
@@ -72,7 +73,7 @@ describe('useMinimapGraph', () => {
mockGraph.onNodeRemoved = originalOnNodeRemoved
mockGraph.onConnectionChange = originalOnConnectionChange
const graphRef = ref(mockGraph as any)
const graphRef = ref(mockGraph) as unknown as Ref<LGraph | null>
const graphManager = useMinimapGraph(graphRef, onGraphChangedMock)
graphManager.setupEventListeners()
@@ -91,7 +92,7 @@ describe('useMinimapGraph', () => {
})
it('should prevent duplicate event listener setup', () => {
const graphRef = ref(mockGraph as any)
const graphRef = ref(mockGraph) as unknown as Ref<LGraph | null>
const graphManager = useMinimapGraph(graphRef, onGraphChangedMock)
// Store original callbacks for comparison
@@ -127,7 +128,7 @@ describe('useMinimapGraph', () => {
mockGraph.onNodeRemoved = originalOnNodeRemoved
mockGraph.onConnectionChange = originalOnConnectionChange
const graphRef = ref(mockGraph as any)
const graphRef = ref(mockGraph) as unknown as Ref<LGraph | null>
const graphManager = useMinimapGraph(graphRef, onGraphChangedMock)
graphManager.setupEventListeners()
@@ -144,7 +145,7 @@ describe('useMinimapGraph', () => {
.spyOn(console, 'error')
.mockImplementation(() => {})
const graphRef = ref(mockGraph as any)
const graphRef = ref(mockGraph) as unknown as Ref<LGraph | null>
const graphManager = useMinimapGraph(graphRef, onGraphChangedMock)
graphManager.cleanupEventListeners()
@@ -157,7 +158,7 @@ describe('useMinimapGraph', () => {
})
it('should detect node position changes', () => {
const graphRef = ref(mockGraph as any)
const graphRef = ref(mockGraph) as unknown as Ref<LGraph | null>
const graphManager = useMinimapGraph(graphRef, onGraphChangedMock)
// First check - cache initial state
@@ -177,14 +178,18 @@ describe('useMinimapGraph', () => {
})
it('should detect node count changes', () => {
const graphRef = ref(mockGraph as any)
const graphRef = ref(mockGraph) as unknown as Ref<LGraph | null>
const graphManager = useMinimapGraph(graphRef, onGraphChangedMock)
// Cache initial state
graphManager.checkForChanges()
// Add a node
mockGraph._nodes.push({ id: '3', pos: [400, 300], size: [100, 50] } as any)
mockGraph._nodes.push({
id: '3',
pos: [400, 300],
size: [100, 50]
} as unknown as LGraphNode)
const hasChanges = graphManager.checkForChanges()
expect(hasChanges).toBe(true)
@@ -193,7 +198,7 @@ describe('useMinimapGraph', () => {
})
it('should detect connection changes', () => {
const graphRef = ref(mockGraph as any)
const graphRef = ref(mockGraph) as unknown as Ref<LGraph | null>
const graphManager = useMinimapGraph(graphRef, onGraphChangedMock)
// Cache initial state
@@ -203,7 +208,7 @@ describe('useMinimapGraph', () => {
mockGraph.links = new Map([
[1, { id: 1 }],
[2, { id: 2 }]
]) as any
]) as unknown as LGraph['links']
const hasChanges = graphManager.checkForChanges()
expect(hasChanges).toBe(true)
@@ -214,7 +219,7 @@ describe('useMinimapGraph', () => {
const originalOnNodeRemoved = vi.fn()
mockGraph.onNodeRemoved = originalOnNodeRemoved
const graphRef = ref(mockGraph as any)
const graphRef = ref(mockGraph) as unknown as Ref<LGraph | null>
const graphManager = useMinimapGraph(graphRef, onGraphChangedMock)
graphManager.setupEventListeners()
@@ -227,7 +232,7 @@ describe('useMinimapGraph', () => {
})
it('should destroy properly', () => {
const graphRef = ref(mockGraph as any)
const graphRef = ref(mockGraph) as unknown as Ref<LGraph | null>
const graphManager = useMinimapGraph(graphRef, onGraphChangedMock)
graphManager.init()
@@ -241,7 +246,7 @@ describe('useMinimapGraph', () => {
})
it('should clear cache', () => {
const graphRef = ref(mockGraph as any)
const graphRef = ref(mockGraph) as unknown as Ref<LGraph | null>
const graphManager = useMinimapGraph(graphRef, onGraphChangedMock)
// Populate cache
@@ -256,7 +261,7 @@ describe('useMinimapGraph', () => {
})
it('should handle null graph gracefully', () => {
const graphRef = ref(null as any)
const graphRef = ref(null) as unknown as Ref<LGraph | null>
const graphManager = useMinimapGraph(graphRef, onGraphChangedMock)
expect(() => graphManager.setupEventListeners()).not.toThrow()
@@ -265,7 +270,7 @@ describe('useMinimapGraph', () => {
})
it('should clean up removed nodes from cache', () => {
const graphRef = ref(mockGraph as any)
const graphRef = ref(mockGraph) as unknown as Ref<LGraph | null>
const graphManager = useMinimapGraph(graphRef, onGraphChangedMock)
// Cache initial state
@@ -283,7 +288,7 @@ describe('useMinimapGraph', () => {
const throttledFn = vi.fn()
vi.mocked(useThrottleFn).mockReturnValue(throttledFn)
const graphRef = ref(mockGraph as any)
const graphRef = ref(mockGraph) as unknown as Ref<LGraph | null>
const graphManager = useMinimapGraph(graphRef, onGraphChangedMock)
graphManager.setupEventListeners()