Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

use-document-title.spec.ts 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { defaultSystemFeatures } from '@/types/feature'
  2. import { act, renderHook } from '@testing-library/react'
  3. import useDocumentTitle from './use-document-title'
  4. import { useGlobalPublicStore } from '@/context/global-public-context'
  5. jest.mock('@/service/common', () => ({
  6. getSystemFeatures: jest.fn(() => ({ ...defaultSystemFeatures })),
  7. }))
  8. describe('title should be empty if systemFeatures is pending', () => {
  9. act(() => {
  10. useGlobalPublicStore.setState({
  11. systemFeatures: { ...defaultSystemFeatures, branding: { ...defaultSystemFeatures.branding, enabled: false } },
  12. isGlobalPending: true,
  13. })
  14. })
  15. it('document title should be empty if set title', () => {
  16. renderHook(() => useDocumentTitle('test'))
  17. expect(document.title).toBe('')
  18. })
  19. it('document title should be empty if not set title', () => {
  20. renderHook(() => useDocumentTitle(''))
  21. expect(document.title).toBe('')
  22. })
  23. })
  24. describe('use default branding', () => {
  25. beforeEach(() => {
  26. act(() => {
  27. useGlobalPublicStore.setState({
  28. isGlobalPending: false,
  29. systemFeatures: { ...defaultSystemFeatures, branding: { ...defaultSystemFeatures.branding, enabled: false } },
  30. })
  31. })
  32. })
  33. it('document title should be test-Dify if set title', () => {
  34. renderHook(() => useDocumentTitle('test'))
  35. expect(document.title).toBe('test - Dify')
  36. })
  37. it('document title should be Dify if not set title', () => {
  38. renderHook(() => useDocumentTitle(''))
  39. expect(document.title).toBe('Dify')
  40. })
  41. })
  42. describe('use specific branding', () => {
  43. beforeEach(() => {
  44. act(() => {
  45. useGlobalPublicStore.setState({
  46. isGlobalPending: false,
  47. systemFeatures: { ...defaultSystemFeatures, branding: { ...defaultSystemFeatures.branding, enabled: true, application_title: 'Test' } },
  48. })
  49. })
  50. })
  51. it('document title should be test-Test if set title', () => {
  52. renderHook(() => useDocumentTitle('test'))
  53. expect(document.title).toBe('test - Test')
  54. })
  55. it('document title should be Test if not set title', () => {
  56. renderHook(() => useDocumentTitle(''))
  57. expect(document.title).toBe('Test')
  58. })
  59. })