initializeStore.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright (C) 2012-2024 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.api_path = '/api'
  23. app.config.pretty_date_format = 'relative'
  24. return pinia
  25. }
  26. export const cleanupStores = () => {
  27. if (!storeInitialized) return
  28. stores.forEach((store) => {
  29. store.$dispose()
  30. })
  31. pinia.state.value = {}
  32. stores.clear()
  33. }