mirror of
https://github.com/langgenius/dify.git
synced 2026-04-28 03:36:36 +08:00
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Stephen Zhou <38493346+hyoban@users.noreply.github.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com>
74 lines
2.6 KiB
TypeScript
74 lines
2.6 KiB
TypeScript
import { validateDirectiveProps } from './markdown-with-directive-schema'
|
|
|
|
describe('markdown-with-directive-schema', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
// Validate the happy path for known directives.
|
|
describe('valid props', () => {
|
|
it('should return true for withiconcardlist when className is provided', () => {
|
|
expect(validateDirectiveProps('withiconcardlist', { className: 'custom-list' })).toBe(true)
|
|
})
|
|
|
|
it('should return true for withiconcarditem when icon is https URL', () => {
|
|
expect(validateDirectiveProps('withiconcarditem', { icon: 'https://example.com/icon.png' })).toBe(true)
|
|
})
|
|
})
|
|
|
|
// Validate strict schema constraints and error branches.
|
|
describe('invalid props', () => {
|
|
it('should return false and log error for unknown directive name', () => {
|
|
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
|
|
const isValid = validateDirectiveProps('unknown-directive', { className: 'custom-list' })
|
|
|
|
expect(isValid).toBe(false)
|
|
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
|
'[markdown-with-directive] Unknown directive name.',
|
|
expect.objectContaining({
|
|
attributes: { className: 'custom-list' },
|
|
directive: 'unknown-directive',
|
|
}),
|
|
)
|
|
})
|
|
|
|
it('should return false and log error for non-http icon URL', () => {
|
|
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
|
|
const isValid = validateDirectiveProps('withiconcarditem', { icon: 'ftp://example.com/icon.png' })
|
|
|
|
expect(isValid).toBe(false)
|
|
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
|
'[markdown-with-directive] Invalid directive props.',
|
|
expect.objectContaining({
|
|
attributes: { icon: 'ftp://example.com/icon.png' },
|
|
directive: 'withiconcarditem',
|
|
issues: expect.arrayContaining([
|
|
expect.objectContaining({
|
|
path: 'icon',
|
|
}),
|
|
]),
|
|
}),
|
|
)
|
|
})
|
|
|
|
it('should return false when extra field is provided to strict list schema', () => {
|
|
const consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
|
|
const isValid = validateDirectiveProps('withiconcardlist', {
|
|
className: 'custom-list',
|
|
extra: 'not-allowed',
|
|
})
|
|
|
|
expect(isValid).toBe(false)
|
|
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
|
'[markdown-with-directive] Invalid directive props.',
|
|
expect.objectContaining({
|
|
directive: 'withiconcardlist',
|
|
}),
|
|
)
|
|
})
|
|
})
|
|
})
|