app.client.spec.tsx 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. // @vitest-environment jsdom
  2. import { afterEach, describe, expect, it } from 'vitest'
  3. import { cleanup, render } from '@testing-library/react'
  4. import { Context } from '@deepseek-ai/cordis'
  5. import { SlotTestRuntime } from '@deepseek-ai/dsh-client-test-runtime'
  6. import { buildRenderApp } from '../src/client/app.tsx'
  7. let runtime: SlotTestRuntime | undefined
  8. afterEach(async () => {
  9. cleanup()
  10. await runtime?.dispose()
  11. runtime = undefined
  12. })
  13. async function bench() {
  14. runtime = await SlotTestRuntime.create()
  15. await runtime.root.declare({}, () => <div data-testid="frame" />)
  16. return { runtime, renderApp: buildRenderApp({ ctx: runtime.ctx }) }
  17. }
  18. describe('buildRenderApp', () => {
  19. it('fails loud when the slot registry is unavailable', () => {
  20. const renderApp = buildRenderApp({ ctx: new Context() })
  21. expect(() => renderApp()).toThrow()
  22. })
  23. it('renders the root slot tree', async () => {
  24. const b = await bench()
  25. const view = render(<>{b.renderApp()}</>)
  26. expect(view.getByTestId('frame')).toBeTruthy()
  27. })
  28. })