mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-13 15:13:07 +00:00
O recorte do card 'Time de você' falhava em navegadores endurecidos (IronFox/Tor desligam WebAssembly e WebGL por padrão) com a copy errada de 'tente outra foto'; o motor MediaPipe exige ambos (o grafo pede kGpuService mesmo com delegate CPU). Agora o adapter sonda WASM/WebGL antes do download e devolve 'unsupported' com mensagem acionável; a entrada de inferência é capada em 1600 e a foto passa pelo loadCardPhoto (foto de 61MP que falhava agora conclui). O enquadramento automático volta ao S15 (bbox cobre a janela): o S18 mirava a caixa do rosto em 103px e deixava o busto inteiro pequeno na janela. Saem o detector de rosto (asset removido), frameCardPhotoOnFace, a referência 103px, o piso 0.2 e a âncora S20 (inerte sob o cover). S16/S17 intactos.
60 lines
1.7 KiB
TypeScript
60 lines
1.7 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import {
|
|
cappedSize,
|
|
removeCardPhotoBackground,
|
|
supportsWebAssembly,
|
|
supportsWebgl,
|
|
} from '@/components/cards/cardCutout'
|
|
|
|
const photo = {} as File
|
|
const report = () => {}
|
|
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals()
|
|
vi.restoreAllMocks()
|
|
})
|
|
|
|
describe('supportsWebAssembly', () => {
|
|
it('is true where wasm compiles', () => {
|
|
expect(supportsWebAssembly()).toBe(true)
|
|
})
|
|
|
|
it('fails closed when the browser hides WebAssembly (IronFox default)', () => {
|
|
vi.stubGlobal('WebAssembly', undefined)
|
|
|
|
expect(supportsWebAssembly()).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('removeCardPhotoBackground — unsupported browser', () => {
|
|
it('reports `unsupported` before downloading anything when WebAssembly is off', async () => {
|
|
vi.stubGlobal('WebAssembly', undefined)
|
|
|
|
await expect(removeCardPhotoBackground(photo, report)).resolves.toEqual({
|
|
ok: false,
|
|
reason: 'unsupported',
|
|
})
|
|
})
|
|
|
|
it('reports `unsupported` when WebGL is blocked (MediaPipe graph needs it even on CPU)', async () => {
|
|
vi.spyOn(HTMLCanvasElement.prototype, 'getContext').mockReturnValue(null)
|
|
|
|
expect(supportsWebgl()).toBe(false)
|
|
await expect(removeCardPhotoBackground(photo, report)).resolves.toEqual({
|
|
ok: false,
|
|
reason: 'unsupported',
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('cappedSize (inference input cap)', () => {
|
|
it('caps the longest edge at 1600 regardless of orientation', () => {
|
|
expect(cappedSize(7000, 8750)).toEqual({ width: 1280, height: 1600 })
|
|
expect(cappedSize(4032, 3024)).toEqual({ width: 1600, height: 1200 })
|
|
})
|
|
|
|
it('keeps photos already inside the cap untouched', () => {
|
|
expect(cappedSize(800, 600)).toEqual({ width: 800, height: 600 })
|
|
})
|
|
})
|