{"version":3,"file":"tests.mjs","names":[],"sources":["../tests/utils.ts"],"sourcesContent":["import { Component } from 'vue';\nimport { vi } from 'vitest';\nimport { mount as _mount, VueWrapper } from '@vue/test-utils';\nimport { type Pinia, setActivePinia, createPinia } from 'pinia';\nimport { createTestingPinia } from '@pinia/testing';\n\nimport { useAuthStore } from '../src/stores/AuthStore';\nimport { PlayerStatus, usePlayerStore } from '../src/stores/PlayerStore';\nimport { Podcast } from '../src/stores/class/general/podcast';\nimport { localisation } from './localisation';\n\nexport { localisation };\n\n/**\n * Utility function to mount a component for testing.\n * This should be used in place of vue-test-utils' `mount` function.\n * This sets sensible defaults for this project, reducing code that has to be\n * written in tests.\n * This will also ensure that dynamic imports are resolved so as to avoid\n * test issues due to subcomponents being loaded.\n * @param component The component to mount\n * @param options Options for configuring the mounting\n * @returns A wrapper for the component\n */\nexport async function mount(component: Component, options?: {\n        /** Use shallow mounting (do not mount subcomponents) */\n        shallow?: boolean,\n        /** Props to set on the component */\n        props?: Record<string, unknown>,\n        /** Stub subcomponents */\n        stubs?: Record<string, Component|boolean>|string[],\n        /** Slot content to render into the mounted component */\n        slots?: Record<string, unknown>,\n        /** Components to register globally on the test app instance (e.g. to test components resolved at runtime via app.component()) */\n        globalComponents?: Record<string, Component>,\n        /** Values to provide on the test app instance (e.g. to test values resolved at runtime via app.provide()/inject()) */\n        provide?: Record<string | symbol, unknown>,\n        /** Hook called before mounting with access to Pinia instance for store initialization */\n        beforeMount?: (pinia: Pinia) => void | Promise<void>\n    }): Promise<VueWrapper> {\n\n    // Component stubbing\n    const stubs: Record<string, Component|boolean> = {\n        'router-link': {\n            template: '<a><slot /></a>'\n        },\n        'RouterLink': {\n            template: '<a><slot /></a>'\n        }\n    };\n    if (options?.stubs !== undefined) {\n        if (Array.isArray(options?.stubs)) {\n            options.stubs.forEach(stub => {\n                stubs[stub] = true\n            });\n        } else {\n            Object.entries(options.stubs).forEach(([key, value]) => {\n                stubs[key] = value;\n            });\n        }\n    }\n\n    // Create real Pinia instance for testing\n    const pinia = createTestingPinia({\n        createSpy: vi.fn\n    });\n\n    // Call beforeMount hook if provided (allows test to configure stores)\n    if (options?.beforeMount) {\n        await options.beforeMount(pinia);\n    }\n\n    // Mount component with configured Pinia\n    const wrapper = _mount(component, {\n        global: {\n            mocks: {\n                $t: localisation,\n                usePlayerStore: vi.fn()\n            },\n            directives: {\n                lazy: vi.fn\n            },\n            plugins: [pinia],\n            stubs,\n            components: options?.globalComponents,\n            provide: options?.provide\n        },\n        props: options?.props,\n        slots: options?.slots,\n        shallow: options?.shallow\n    });\n\n    // Wait for dynamic imports\n    await vi.dynamicImportSettled();\n\n    // Return wrapper\n    return wrapper;\n}\n\nconst fetchData = vi.fn();\nfetchData.mockReturnValue(Promise.resolve());\n\n/**\n * Helper for AuthStore configuration\n * @returns beforeMount hook function\n */\nexport function setupAuthStore(config?: {\n    roles?: string | string[],\n    organisationId?: string,\n    organisationName?: string,\n    organisationAttributes?: Record<string, string | number | boolean>,\n    scope?: Array<number>\n}) {\n    return async () => {\n        const roles = Array.isArray(config?.roles)\n            ? config.roles\n            : (config?.roles ? [config.roles] : []);\n\n        const orgId = config?.organisationId || \"test-org-id\";\n        const orgName = config?.organisationName || \"Test Organisation\";\n\n        const authStore = useAuthStore(); // Uses active pinia (no parameter)\n        authStore.$patch({\n            authRole: roles,\n            authOrgaId: orgId,\n            authOrgaName: orgName,\n            authOrganisation: {\n                id: orgId,\n                name: orgName,\n                imageUrl: \"\",\n                attributes: config?.organisationAttributes || {}\n            },\n            authProfile: {\n                ...(authStore.authProfile ?? {}),\n                scope: config?.scope ?? []\n            }\n        });\n    };\n}\n\n/**\n * Helper for PlayerStore configuration\n * @returns beforeMount hook function\n */\nexport function setupPlayerStore(config?: {\n    playerPodcast?: Podcast,\n    playerStatus?: PlayerStatus\n}) {\n    return async () => {\n        const playerStore = usePlayerStore(); // Uses active pinia\n        playerStore.$patch({\n            playerPodcast: config?.playerPodcast,\n            playerStatus: config?.playerStatus || PlayerStatus.STOPPED\n        });\n    };\n}\n\n/**\n * Combines multiple store setups into one beforeMount hook\n */\nexport function combineStoreSetups(...setups: Array<() => void>) {\n    return () => {\n        setups.forEach(setup => setup());\n    };\n}\n\nexport { VueWrapper };\n\n/**\n * Creates a Pinia instance without mounting a component.\n * Use this for testing composables or APIs directly.\n */\nexport function setupPinia(setupFn?: () => void | Promise<void>): Pinia {\n    const pinia = createPinia();\n    setActivePinia(pinia);\n    if (setupFn) { setupFn(); }\n    return pinia;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwBA,eAAsB,MAAM,WAAsB,SAetB;CAGxB,MAAM,QAA2C;EAC7C,eAAe,EACX,UAAU,kBACd;EACA,cAAc,EACV,UAAU,kBACd;CACJ;CACA,IAAI,SAAS,UAAU,KAAA,GACnB,IAAI,MAAM,QAAQ,SAAS,KAAK,GAC5B,QAAQ,MAAM,SAAQ,SAAQ;EAC1B,MAAM,QAAQ;CAClB,CAAC;MAED,OAAO,QAAQ,QAAQ,KAAK,EAAE,SAAS,CAAC,KAAK,WAAW;EACpD,MAAM,OAAO;CACjB,CAAC;CAKT,MAAM,QAAQ,mBAAmB,EAC7B,WAAW,GAAG,GAClB,CAAC;CAGD,IAAI,SAAS,aACT,MAAM,QAAQ,YAAY,KAAK;CAInC,MAAM,UAAU,QAAO,WAAW;EAC9B,QAAQ;GACJ,OAAO;IACH,IAAI;IACJ,gBAAgB,GAAG,GAAG;GAC1B;GACA,YAAY,EACR,MAAM,GAAG,GACb;GACA,SAAS,CAAC,KAAK;GACf;GACA,YAAY,SAAS;GACrB,SAAS,SAAS;EACtB;EACA,OAAO,SAAS;EAChB,OAAO,SAAS;EAChB,SAAS,SAAS;CACtB,CAAC;CAGD,MAAM,GAAG,qBAAqB;CAG9B,OAAO;AACX;AAEkB,GAAG,GACrB,EAAU,gBAAgB,QAAQ,QAAQ,CAAC;;;;;AAM3C,SAAgB,eAAe,QAM5B;CACC,OAAO,YAAY;EACf,MAAM,QAAQ,MAAM,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