invariant.spec.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233
  1. // @vitest-environment jsdom
  2. import { describe, expect, it } from 'vitest'
  3. import { Context } from 'cordis'
  4. import { apply as nodeApply } from '@deepseek-ai/dsh-client-ui-theme'
  5. import { apply as clientApply, inject, ThemeService } from '@deepseek-ai/dsh-client-ui-theme/client'
  6. import * as ThemeInvariant from '@deepseek-ai/dsh-client-ui-theme/invariant'
  7. import { apply as localeApply } from '@deepseek-ai/dsh-client-locale/client'
  8. import { SlotsService } from '@deepseek-ai/dsh-client-runtime/client'
  9. import InvariantService from '@deepseek-ai/dsh-invariants'
  10. describe('invariant companion', () => {
  11. it('registers under the package name with an empty installer', async () => {
  12. const ctx = new Context()
  13. await ctx.plugin(InvariantService, { enabled: true })
  14. await expect(ctx.plugin(ThemeInvariant).await()).resolves.toBeDefined()
  15. })
  16. it('node-half apply is a no-op host placeholder', () => {
  17. nodeApply()
  18. expect(true).toBe(true) // reaching here without throw is the contract
  19. })
  20. it('client apply provides ctx.theme over the slots/locale edges', async () => {
  21. // The feature registers its own Appearance settings row with localized
  22. // copy, hence the slots + locale edges.
  23. expect(inject).toEqual(['slots', 'locale'])
  24. const ctx = new Context()
  25. new SlotsService(ctx)
  26. await ctx.plugin({ inject: ['slots'], apply: localeApply }).await()
  27. await ctx.plugin({ inject, apply: clientApply }).await()
  28. expect(ctx.get('theme')).toBeInstanceOf(ThemeService)
  29. })
  30. })