import { describe, it, expect, vi, beforeEach } from 'vitest' import { useIframe } from '../use-iframe' import { useGames } from '#lib/composables/game/use-games' // Mock dependencies vi.mock('nuxt/app', () => ({ useRoute: () => ({ params: { slug: 'test-game', }, }), })) vi.mock('#lib/composables/game/use-games', () => ({ useGames: vi.fn().mockReturnValue({ getGameUrlIframe: vi.fn(), getGameUrl: vi.fn(), getIframeGameMapGameApi: vi.fn(), }), })) describe('useIframe', () => { let composable: ReturnType let game: ReturnType beforeEach(() => { composable = useIframe() game = useGames() }) it('should initialize reactive variables correctly', () => { expect(composable.gameURL.value).toBe('') expect(composable.classIframeBackground.value).toBe('test-game') expect(composable.progressNumber.value).toBe(10) expect(composable.isShowProgress.value).toBe(true) expect(composable.stepProgress.value).toBeUndefined() }) it('should set classIframeBackground based on gameName', () => { expect(composable.classIframeBackground.value).toBe('test-game') }) it('should return false if running inside an iframe', () => { expect(composable.checkIsIframe.value).toBe(false) }) it('should call getIframeUrl correctly', () => { composable.getIframeUrl() expect(game.getGameUrl).toHaveBeenCalled() expect(game.getIframeGameMapGameApi).toHaveBeenCalled() }) it('should return gameURL correctly', () => { expect(composable.gameURL.value).toEqual('') }) }) describe('useIframe - setProgressNumber', () => { let composable: ReturnType beforeEach(() => { composable = useIframe() }) it('should update progressNumber correctly', async () => { const MAX_STEP = 20 await composable.setProgressNumber() expect(composable.progressNumber.value).toBe(MAX_STEP) }) it('should turn of show progress correctly', async () => { const MAX_STEP = 100 composable.progressNumber.value = MAX_STEP await composable.setProgressNumber() expect(composable.isShowProgress.value).toBe(false) }) })