Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

1.1 KB
Raw Blame
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { renderToString } from 'react-dom/server'
import { ThemeSelector } from '../theme-selector'

const setTheme = vi.fn()

vi.mock('next-themes', () => ({
  useTheme: () => ({ theme: 'system', setTheme }),
}))

describe('ThemeSelector', () => {
  beforeEach(() => {
    vi.clearAllMocks()
  })

  it('renders its trigger in the server HTML', () => {
    const container = document.createElement('div')
    container.innerHTML = renderToString(<ThemeSelector />)

    expect(container.querySelector('button[aria-label="common.theme.label"]')).not.toBeNull()
  })

  it.each([
    ['common.theme.light', 'light'],
    ['common.theme.dark', 'dark'],
    ['common.theme.system', 'system'],
  ])('selects %s', async (name, theme) => {
    const user = userEvent.setup()
    render(<ThemeSelector />)

    await user.click(screen.getByRole('button', { name: 'common.theme.label' }))
    await user.click(await screen.findByRole('menuitemradio', { name }))

    expect(setTheme).toHaveBeenCalledWith(theme)
  })
})