initializeStore.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
  2. import { createTestingPinia } from '@pinia/testing'
  3. import { useApplicationStore } from '#shared/stores/application.ts'
  4. import type { TestingPinia } from '@pinia/testing'
  5. import type { Store } from 'pinia'
  6. let storeInitialized = false
  7. let pinia: TestingPinia
  8. export const getTestPinia = () => pinia
  9. const stores = new Set<Store>()
  10. export const initializeStore = () => {
  11. if (storeInitialized) return pinia
  12. pinia = createTestingPinia({ createSpy: vi.fn, stubActions: false })
  13. // plugins.push({ install: pinia.install })
  14. pinia.use((context) => {
  15. stores.add(context.store)
  16. })
  17. storeInitialized = true
  18. const app = useApplicationStore()
  19. app.config.product_logo = 'logo.svg'
  20. app.config.ui_ticket_overview_ticket_limit = 5
  21. app.config.product_name = 'Zammad'
  22. app.config.ticket_hook = 'Ticket#'
  23. app.config.api_path = '/api'
  24. app.config.pretty_date_format = 'relative'
  25. return pinia
  26. }
  27. export const cleanupStores = () => {
  28. if (!storeInitialized) return
  29. stores.forEach((store) => {
  30. store.$dispose()
  31. })
  32. pinia.state.value = {}
  33. stores.clear()
  34. }