invariant.client.spec.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // @vitest-environment jsdom
  2. import { describe, expect, it } from 'vitest'
  3. import { Context } from '@deepseek-ai/cordis'
  4. import { apply as nodeApply } from '@deepseek-ai/dsh-client-ui-theme'
  5. import { apply as clientApply, inject, ThemeRuntime } 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, inject as localeInject } from '@deepseek-ai/dsh-client-locale/client'
  8. import { SlotRegistry } from '@deepseek-ai/dsh-client-ui-renderer/client'
  9. import InvariantRegistry from '@deepseek-ai/dsh-invariants'
  10. import { stubSettingsScope } from '@deepseek-ai/dsh-client-test-runtime'
  11. describe('invariant companion', () => {
  12. it('registers under the package name with an empty installer', async () => {
  13. const ctx = new Context()
  14. await ctx.plugin(InvariantRegistry, { enabled: true })
  15. await expect(ctx.plugin(ThemeInvariant).await()).resolves.toBeDefined()
  16. })
  17. it('node-half waits for optional Host services', () => {
  18. nodeApply(new Context())
  19. expect(true).toBe(true)
  20. })
  21. it('client apply provides ctx.theme over the slots/locale edges', async () => {
  22. // The feature registers its own Appearance settings row with localized
  23. // copy, hence the slots + locale edges.
  24. expect(inject).toEqual(['slots', 'locale', 'connection', 'remote', 'settingsScope'])
  25. const ctx = new Context()
  26. new SlotRegistry(ctx)
  27. ctx.provide('connection', {
  28. api: { settings: { describe: () => Promise.resolve({
  29. rpcId: 'theme-invariant' as never,
  30. result: { ok: true, value: { writable: true, hasDocument: false, namespaces: [] } },
  31. }) } },
  32. isLoopback: true,
  33. } as never)
  34. // The settings row's transport and the forwarded-event port.
  35. ctx.provide('remote', { $on: () => () => {} } as never)
  36. ctx.provide('settingsScope', { bind: () => stubSettingsScope().scope } as never)
  37. await ctx.plugin({ inject: localeInject, apply: localeApply }).await()
  38. await ctx.plugin({ inject, apply: clientApply }).await()
  39. expect(ctx.get('theme')).toBeInstanceOf(ThemeRuntime)
  40. })
  41. })