Files
dify/web/hooks/use-document-title.spec.ts
yyh c7641bb1ce refactor(web): unify app-shell bootstrap on TanStack Query + Next.js route conventions (#35394)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-04-20 02:52:08 +00:00

71 lines
2.4 KiB
TypeScript

import { renderHookWithSystemFeatures } from '@/__tests__/utils/mock-system-features'
/**
* Test suite for useDocumentTitle hook
*
* This hook manages the browser document title with support for:
* - Custom branding (when enabled in system features)
* - Default "Dify" branding
* - Pending state handling (prevents title flicker during loading)
* - Page-specific titles with automatic suffix
*
* Title format: "[Page Title] - [Brand Name]"
* If no page title: "[Brand Name]"
*/
import useDocumentTitle from './use-document-title'
/**
* Test behavior when system features are still loading
* Title should remain empty to prevent flicker
*/
describe('title should be empty if systemFeatures is pending', () => {
it('document title should be empty if set title', () => {
renderHookWithSystemFeatures(() => useDocumentTitle('test'), { systemFeatures: null })
expect(document.title).toBe('')
})
it('document title should be empty if not set title', () => {
renderHookWithSystemFeatures(() => useDocumentTitle(''), { systemFeatures: null })
expect(document.title).toBe('')
})
})
/**
* Test default Dify branding behavior
* When custom branding is disabled, should use "Dify" as the brand name
*/
describe('use default branding', () => {
it('document title should be test-Dify if set title', () => {
renderHookWithSystemFeatures(() => useDocumentTitle('test'), {
systemFeatures: { branding: { enabled: false } },
})
expect(document.title).toBe('test - Dify')
})
it('document title should be Dify if not set title', () => {
renderHookWithSystemFeatures(() => useDocumentTitle(''), {
systemFeatures: { branding: { enabled: false } },
})
expect(document.title).toBe('Dify')
})
})
/**
* Test custom branding behavior
* When custom branding is enabled, should use the configured application_title
*/
describe('use specific branding', () => {
it('document title should be test-Test if set title', () => {
renderHookWithSystemFeatures(() => useDocumentTitle('test'), {
systemFeatures: { branding: { enabled: true, application_title: 'Test' } },
})
expect(document.title).toBe('test - Test')
})
it('document title should be Test if not set title', () => {
renderHookWithSystemFeatures(() => useDocumentTitle(''), {
systemFeatures: { branding: { enabled: true, application_title: 'Test' } },
})
expect(document.title).toBe('Test')
})
})