dify/web/app/components/integrations/__tests__/routes.spec.ts
Jingyi 9b74df21d0
feat(web): refine onboarding UI (#37433)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: yyh <yuanyouhuilyz@gmail.com>
Co-authored-by: Joel <iamjoel007@gmail.com>
Co-authored-by: hjlarry <hjlarry@163.com>
Co-authored-by: fatelei <fatelei@gmail.com>
Co-authored-by: Asuka Minato <i@asukaminato.eu.org>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Xiyuan Chen <52963600+GareArc@users.noreply.github.com>
Co-authored-by: gigglewang <gigglewang@dify.ai>
Co-authored-by: Yunlu Wen <yunlu.wen@dify.ai>
Co-authored-by: chariri <w@chariri.moe>
Co-authored-by: Evan <2869018789@qq.com>
Co-authored-by: yyh <92089059+lyzno1@users.noreply.github.com>
2026-06-15 08:47:15 +00:00

119 lines
5.4 KiB
TypeScript

import {
buildIntegrationPath,
buildMarketplacePathByIntegrationSection,
buildMarketplaceUrlPathByIntegrationSection,
getIntegrationRedirectPathByLegacyToolsSearchParams,
getIntegrationRouteTargetBySlug,
integrationPathBySection,
marketplaceCategoryByIntegrationSection,
marketplaceUrlPathByIntegrationSection,
} from '../routes'
describe('integration routes', () => {
it('maps integration sections to canonical paths', () => {
expect(integrationPathBySection).toEqual({
'provider': '/integrations/model-provider',
'builtin': '/integrations/tools/built-in',
'custom-tool': '/integrations/tools/api',
'workflow-tool': '/integrations/tools/workflow',
'mcp': '/integrations/tools/mcp',
'data-source': '/integrations/data-source',
'custom-endpoint': '/integrations/custom-endpoint',
'trigger': '/integrations/trigger',
'agent-strategy': '/integrations/agent-strategy',
'extension': '/integrations/extension',
})
expect(buildIntegrationPath('custom-tool')).toBe('/integrations/tools/api')
})
it('maps integration sections to marketplace category paths', () => {
expect(marketplaceCategoryByIntegrationSection).toEqual({
'provider': 'model',
'builtin': 'tool',
'mcp': 'tool',
'custom-tool': 'tool',
'workflow-tool': 'tool',
'data-source': 'datasource',
'custom-endpoint': 'extension',
'trigger': 'trigger',
'agent-strategy': 'agent-strategy',
'extension': 'extension',
})
expect(buildMarketplacePathByIntegrationSection('provider')).toBe('/marketplace?category=model')
expect(buildMarketplacePathByIntegrationSection('custom-tool')).toBe('/marketplace?category=tool')
expect(buildMarketplacePathByIntegrationSection('extension')).toBe('/marketplace?category=extension')
})
it('maps integration sections to marketplace platform paths', () => {
expect(marketplaceUrlPathByIntegrationSection).toEqual({
'provider': '/plugins/model',
'builtin': '/plugins/tool',
'mcp': '/plugins/tool',
'custom-tool': '/plugins/tool',
'workflow-tool': '/plugins/tool',
'data-source': '/plugins/datasource',
'custom-endpoint': '/plugins/extension',
'trigger': '/plugins/trigger',
'agent-strategy': '/plugins/agent-strategy',
'extension': '/plugins/extension',
})
expect(buildMarketplaceUrlPathByIntegrationSection('provider')).toBe('/plugins/model')
expect(buildMarketplaceUrlPathByIntegrationSection('custom-tool')).toBe('/plugins/tool')
expect(buildMarketplaceUrlPathByIntegrationSection('extension')).toBe('/plugins/extension')
})
it.each([
[undefined, { type: 'redirect', destination: '/integrations/model-provider' }],
[[], { type: 'redirect', destination: '/integrations/model-provider' }],
[['model-provider'], { type: 'section', section: 'provider' }],
[['tools'], { type: 'redirect', destination: '/integrations/tools/built-in' }],
[['tools', 'built-in'], { type: 'section', section: 'builtin' }],
[['tool', 'api'], { type: 'redirect', destination: '/integrations/tools/api' }],
[['tools', 'api'], { type: 'section', section: 'custom-tool' }],
[['tools', 'workflow'], { type: 'section', section: 'workflow-tool' }],
[['tools', 'mcp'], { type: 'section', section: 'mcp' }],
[['data-source'], { type: 'section', section: 'data-source' }],
[['custom-endpoint'], { type: 'section', section: 'custom-endpoint' }],
[['trigger'], { type: 'section', section: 'trigger' }],
[['agent-strategy'], { type: 'section', section: 'agent-strategy' }],
[['extension'], { type: 'section', section: 'extension' }],
[['model-providers'], { type: 'not-found' }],
[['data-sources'], { type: 'not-found' }],
[['api-extensions'], { type: 'not-found' }],
[['tools', 'api-extension'], { type: 'not-found' }],
[['tools', 'swagger-api'], { type: 'not-found' }],
[['tools', 'trigger'], { type: 'not-found' }],
[['tools', 'agent-strategy'], { type: 'not-found' }],
[['tools', 'extension'], { type: 'not-found' }],
[['discover'], { type: 'not-found' }],
[['missing'], { type: 'not-found' }],
])('resolves slug %j', (slug, expected) => {
expect(getIntegrationRouteTargetBySlug(slug)).toEqual(expected)
})
it('preserves query params when redirecting legacy custom tool route', () => {
expect(getIntegrationRouteTargetBySlug(['tool', 'api'], {
q: 'slack',
tags: ['a', 'b'],
})).toEqual({
type: 'redirect',
destination: '/integrations/tools/api?q=slack&tags=a&tags=b',
})
})
it.each([
[{}, '/integrations/tools/built-in'],
[{ section: 'provider' }, '/integrations/model-provider'],
[{ section: 'builtin' }, '/integrations/tools/built-in'],
[{ category: 'builtin' }, '/integrations/tools/built-in'],
[{ category: 'api' }, '/integrations/tools/api'],
[{ category: 'workflow' }, '/integrations/tools/workflow'],
[{ category: 'mcp' }, '/integrations/tools/mcp'],
[{ section: 'data-source' }, '/integrations/data-source'],
[{ section: 'custom-endpoint' }, '/integrations/custom-endpoint'],
[{ section: 'custom-tool', category: 'api', q: 'slack', tags: ['a', 'b'] }, '/integrations/tools/api?q=slack&tags=a&tags=b'],
])('builds legacy /tools redirect for search params %j', (searchParams, expected) => {
expect(getIntegrationRedirectPathByLegacyToolsSearchParams(searchParams)).toBe(expected)
})
})