import { beforeEach, describe, expect, test, vi } from 'vitest'; import { nextTick, ref } from 'vue'; import { flushPromises, mount } from '@vue/test-utils'; const mocks = vi.hoisted(() => ({ currentUser: { value: { currentAvatar: 'avtr_current', $previousAvatarSwapTime: 0 }, __v_isRef: true }, modalConfirm: vi.fn(), configGetString: vi.fn(), configSetString: vi.fn(), processBulk: vi.fn(), applyAvatar: vi.fn((json) => ({ ...json })), selectAvatarWithoutConfirmation: vi.fn(), showAvatarDialog: vi.fn(), getAllAvatarTags: vi.fn(), getAvatarTimeSpent: vi.fn(), virtualMeasure: vi.fn() })); vi.mock('pinia', async (importOriginal) => { const actual = await importOriginal(); return { ...actual, storeToRefs: (store) => store }; }); vi.mock('vue-i18n', () => ({ useI18n: () => ({ t: (key) => key }) })); vi.mock('vue-sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } })); vi.mock('../../../plugins/router', () => ({ router: { push: vi.fn(), replace: vi.fn(), beforeEach: vi.fn(), currentRoute: ref({ path: '/', name: '' }), isReady: vi.fn().mockResolvedValue(true) }, initRouter: vi.fn() })); vi.mock('@tanstack/vue-virtual', () => ({ useVirtualizer: () => ({ value: { getVirtualItems: () => [{ key: 0, index: 0, start: 0 }], getTotalSize: () => 100, measure: (...args) => mocks.virtualMeasure(...args), measureElement: vi.fn() } }) })); vi.mock('../../../stores', () => ({ useAppearanceSettingsStore: () => ({ tablePageSizes: [10, 25, 50], tablePageSize: 25 }), useAvatarStore: () => ({}), useModalStore: () => ({ confirm: (...args) => mocks.modalConfirm(...args), prompt: vi.fn() }), useUserStore: () => ({ currentUser: mocks.currentUser }) })); vi.mock('../../../coordinators/avatarCoordinator', () => ({ applyAvatar: (...args) => mocks.applyAvatar(...args), selectAvatarWithoutConfirmation: (...args) => mocks.selectAvatarWithoutConfirmation(...args), showAvatarDialog: (...args) => mocks.showAvatarDialog(...args) })); vi.mock('../../../coordinators/imageUploadCoordinator', () => ({ handleImageUploadInput: () => ({ file: null, clearInput: vi.fn() }), resizeImageToFitLimits: vi.fn(), uploadImageLegacy: vi.fn() })); vi.mock('../../../shared/utils/imageUpload', () => ({ readFileAsBase64: vi.fn(), withUploadTimeout: async (promise) => promise })); vi.mock('../../../api', () => ({ avatarRequest: { getAvatars: vi.fn(), saveAvatar: vi.fn(), createImposter: vi.fn(), uploadAvatarImage: vi.fn() } })); vi.mock('../../../services/database', () => ({ database: { getAllAvatarTags: (...args) => mocks.getAllAvatarTags(...args), getAvatarTimeSpent: (...args) => mocks.getAvatarTimeSpent(...args), addAvatarTag: vi.fn(), removeAvatarTag: vi.fn(), updateAvatarTagColor: vi.fn() } })); vi.mock('../columns.jsx', () => ({ getColumns: () => [] })); vi.mock('../../../shared/utils/avatar', () => ({ getPlatformInfo: () => ({}) })); vi.mock('../../../shared/constants', () => ({ getTagColor: () => ({ bg: '#000', text: '#fff' }) })); vi.mock('../../../services/request', () => ({ processBulk: (...args) => mocks.processBulk(...args) })); vi.mock('../composables/useAvatarCardGrid.js', () => ({ useAvatarCardGrid: () => ({ cardScale: ref(0.6), cardSpacing: ref(1), cardScalePercent: ref(60), cardSpacingPercent: ref(100), cardScaleValue: ref([0.6]), cardSpacingValue: ref([1]), scaleSlider: { min: 0.3, max: 0.9, step: 0.05 }, spacingSlider: { min: 0.5, max: 1.5, step: 0.05 }, gridContainerRef: ref(null), gridStyle: ref(() => ({ '--avatar-grid-columns': '1' })), chunkIntoRows: (items, prefix = 'row') => Array.isArray(items) ? items.map((item, index) => ({ key: `${prefix}:${index}`, items: [item] })) : [], estimateRowHeight: () => 80, updateContainerWidth: vi.fn() }) })); vi.mock('../../../composables/useDataTableScrollHeight', () => ({ useDataTableScrollHeight: () => ({ tableStyle: {} }) })); vi.mock('../../../lib/table/useVrcxVueTable', () => ({ useVrcxVueTable: () => ({ table: {}, pagination: ref({ pageIndex: 0, pageSize: 25 }) }) })); vi.mock('../../../services/config.js', () => ({ default: { getString: (...args) => mocks.configGetString(...args), setString: (...args) => mocks.configSetString(...args) } })); vi.mock('../../../components/ui/context-menu', () => ({ ContextMenuContent: { template: '