test: update useDocumentTitle test

This commit is contained in:
NFish 2025-05-13 15:26:36 +08:00
parent 94c64b661e
commit 62de9ae5d9
1 changed files with 31 additions and 4 deletions

View File

@ -1,12 +1,20 @@
import { defaultSystemFeatures } from '@/types/feature'
import { renderHook } from '@testing-library/react'
import { act, renderHook } from '@testing-library/react'
import useDocumentTitle from './use-document-title'
import { useGlobalPublicStore } from '@/context/global-public-context'
jest.mock('@/context/global-public-context', () => ({
useGlobalPublicStore: jest.fn(() => ({ ...defaultSystemFeatures })),
jest.mock('@/service/common', () => ({
getSystemFeatures: jest.fn(() => ({ ...defaultSystemFeatures })),
}))
describe('branding.enabled is false', () => {
describe('use default branding', () => {
beforeEach(() => {
act(() => {
useGlobalPublicStore.setState({
systemFeatures: { ...defaultSystemFeatures, branding: { ...defaultSystemFeatures.branding, enabled: false } },
})
})
})
it('document title should be test-Dify if set title', () => {
renderHook(() => useDocumentTitle('test'))
expect(document.title).toBe('test - Dify')
@ -17,3 +25,22 @@ describe('branding.enabled is false', () => {
expect(document.title).toBe('Dify')
})
})
describe('use specific branding', () => {
beforeEach(() => {
act(() => {
useGlobalPublicStore.setState({
systemFeatures: { ...defaultSystemFeatures, branding: { ...defaultSystemFeatures.branding, enabled: true, application_title: 'Test' } },
})
})
})
it('document title should be test-Test if set title', () => {
renderHook(() => useDocumentTitle('test'))
expect(document.title).toBe('test - Test')
})
it('document title should be Test if not set title', () => {
renderHook(() => useDocumentTitle(''))
expect(document.title).toBe('Test')
})
})