Files
supabase/apps/studio/hooks/custom-content/useCustomContent.test.ts
Joshen Lim bc1c050b1d Chore/custom content hook (#38073)
* Init custom content hook

* Implement useCustomContent hook similarly to useIsFeatureEnabled, and implement extension of organization documents

* Attempt to type things nicely

* add test

---------

Co-authored-by: Jordi Enric <jordi.err@gmail.com>
2025-08-22 16:52:28 +08:00

37 lines
1.2 KiB
TypeScript

import { renderHook, cleanup } from '@testing-library/react'
import { beforeEach, describe, expect, it, vi } from 'vitest'
beforeEach(() => {
vi.clearAllMocks()
vi.resetModules()
cleanup()
})
describe('useCustomContent', () => {
it('should return null if content is not found in the custom-content.json file', async () => {
vi.doMock('./custom-content.json', () => ({
default: {
'organization:legal_documents': null,
},
}))
const { useCustomContent } = await import('./useCustomContent')
const { result } = renderHook(() => useCustomContent(['organization:legal_documents']))
expect(result.current.organizationLegalDocuments).toEqual(null)
})
it('should return the content for the key passed in if it exists in the custom-content.json file', async () => {
vi.doMock('./custom-content.json', () => ({
default: {
'organization:legal_documents': {
someValue: 'foo',
},
},
}))
const { useCustomContent } = await import('./useCustomContent')
const { result } = renderHook(() => useCustomContent(['organization:legal_documents']))
expect(result.current.organizationLegalDocuments).toEqual({ someValue: 'foo' })
})
})