Files
dify/web/utils/__tests__/mcp.spec.ts
CodingOnStar d66b0d2d11 refactor(tests): reorganize test files and enhance test coverage for utility functions
- Moved test files for completion parameters, clipboard, app redirection, and emoji utilities to the appropriate directory structure.
- Added comprehensive tests for clipboard functionality, including modern and legacy methods.
- Implemented tests for app redirection logic based on user permissions and app modes.
- Enhanced tests for completion parameters validation and error handling.
- Introduced tests for emoji search functionality with various scenarios.
- Updated icon utility tests to cover edge cases and security concerns.
- Improved formatting tests for numbers, file sizes, and time representation.
2026-03-26 09:42:09 +08:00

89 lines
2.8 KiB
TypeScript

/**
* Test suite for MCP (Model Context Protocol) utility functions
* Tests icon detection logic for MCP-related features
*/
import { shouldUseMcpIcon, shouldUseMcpIconForAppIcon } from '../mcp'
describe('mcp', () => {
/**
* Tests shouldUseMcpIcon function which determines if the MCP icon
* should be used based on the icon source format
*/
describe('shouldUseMcpIcon', () => {
/**
* The link emoji (🔗) is used as a special marker for MCP icons
*/
it('returns true for emoji object with 🔗 content', () => {
const src = { content: '🔗', background: '#fff' }
expect(shouldUseMcpIcon(src)).toBe(true)
})
it('returns false for emoji object with different content', () => {
const src = { content: '🎉', background: '#fff' }
expect(shouldUseMcpIcon(src)).toBe(false)
})
it('returns false for string URL', () => {
const src = 'https://example.com/icon.png'
expect(shouldUseMcpIcon(src)).toBe(false)
})
it('returns false for null', () => {
expect(shouldUseMcpIcon(null)).toBe(false)
})
it('returns false for undefined', () => {
expect(shouldUseMcpIcon(undefined)).toBe(false)
})
it('returns false for empty object', () => {
expect(shouldUseMcpIcon({})).toBe(false)
})
it('returns false for object without content property', () => {
const src = { background: '#fff' }
expect(shouldUseMcpIcon(src)).toBe(false)
})
it('returns false for object with null content', () => {
const src = { content: null, background: '#fff' }
expect(shouldUseMcpIcon(src)).toBe(false)
})
})
/**
* Tests shouldUseMcpIconForAppIcon function which checks if an app icon
* should use the MCP icon based on icon type and content
*/
describe('shouldUseMcpIconForAppIcon', () => {
/**
* MCP icon should only be used when both conditions are met:
* - Icon type is 'emoji'
* - Icon content is the link emoji (🔗)
*/
it('returns true when iconType is emoji and icon is 🔗', () => {
expect(shouldUseMcpIconForAppIcon('emoji', '🔗')).toBe(true)
})
it('returns false when iconType is emoji but icon is different', () => {
expect(shouldUseMcpIconForAppIcon('emoji', '🎉')).toBe(false)
})
it('returns false when iconType is image', () => {
expect(shouldUseMcpIconForAppIcon('image', '🔗')).toBe(false)
})
it('returns false when iconType is image and icon is different', () => {
expect(shouldUseMcpIconForAppIcon('image', 'file-id-123')).toBe(false)
})
it('returns false for empty strings', () => {
expect(shouldUseMcpIconForAppIcon('', '')).toBe(false)
})
it('returns false when iconType is empty but icon is 🔗', () => {
expect(shouldUseMcpIconForAppIcon('', '🔗')).toBe(false)
})
})
})