Skip to content

Commit bff56dc

Browse files
Copilotesmcelroy
andauthored
fix: resolve all ESLint errors across test files
- e2e/settings.spec.ts: remove unused createLandscapePng/uploadTestImage imports - App.test.tsx: replace `as any` with `as unknown as <T>` for matchMedia and FileReader mocks - PhotoGrid.test.tsx: remove unused beforeEach import; replace `as any` with `as unknown as <T>` for anchor/ClipboardItem/fetch mocks - heicUtils.test.ts: replace `as any` with `as unknown as HTMLCanvasElement` in createElement mocks - useDarkMode.test.ts: replace `as any` with `as unknown as typeof window.matchMedia` - imageUtils.test.ts: remove unused WatermarkPosition import; drop unused _quality param; fix no-this-alias by using arrow function in property setter; remove unused result variables Agent-Logs-Url: https://github.com/esmcelroy/squarify/sessions/10d4fd08-d586-4419-a6d9-aeb5da278869 Co-authored-by: esmcelroy <3530006+esmcelroy@users.noreply.github.com>
1 parent 7355fd2 commit bff56dc

6 files changed

Lines changed: 22 additions & 24 deletions

File tree

e2e/settings.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { test, expect } from '@playwright/test'
2-
import { createLandscapePng, uploadTestImage } from './test-helpers'
32

43
test.beforeEach(async ({ page }) => {
54
await page.goto('/')

src/__tests__/App.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('App', () => {
3939
addListener: vi.fn(),
4040
removeListener: vi.fn(),
4141
dispatchEvent: vi.fn(),
42-
})) as any;
42+
})) as unknown as MediaQueryList;
4343
});
4444

4545
afterEach(() => {
@@ -114,7 +114,7 @@ describe('App', () => {
114114
setTimeout(() => this.onload?.(), 0);
115115
}
116116
}
117-
global.FileReader = MockFileReader as any;
117+
global.FileReader = MockFileReader as unknown as typeof FileReader;
118118

119119
return {
120120
restore: () => { global.FileReader = origFileReader; },

src/__tests__/PhotoGrid.test.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
1+
import { describe, it, expect, vi, afterEach } from 'vitest';
22
import { render, screen, fireEvent, act } from '@testing-library/react';
33
import { PhotoGrid } from '../components/PhotoGrid';
44
import type { UploadedPhoto } from '../types';
@@ -70,7 +70,7 @@ describe('PhotoGrid', () => {
7070
const clickSpy = vi.fn()
7171
const createElementSpy = vi.spyOn(document, 'createElement').mockImplementation((tag: string) => {
7272
if (tag === 'a') {
73-
return { href: '', download: '', click: clickSpy } as any
73+
return { href: '', download: '', click: clickSpy } as unknown as HTMLAnchorElement
7474
}
7575
return originalCreateElement(tag)
7676
})
@@ -116,13 +116,13 @@ describe('PhotoGrid', () => {
116116
})
117117
globalThis.ClipboardItem = class {
118118
constructor(public items: Record<string, Blob>) {}
119-
} as any
119+
} as unknown as typeof ClipboardItem
120120

121121
const pngBlob = new Blob(['px'], { type: 'image/png' })
122122
const mockFetch = vi.fn().mockResolvedValue({
123123
blob: () => Promise.resolve(pngBlob),
124124
})
125-
window.fetch = mockFetch as any
125+
window.fetch = mockFetch as unknown as typeof fetch
126126

127127
const photos = [
128128
makePhoto({ id: 'p1', paddedDataUrl: 'data:image/png;base64,padded' }),
@@ -160,7 +160,7 @@ describe('PhotoGrid', () => {
160160
set(v: string) { downloadFilename = v },
161161
get() { return downloadFilename },
162162
})
163-
return anchor as any
163+
return anchor as unknown as HTMLAnchorElement
164164
}
165165
return originalCreateElement(tag)
166166
})
@@ -187,7 +187,7 @@ describe('PhotoGrid', () => {
187187
set(v: string) { downloadFilename = v },
188188
get() { return downloadFilename },
189189
})
190-
return anchor as any
190+
return anchor as unknown as HTMLAnchorElement
191191
}
192192
return originalCreateElement(tag)
193193
})

