diff --git a/web/hooks/use-document-title.spec.ts b/web/hooks/use-document-title.spec.ts index 0316c3a3e7..6359458d56 100644 --- a/web/hooks/use-document-title.spec.ts +++ b/web/hooks/use-document-title.spec.ts @@ -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') + }) +})