src/__tests__/heicUtils.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ describe('convertHeicToJpeg', () => {
117117
}])
118118
const mockCanvas = makeMockCanvas()
119119
createElementSpy = vi.spyOn(document, 'createElement').mockImplementation((tag: string) => {
120-
if (tag === 'canvas') return mockCanvas as any
120+
if (tag === 'canvas') return mockCanvas as unknown as HTMLCanvasElement
121121
return originalCreateElement(tag)
122122
})
123123
})
@@ -150,7 +150,7 @@ describe('convertHeicToJpeg', () => {
150150
createElementSpy.mockRestore()
151151
const mockCanvas = makeMockCanvas(null)
152152
createElementSpy = vi.spyOn(document, 'createElement').mockImplementation((tag: string) => {
153-
if (tag === 'canvas') return mockCanvas as any
153+
if (tag === 'canvas') return mockCanvas as unknown as HTMLCanvasElement
154154
return originalCreateElement(tag)
155155
})
156156

@@ -173,7 +173,7 @@ describe('processFilesForHeic', () => {
173173
}])
174174
const mockCanvas = makeMockCanvas()
175175
createElementSpy = vi.spyOn(document, 'createElement').mockImplementation((tag: string) => {
176-
if (tag === 'canvas') return mockCanvas as any
176+
if (tag === 'canvas') return mockCanvas as unknown as HTMLCanvasElement
177177
return originalCreateElement(tag)
178178
})
179179
})

src/__tests__/imageUtils.test.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
22
import { findMaxAspectRatio, getImageDimensions, padImageToAspectRatio, drawPatternFill, drawWatermark, getWatermarkPosition } from '../lib/imageUtils'
3-
import type { UploadedPhoto, PaddingSettings, PatternSettings, WatermarkSettings, WatermarkPosition } from '../types'
3+
import type { UploadedPhoto, PaddingSettings, PatternSettings, WatermarkSettings } from '../types'
44

55
function makePhoto(width: number, height: number, overrides?: Partial<UploadedPhoto>): UploadedPhoto {
66
return {
@@ -92,7 +92,7 @@ function installCanvasMocks() {
9292

9393
HTMLCanvasElement.prototype.getContext = vi.fn(() => mockCtx) as unknown as typeof HTMLCanvasElement.prototype.getContext
9494
HTMLCanvasElement.prototype.toDataURL = vi.fn(
95-
(type?: string, _quality?: unknown) => `data:${type ?? 'image/png'};base64,MOCK`
95+
(type?: string) => `data:${type ?? 'image/png'};base64,MOCK`
9696
)
9797
}
9898

@@ -108,13 +108,12 @@ function installImageMock(naturalWidth = 800, naturalHeight = 600) {
108108
onerror: ((err: unknown) => void) | null = null
109109

110110
constructor() {
111-
const self = this
112111
// Auto-fire onload on next microtask after src is set
113112
Object.defineProperty(this, 'src', {
114-
get: () => self._src,
115-
set(value: string) {
116-
self._src = value
117-
queueMicrotask(() => self.onload?.())
113+
get: () => this._src,
114+
set: (value: string) => {
115+
this._src = value
116+
queueMicrotask(() => this.onload?.())
118117
},
119118
})
120119
}
@@ -288,15 +287,15 @@ describe('padImageToAspectRatio', () => {
288287
it('outputs webp format with quality', async () => {
289288
const photo = makePhoto(600, 600, { dataUrl: 'data:img' })
290289
const settings = defaultSettings({ outputFormat: 'webp', outputQuality: 0.9 })
291-
const result = await padImageToAspectRatio(photo, 2, settings)
290+
await padImageToAspectRatio(photo, 2, settings)
292291

293292
expect(HTMLCanvasElement.prototype.toDataURL).toHaveBeenCalledWith('image/webp', 0.9)
294293
})
295294

296295
it('outputs png format without quality parameter', async () => {
297296
const photo = makePhoto(600, 600, { dataUrl: 'data:img' })
298297
const settings = defaultSettings({ outputFormat: 'png' })
299-
const result = await padImageToAspectRatio(photo, 2, settings)
298+
await padImageToAspectRatio(photo, 2, settings)
300299

301300
expect(HTMLCanvasElement.prototype.toDataURL).toHaveBeenCalledWith('image/png', undefined)
302301
})

src/__tests__/useDarkMode.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ describe('useDarkMode', () => {
3434
mockListeners.push(...listeners);
3535
// Keep reference so listeners added later are captured
3636
const origAddEventListener = mql.addEventListener as ReturnType<typeof vi.fn>;
37-
(mql as any).addEventListener = vi.fn((_event: string, handler: (e: { matches: boolean }) => void) => {
37+
(mql as unknown as Record<string, unknown>).addEventListener = vi.fn((_event: string, handler: (e: { matches: boolean }) => void) => {
3838
mockListeners.push(handler);
3939
origAddEventListener(_event, handler);
4040
});
4141
return mql;
42-
}) as any;
42+
}) as unknown as typeof window.matchMedia;
4343
});
4444

4545
afterEach(() => {
@@ -104,7 +104,7 @@ describe('useDarkMode', () => {
104104
window.matchMedia = vi.fn(() => {
105105
const { mql } = createMatchMedia(true);
106106
return mql;
107-
}) as any;
107+
}) as unknown as typeof window.matchMedia;
108108
const { result } = renderHook(() => useDarkMode());
109109
expect(result.current[0]).toBe('system');
110110
expect(result.current[2]).toBe(true);

0 commit comments

Comments
 (0)