chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
60158935f4
commit
6519682885
15831 files changed
+3063428
No files matched your search
@@ -0,0 +1,594 @@
|
||||
import type { ComponentProps, ReactElement } from 'react'
|
||||
import { act, fireEvent, screen, waitFor, within } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { useState } from 'react'
|
||||
import { PluginCategoryEnum } from '@/app/components/plugins/types'
|
||||
import { consoleQuery } from '@/service/console'
|
||||
import {
|
||||
createProviderSummaryFixture,
|
||||
seedModelProviderQueries,
|
||||
} from '@/test/console/model-provider'
|
||||
import { createConsoleQueryWrapper } from '@/test/console/query-data'
|
||||
import { createDeferred } from '@/test/deferred'
|
||||
import { createPluginDeclarationFixture, createPluginEntity } from '@/test/fixtures/plugin'
|
||||
import { renderWithNuqs } from '@/test/nuqs-testing'
|
||||
import IntegrationsPage from '../index'
|
||||
|
||||
const api = vi.hoisted(() => ({
|
||||
push: vi.fn(),
|
||||
manifest: vi.fn<typeof import('@/service/plugins').fetchManifestFromMarketPlace>(),
|
||||
upload: vi.fn<typeof import('@/service/plugins').uploadFile>(),
|
||||
permission:
|
||||
vi.fn<
|
||||
typeof import('@/service/console').consoleClient.workspaces.current.plugin.permission.fetch.get
|
||||
>(),
|
||||
savePermission:
|
||||
vi.fn<
|
||||
typeof import('@/service/console').consoleClient.workspaces.current.plugin.permission.change.post
|
||||
>(),
|
||||
category:
|
||||
vi.fn<
|
||||
typeof import('@/service/console').consoleClient.workspaces.current.plugin.byCategory.list.get
|
||||
>(),
|
||||
autoUpgrade:
|
||||
vi.fn<
|
||||
typeof import('@/service/console').consoleClient.workspaces.current.plugin.autoUpgrade.fetch.get
|
||||
>(),
|
||||
saveAutoUpgrade:
|
||||
vi.fn<
|
||||
typeof import('@/service/console').consoleClient.workspaces.current.plugin.autoUpgrade.change.post
|
||||
>(),
|
||||
debug:
|
||||
vi.fn<
|
||||
typeof import('@/service/console').consoleClient.workspaces.current.plugin.debuggingKey.get
|
||||
>(),
|
||||
}))
|
||||
vi.mock('@/next/navigation', async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import('@/next/navigation')>()),
|
||||
useRouter: () => ({ push: api.push }),
|
||||
}))
|
||||
vi.mock('@/service/console', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('@/service/console')>()
|
||||
const { withConsoleResponses, withConsoleClientResponses } =
|
||||
await import('@/test/console/service-responses')
|
||||
return {
|
||||
...actual,
|
||||
consoleQuery: withConsoleResponses(actual.consoleQuery, {
|
||||
'workspaces.current.plugin.byCategory.list.get': api.category,
|
||||
'workspaces.current.plugin.list.installations.ids.post': async () => ({ plugins: [] }),
|
||||
'workspaces.current.plugin.list.get': async () => ({ plugins: [], total: 0 }),
|
||||
'workspaces.current.plugin.installedIds.get': async () => ({ plugin_ids: [] }),
|
||||
'auth.plugin.datasource.list.get': async () => ({ result: [] }),
|
||||
'apiBasedExtension.get': async () => [],
|
||||
'workspaces.current.toolProviders.get': async () => [],
|
||||
'workspaces.current.tools.api.get': async () => [],
|
||||
'workspaces.current.tools.workflow.get': async () => [],
|
||||
}),
|
||||
consoleClient: withConsoleClientResponses(actual.consoleClient, {
|
||||
'workspaces.current.plugin.permission.fetch.get': api.permission,
|
||||
'workspaces.current.plugin.permission.change.post': api.savePermission,
|
||||
'workspaces.current.plugin.autoUpgrade.fetch.get': api.autoUpgrade,
|
||||
'workspaces.current.plugin.autoUpgrade.change.post': api.saveAutoUpgrade,
|
||||
'workspaces.current.plugin.debuggingKey.get': api.debug,
|
||||
'workspaces.current.plugin.marketplace.pkg.get': async () => ({
|
||||
manifest: { ...createPluginEntity().declaration, category: PluginCategoryEnum.trigger },
|
||||
}),
|
||||
'workspaces.current.plugin.tasks.get': async () => ({ tasks: [] }),
|
||||
}),
|
||||
}
|
||||
})
|
||||
vi.mock('@/service/plugins', async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import('@/service/plugins')>()),
|
||||
fetchManifestFromMarketPlace: api.manifest,
|
||||
uploadFile: api.upload,
|
||||
}))
|
||||
vi.mock('@/service/marketplace', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('@/service/marketplace')>()
|
||||
return {
|
||||
...actual,
|
||||
marketplaceClient: {
|
||||
...actual.marketplaceClient,
|
||||
collectionPlugins: async () => ({ data: { plugins: [] } }),
|
||||
collections: async () => ({ data: { collections: [] } }),
|
||||
},
|
||||
}
|
||||
})
|
||||
vi.mock('@/service/base', async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import('@/service/base')>()),
|
||||
postMarketplace: async (url: string) => {
|
||||
if (url === '/plugins/search/advanced') return { data: { plugins: [], total: 0 } }
|
||||
throw new Error(`Unexpected marketplace request: ${url}`)
|
||||
},
|
||||
}))
|
||||
|
||||
const permissions = [
|
||||
'plugin.install',
|
||||
'plugin.debug',
|
||||
'plugin.plugin_preferences',
|
||||
'tool.manage',
|
||||
'mcp.manage',
|
||||
'api_extension.manage',
|
||||
]
|
||||
const models = [
|
||||
createProviderSummaryFixture({
|
||||
provider: 'openai',
|
||||
label: { en_US: 'OpenAI' },
|
||||
is_configured: false,
|
||||
custom_configuration: { status: 'no-configure' },
|
||||
}),
|
||||
createProviderSummaryFixture({
|
||||
provider: 'anthropic',
|
||||
label: { en_US: 'Anthropic' },
|
||||
is_configured: false,
|
||||
custom_configuration: { status: 'no-configure' },
|
||||
}),
|
||||
]
|
||||
const defaultUpgrade = {
|
||||
strategy_setting: 'fix_only' as const,
|
||||
upgrade_time_of_day: 0,
|
||||
upgrade_mode: 'all' as const,
|
||||
exclude_plugins: [],
|
||||
include_plugins: [],
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
api.push.mockReset()
|
||||
api.manifest.mockReset().mockResolvedValue({
|
||||
data: {
|
||||
plugin: {
|
||||
plugin_unique_identifier: 'test/trigger:1.0.0@package',
|
||||
name: 'trigger',
|
||||
org: 'test',
|
||||
icon: 'icon.svg',
|
||||
label: { ...createPluginDeclarationFixture().label, en_US: 'Trigger Package' },
|
||||
category: PluginCategoryEnum.trigger,
|
||||
version: '1.0.0',
|
||||
latest_version: '1.0.0',
|
||||
brief: createPluginDeclarationFixture().description,
|
||||
introduction: '',
|
||||
verified: true,
|
||||
install_count: 10,
|
||||
badges: [],
|
||||
verification: { authorized_category: 'community' },
|
||||
from: 'marketplace',
|
||||
},
|
||||
version: { version: '1.0.0' },
|
||||
},
|
||||
})
|
||||
api.upload.mockReset().mockReturnValue(new Promise(() => {}))
|
||||
api.permission
|
||||
.mockReset()
|
||||
.mockResolvedValue({ install_permission: 'everyone', debug_permission: 'everyone' })
|
||||
api.savePermission.mockReset().mockResolvedValue({ success: true })
|
||||
api.category.mockReset().mockResolvedValue({ builtin_tools: [], plugins: [], has_more: false })
|
||||
api.autoUpgrade.mockReset().mockImplementation(async ({ query }) => ({
|
||||
category: query.category,
|
||||
auto_upgrade: defaultUpgrade,
|
||||
}))
|
||||
api.saveAutoUpgrade.mockReset().mockResolvedValue({ success: true })
|
||||
api.debug.mockReset().mockResolvedValue({ key: 'test-debug-key', host: 'localhost', port: 5003 })
|
||||
vi.spyOn(window, 'open').mockImplementation(() => null)
|
||||
document.title = ''
|
||||
})
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
function renderPage({
|
||||
props = {},
|
||||
searchParams = {},
|
||||
workspacePermissionKeys = permissions,
|
||||
rbacEnabled = true,
|
||||
restrictLocalPackages = false,
|
||||
ui,
|
||||
}: {
|
||||
props?: ComponentProps<typeof IntegrationsPage>
|
||||
searchParams?: Record<string, string>
|
||||
workspacePermissionKeys?: string[]
|
||||
rbacEnabled?: boolean
|
||||
restrictLocalPackages?: boolean
|
||||
ui?: ReactElement
|
||||
} = {}) {
|
||||
const { wrapper: QueryProvider, queryClient } = createConsoleQueryWrapper({
|
||||
workspacePermissionKeys,
|
||||
systemFeatures: {
|
||||
rbac_enabled: rbacEnabled,
|
||||
enable_marketplace: true,
|
||||
plugin_installation_permission: { restrict_to_marketplace_only: restrictLocalPackages },
|
||||
},
|
||||
})
|
||||
seedModelProviderQueries(queryClient)
|
||||
queryClient.setQueryData(consoleQuery.workspaces.current.modelProviders.summary.get.queryKey(), {
|
||||
data: models,
|
||||
plugins: {},
|
||||
})
|
||||
const renderOwner = (content: ReactElement) => <QueryProvider>{content}</QueryProvider>
|
||||
const view = renderWithNuqs(renderOwner(ui ?? <IntegrationsPage {...props} />), {
|
||||
searchParams,
|
||||
hasMemory: true,
|
||||
})
|
||||
return {
|
||||
...view,
|
||||
queryClient,
|
||||
rerender: (content: ReactElement) => view.rerender(renderOwner(content)),
|
||||
}
|
||||
}
|
||||
function SettingsIntegrations() {
|
||||
const [section, setSection] =
|
||||
useState<ComponentProps<typeof IntegrationsPage>['section']>('provider')
|
||||
return <IntegrationsPage section={section} onSectionChange={setSection} />
|
||||
}
|
||||
|
||||
it('defaults to models and preserves a real model search across section navigation', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderPage({ ui: <SettingsIntegrations /> })
|
||||
expect(screen.getByRole('heading', { name: 'navigation.settings.provider' })).toBeInTheDocument()
|
||||
expect(screen.getByText('OpenAI')).toBeInTheDocument()
|
||||
expect(screen.getByText('Anthropic')).toBeInTheDocument()
|
||||
await user.type(screen.getByRole('searchbox', { name: 'common.operation.search' }), 'OpenAI')
|
||||
await waitFor(() => expect(screen.queryByText('Anthropic')).not.toBeInTheDocument())
|
||||
const navigation = screen.getByRole('navigation', { name: 'navigation.settings.integrations' })
|
||||
await user.click(
|
||||
within(navigation).getByRole('button', { name: 'navigation.settings.dataSource' }),
|
||||
)
|
||||
expect(
|
||||
screen.getByRole('heading', { name: 'navigation.settings.dataSource' }),
|
||||
).toBeInTheDocument()
|
||||
await user.click(within(navigation).getByRole('button', { name: 'navigation.settings.provider' }))
|
||||
expect(screen.getByRole('searchbox', { name: 'common.operation.search' })).toHaveValue('OpenAI')
|
||||
expect(screen.getByText('OpenAI')).toBeInTheDocument()
|
||||
expect(screen.queryByText('Anthropic')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('closes compact navigation after changing the settings section', async () => {
|
||||
const user = userEvent.setup()
|
||||
vi.spyOn(window, 'matchMedia').mockImplementation((query) => ({
|
||||
matches: query === '(width < 48rem)',
|
||||
media: query,
|
||||
onchange: null,
|
||||
addEventListener: vi.fn(),
|
||||
removeEventListener: vi.fn(),
|
||||
addListener: vi.fn(),
|
||||
removeListener: vi.fn(),
|
||||
dispatchEvent: vi.fn(),
|
||||
}))
|
||||
renderPage({ ui: <SettingsIntegrations /> })
|
||||
await user.click(
|
||||
screen.getByRole('button', {
|
||||
name: 'navigation.mainNav.integrations: navigation.settings.provider',
|
||||
}),
|
||||
)
|
||||
const drawer = await screen.findByRole('dialog', { name: 'navigation.mainNav.integrations' })
|
||||
await user.click(within(drawer).getByRole('button', { name: 'navigation.settings.dataSource' }))
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.queryByRole('dialog', { name: 'navigation.mainNav.integrations' }),
|
||||
).not.toBeInTheDocument(),
|
||||
)
|
||||
expect(
|
||||
screen.getByRole('heading', { name: 'navigation.settings.dataSource' }),
|
||||
).toBeInTheDocument()
|
||||
expect(
|
||||
screen.getByRole('button', {
|
||||
name: 'navigation.mainNav.integrations: navigation.settings.dataSource',
|
||||
}),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('preserves the host title in settings and updates it for route navigation', () => {
|
||||
document.title = 'Workspace settings - Dify'
|
||||
const view = renderPage()
|
||||
expect(document.title).toBe('Workspace settings - Dify')
|
||||
view.rerender(<IntegrationsPage section="provider" syncDocumentTitle />)
|
||||
expect(document.title).toBe(
|
||||
'navigation.settings.provider · navigation.mainNav.integrations - Dify',
|
||||
)
|
||||
view.rerender(<IntegrationsPage section="data-source" syncDocumentTitle />)
|
||||
expect(document.title).toBe(
|
||||
'navigation.settings.dataSource · navigation.mainNav.integrations - Dify',
|
||||
)
|
||||
})
|
||||
|
||||
it('honors a legacy category-only MCP URL and the explicit route section takes precedence', async () => {
|
||||
const user = userEvent.setup()
|
||||
const view = renderPage({ searchParams: { category: 'mcp' } })
|
||||
expect(screen.getByRole('heading', { name: 'MCP' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('link', { name: 'MCP' })).toHaveAttribute('aria-current', 'page')
|
||||
await user.click(await screen.findByRole('button', { name: 'tools.mcp.create.cardTitle' }))
|
||||
expect(await screen.findByRole('dialog', { name: 'tools.mcp.modal.title' })).toBeInTheDocument()
|
||||
await user.click(screen.getByRole('button', { name: 'tools.mcp.modal.cancel' }))
|
||||
view.rerender(<IntegrationsPage section="custom-tool" />)
|
||||
expect(
|
||||
screen.getByRole('heading', { name: 'navigation.settings.swaggerAPIAsTool' }),
|
||||
).toBeInTheDocument()
|
||||
expect(
|
||||
screen.getByRole('link', { name: 'navigation.settings.swaggerAPIAsTool' }),
|
||||
).toHaveAttribute('aria-current', 'page')
|
||||
expect(
|
||||
screen.getByRole('link', { name: 'navigation.settings.swaggerAPIAsTool' }),
|
||||
).toHaveAttribute('href', '/integrations/tools/api')
|
||||
})
|
||||
|
||||
it('expands tools in the same render that enters a tool section and keeps them expanded after leaving', () => {
|
||||
const view = renderPage({ props: { section: 'provider' } })
|
||||
const tools = screen.getByRole('button', { name: 'navigation.menus.tools' })
|
||||
expect(tools).toHaveAttribute('aria-expanded', 'false')
|
||||
|
||||
view.rerender(<IntegrationsPage section="mcp" />)
|
||||
expect(tools).toHaveAttribute('aria-expanded', 'true')
|
||||
|
||||
view.rerender(<IntegrationsPage section="data-source" />)
|
||||
expect(tools).toHaveAttribute('aria-expanded', 'true')
|
||||
})
|
||||
|
||||
it('keeps tools expanded while visiting models and changes to tools only when opening the disclosure', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderPage({ ui: <SettingsIntegrations /> })
|
||||
const tools = screen.getByRole('button', { name: 'navigation.menus.tools' })
|
||||
await user.click(tools)
|
||||
expect(
|
||||
await screen.findByRole('heading', { name: 'navigation.toolsPage.toolPlugin' }),
|
||||
).toBeInTheDocument()
|
||||
expect(tools).toHaveAttribute('aria-expanded', 'true')
|
||||
const navigation = screen.getByRole('navigation', { name: 'navigation.settings.integrations' })
|
||||
await user.click(within(navigation).getByRole('button', { name: 'navigation.settings.provider' }))
|
||||
expect(tools).toHaveAttribute('aria-expanded', 'true')
|
||||
expect(screen.getByRole('heading', { name: 'navigation.settings.provider' })).toBeInTheDocument()
|
||||
await user.click(tools)
|
||||
expect(tools).toHaveAttribute('aria-expanded', 'false')
|
||||
expect(screen.getByRole('heading', { name: 'navigation.settings.provider' })).toBeInTheDocument()
|
||||
expect(within(navigation).queryByRole('button', { name: 'MCP' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('opens the built-in tools route from the parent tools disclosure', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderPage()
|
||||
await user.click(screen.getByRole('button', { name: 'navigation.menus.tools' }))
|
||||
expect(api.push).toHaveBeenCalledExactlyOnceWith('/integrations/tools/built-in')
|
||||
})
|
||||
|
||||
it.each([
|
||||
['builtin', 'tool', 'navigation.toolsPage.toolPlugin'],
|
||||
['trigger', 'trigger', 'plugin.categorySingle.trigger'],
|
||||
['extension', 'extension', 'plugin.categorySingle.extension'],
|
||||
['agent-strategy', 'agent-strategy', 'plugin.categorySingle.agent'],
|
||||
] as const)('loads the %s plugin category from the URL', async (section, category, heading) => {
|
||||
renderPage({ searchParams: { section } })
|
||||
expect(screen.getByRole('heading', { name: heading })).toBeInTheDocument()
|
||||
await waitFor(() =>
|
||||
expect(api.category).toHaveBeenCalledWith(expect.objectContaining({ params: { category } })),
|
||||
)
|
||||
expect(screen.getByRole('link', { name: heading })).toHaveAttribute('aria-current', 'page')
|
||||
})
|
||||
|
||||
it.each([
|
||||
['provider', '/plugins/model'],
|
||||
['data-source', '/plugins/datasource'],
|
||||
] as const)('opens the %s marketplace from its actual section action', async (section, path) => {
|
||||
const user = userEvent.setup()
|
||||
renderPage({ props: { section } })
|
||||
const action = 'plugin.marketplace.difyMarketplace'
|
||||
await user.click(await screen.findByRole('button', { name: action }))
|
||||
expect(window.open).toHaveBeenCalledWith(
|
||||
expect.stringContaining(`${path}?source=`),
|
||||
'_blank',
|
||||
'noopener,noreferrer',
|
||||
)
|
||||
})
|
||||
|
||||
it('opens the category marketplace path from the install menu', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderPage({ props: { section: 'trigger' } })
|
||||
await user.click(await screen.findByRole('button', { name: 'plugin.installAction' }))
|
||||
await user.click(screen.getByRole('menuitem', { name: 'plugin.source.marketplace' }))
|
||||
expect(window.open).toHaveBeenCalledExactlyOnceWith(
|
||||
expect.stringContaining('/plugins/trigger?source='),
|
||||
'_blank',
|
||||
'noopener,noreferrer',
|
||||
)
|
||||
})
|
||||
|
||||
it('saves category-specific automatic update settings from the toolbar', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderPage({ props: { section: 'trigger' } })
|
||||
await user.click(await screen.findByRole('button', { name: /plugin.autoUpdate.autoUpdate/ }))
|
||||
const dialog = screen.getByRole('dialog', { name: 'plugin.autoUpdate.autoUpdateSettings' })
|
||||
await user.click(
|
||||
within(dialog).getByRole('radio', { name: 'plugin.autoUpdate.strategy.disabled.name' }),
|
||||
)
|
||||
await user.click(within(dialog).getByRole('button', { name: 'common.operation.save' }))
|
||||
await waitFor(() =>
|
||||
expect(api.saveAutoUpgrade).toHaveBeenCalledWith({
|
||||
body: expect.objectContaining({
|
||||
category: 'trigger',
|
||||
auto_upgrade: expect.objectContaining({ strategy_setting: 'disabled' }),
|
||||
}),
|
||||
}),
|
||||
)
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.queryByRole('dialog', { name: 'plugin.autoUpdate.autoUpdateSettings' }),
|
||||
).not.toBeInTheDocument(),
|
||||
)
|
||||
})
|
||||
|
||||
it('shows a real remote debug connection from the sidebar', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderPage({ props: { section: 'data-source' } })
|
||||
await user.click(await screen.findByRole('button', { name: 'plugin.debugInfo.title' }))
|
||||
const dialog = screen.getByRole('dialog', { name: 'plugin.debugInfo.title' })
|
||||
expect(within(dialog).getByText('localhost:5003')).toBeInTheDocument()
|
||||
expect(within(dialog).getByRole('link', { name: 'plugin.debugInfo.viewDocs' })).toHaveAttribute(
|
||||
'href',
|
||||
expect.stringContaining('remote-debug-a-plugin'),
|
||||
)
|
||||
})
|
||||
|
||||
it('hides install, debug, and settings actions for a reader without requesting debug credentials', async () => {
|
||||
renderPage({ props: { section: 'trigger' }, workspacePermissionKeys: [] })
|
||||
await screen.findByText('plugin.list.noTriggerFound')
|
||||
expect(screen.queryByRole('button', { name: 'plugin.installAction' })).not.toBeInTheDocument()
|
||||
expect(
|
||||
screen.queryByRole('button', { name: 'plugin.source.marketplace' }),
|
||||
).not.toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: 'plugin.debugInfo.title' })).not.toBeInTheDocument()
|
||||
expect(
|
||||
screen.queryByRole('button', { name: /plugin.autoUpdate.autoUpdate/ }),
|
||||
).not.toBeInTheDocument()
|
||||
expect(
|
||||
screen.queryByRole('button', { name: 'plugin.privilege.permissions' }),
|
||||
).not.toBeInTheDocument()
|
||||
expect(api.debug).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('persists legacy permission changes and immediately hides installations when nobody may install', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderPage({ props: { section: 'trigger' }, rbacEnabled: false })
|
||||
await user.click(await screen.findByRole('button', { name: 'plugin.privilege.permissions' }))
|
||||
const dialog = screen.getByRole('dialog', { name: 'plugin.privilege.permissions' })
|
||||
await user.click(
|
||||
within(dialog).getByRole('radio', {
|
||||
name: 'plugin.privilege.quickWhoCanInstall: plugin.privilege.noone',
|
||||
}),
|
||||
)
|
||||
await waitFor(() =>
|
||||
expect(api.savePermission).toHaveBeenCalledWith({
|
||||
body: { install_permission: 'noone', debug_permission: 'everyone' },
|
||||
}),
|
||||
)
|
||||
await user.click(within(dialog).getByRole('button', { name: 'common.operation.close' }))
|
||||
expect(screen.queryByRole('button', { name: 'plugin.installAction' })).not.toBeInTheDocument()
|
||||
await user.click(screen.getByRole('button', { name: 'plugin.privilege.permissions' }))
|
||||
expect(
|
||||
screen.getByRole('radio', {
|
||||
name: 'plugin.privilege.quickWhoCanInstall: plugin.privilege.noone',
|
||||
}),
|
||||
).toBeChecked()
|
||||
})
|
||||
|
||||
it('restores the selected legacy permission when saving fails', async () => {
|
||||
const user = userEvent.setup()
|
||||
api.savePermission.mockRejectedValueOnce(new Error('Unavailable'))
|
||||
renderPage({ props: { section: 'trigger' }, rbacEnabled: false })
|
||||
await user.click(await screen.findByRole('button', { name: 'plugin.privilege.permissions' }))
|
||||
await user.click(
|
||||
screen.getByRole('radio', {
|
||||
name: 'plugin.privilege.quickWhoCanInstall: plugin.privilege.noone',
|
||||
}),
|
||||
)
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.getByRole('radio', {
|
||||
name: 'plugin.privilege.quickWhoCanInstall: plugin.privilege.everyone',
|
||||
}),
|
||||
).toBeChecked(),
|
||||
)
|
||||
await user.click(screen.getByRole('button', { name: 'common.operation.close' }))
|
||||
expect(screen.getByRole('button', { name: 'plugin.installAction' })).toBeEnabled()
|
||||
})
|
||||
|
||||
it.each([true, false])(
|
||||
'waits for permission before consuming a marketplace URL; installation allowed: %s',
|
||||
async (allowed) => {
|
||||
const user = userEvent.setup()
|
||||
const permission = createDeferred<Awaited<ReturnType<typeof api.permission>>>()
|
||||
api.permission.mockReturnValueOnce(permission.promise)
|
||||
const packageId = 'test/trigger:1.0.0@package'
|
||||
const view = renderPage({
|
||||
props: { section: 'trigger' },
|
||||
rbacEnabled: false,
|
||||
searchParams: { 'package-ids': JSON.stringify([packageId]) },
|
||||
})
|
||||
await screen.findByText('plugin.list.noTriggerFound')
|
||||
expect(api.manifest).not.toHaveBeenCalled()
|
||||
expect(view.onUrlUpdate).not.toHaveBeenCalled()
|
||||
await act(async () =>
|
||||
permission.resolve({
|
||||
install_permission: allowed ? 'everyone' : 'noone',
|
||||
debug_permission: 'everyone',
|
||||
}),
|
||||
)
|
||||
if (allowed) {
|
||||
const dialog = await screen.findByRole('dialog', {
|
||||
name: 'plugin.installModal.installPlugin',
|
||||
})
|
||||
expect(within(dialog).getByText('Trigger Package')).toBeInTheDocument()
|
||||
expect(api.manifest).toHaveBeenCalledWith(encodeURIComponent(packageId))
|
||||
await user.click(within(dialog).getByRole('button', { name: 'common.operation.cancel' }))
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())
|
||||
} else {
|
||||
expect(api.manifest).not.toHaveBeenCalled()
|
||||
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
|
||||
}
|
||||
await waitFor(() =>
|
||||
expect(view.onUrlUpdate.mock.lastCall?.[0].searchParams.has('package-ids')).toBe(false),
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
it('opens the real local installer for a dropped tool package and clears it when cancelled', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderPage({ props: { section: 'builtin' } })
|
||||
await screen.findByRole('button', { name: 'plugin.installAction' })
|
||||
const file = new File(['package'], 'tool.difypkg', { type: 'application/octet-stream' })
|
||||
fireEvent.drop(screen.getByRole('heading', { name: 'navigation.toolsPage.toolPlugin' }), {
|
||||
dataTransfer: { files: [file], types: ['Files'] },
|
||||
})
|
||||
const dialog = await screen.findByRole('dialog', { name: 'plugin.installModal.installPlugin' })
|
||||
await waitFor(() => expect(api.upload).toHaveBeenCalledExactlyOnceWith(file, false))
|
||||
expect(within(dialog).getByText('tool.difypkg')).toBeInTheDocument()
|
||||
await user.click(within(dialog).getByRole('button', { name: 'common.operation.cancel' }))
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())
|
||||
expect(
|
||||
screen.getByRole('heading', { name: 'navigation.toolsPage.toolPlugin' }),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it.each([
|
||||
{
|
||||
reason: 'permission',
|
||||
section: 'builtin' as const,
|
||||
workspacePermissionKeys: [],
|
||||
restrictLocalPackages: false,
|
||||
filename: 'tool.difypkg',
|
||||
},
|
||||
{
|
||||
reason: 'marketplace-only policy',
|
||||
section: 'builtin' as const,
|
||||
workspacePermissionKeys: permissions,
|
||||
restrictLocalPackages: true,
|
||||
filename: 'tool.difypkg',
|
||||
},
|
||||
{
|
||||
reason: 'non-tool category',
|
||||
section: 'trigger' as const,
|
||||
workspacePermissionKeys: permissions,
|
||||
restrictLocalPackages: false,
|
||||
filename: 'tool.difypkg',
|
||||
},
|
||||
{
|
||||
reason: 'unsupported file',
|
||||
section: 'builtin' as const,
|
||||
workspacePermissionKeys: permissions,
|
||||
restrictLocalPackages: false,
|
||||
filename: 'notes.txt',
|
||||
},
|
||||
])(
|
||||
'ignores a package drop excluded by $reason',
|
||||
async ({ section, workspacePermissionKeys, restrictLocalPackages, filename }) => {
|
||||
renderPage({ props: { section }, workspacePermissionKeys, restrictLocalPackages })
|
||||
await waitFor(() => expect(api.category).toHaveBeenCalled())
|
||||
fireEvent.drop(
|
||||
screen.getByRole('heading', {
|
||||
name:
|
||||
section === 'builtin'
|
||||
? 'navigation.toolsPage.toolPlugin'
|
||||
: 'plugin.categorySingle.trigger',
|
||||
}),
|
||||
{ dataTransfer: { files: [new File(['package'], filename)], types: ['Files'] } },
|
||||
)
|
||||
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
|
||||
expect(api.upload).not.toHaveBeenCalled()
|
||||
},
|
||||
)
|
||||
@@ -0,0 +1,27 @@
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import { IntegrationsRoutePage } from '../route-page'
|
||||
|
||||
let mockPathname = '/integrations/model-provider'
|
||||
|
||||
vi.mock('@/next/navigation', () => ({
|
||||
usePathname: () => mockPathname,
|
||||
}))
|
||||
vi.mock('../index', () => ({
|
||||
default: ({ section }: { section: string }) => <p>{`section: ${section}`}</p>,
|
||||
}))
|
||||
|
||||
describe('IntegrationsRoutePage', () => {
|
||||
it('renders the section of the current integrations path', () => {
|
||||
mockPathname = '/integrations/tools/mcp'
|
||||
render(<IntegrationsRoutePage />)
|
||||
|
||||
expect(screen.getByText('section: mcp')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders nothing for a path the route segment redirects', () => {
|
||||
mockPathname = '/integrations/tools'
|
||||
const { container } = render(<IntegrationsRoutePage />)
|
||||
|
||||
expect(container).toBeEmptyDOMElement()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,126 @@
|
||||
import {
|
||||
buildMarketplaceUrlPathByIntegrationSection,
|
||||
getIntegrationRedirectPathByLegacyToolsSearchParams,
|
||||
getIntegrationRouteTargetBySlug,
|
||||
} from '../routes'
|
||||
|
||||
describe('integration routes', () => {
|
||||
it.each([
|
||||
['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'],
|
||||
] as const)('builds the marketplace destination for %s', (section, path) => {
|
||||
expect(buildMarketplaceUrlPathByIntegrationSection(section)).toBe(path)
|
||||
})
|
||||
|
||||
it.each([
|
||||
[undefined, { type: 'redirect', destination: '/integrations/model-provider' }],
|
||||
[[], { type: 'redirect', destination: '/integrations/model-provider' }],
|
||||
[['model-provider'], { type: 'section', section: 'provider' }],
|
||||
[
|
||||
['model-provider', 'plugins'],
|
||||
{ type: 'redirect', destination: '/integrations/model-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' }],
|
||||
[
|
||||
['agent-strategy', 'plugins'],
|
||||
{ type: 'redirect', destination: '/integrations/agent-strategy' },
|
||||
],
|
||||
[['trigger', 'plugins'], { type: 'redirect', destination: '/integrations/trigger' }],
|
||||
[
|
||||
['tools', 'built-in', 'plugins'],
|
||||
{ type: 'redirect', destination: '/integrations/tools/built-in' },
|
||||
],
|
||||
[['data-source', 'plugins'], { type: 'redirect', destination: '/integrations/data-source' }],
|
||||
[['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('preserves marketplace install query params when redirecting nested marketplace callbacks', () => {
|
||||
expect(
|
||||
getIntegrationRouteTargetBySlug(['agent-strategy', 'plugins'], {
|
||||
'package-ids': '["junjiem/mcp_see_agent"]',
|
||||
}),
|
||||
).toEqual({
|
||||
type: 'redirect',
|
||||
destination: '/integrations/agent-strategy?package-ids=%5B%22junjiem%2Fmcp_see_agent%22%5D',
|
||||
})
|
||||
})
|
||||
|
||||
it('preserves marketplace install query params when redirecting model and data source callbacks', () => {
|
||||
expect(
|
||||
getIntegrationRouteTargetBySlug(['model-provider', 'plugins'], {
|
||||
'package-ids': '["langgenius/openai"]',
|
||||
}),
|
||||
).toEqual({
|
||||
type: 'redirect',
|
||||
destination: '/integrations/model-provider?package-ids=%5B%22langgenius%2Fopenai%22%5D',
|
||||
})
|
||||
expect(
|
||||
getIntegrationRouteTargetBySlug(['data-source', 'plugins'], {
|
||||
'package-ids': '["langgenius/notion_datasource"]',
|
||||
}),
|
||||
).toEqual({
|
||||
type: 'redirect',
|
||||
destination:
|
||||
'/integrations/data-source?package-ids=%5B%22langgenius%2Fnotion_datasource%22%5D',
|
||||
})
|
||||
})
|
||||
|
||||
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)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,657 @@
|
||||
import type { ComponentProps } from 'react'
|
||||
import { act, cleanup, screen, waitFor, within } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { consoleQuery } from '@/service/console'
|
||||
import { seedModelProviderQueries } from '@/test/console/model-provider'
|
||||
import { createConsoleQueryWrapper } from '@/test/console/query-data'
|
||||
import { createToolProviderFixture } from '@/test/console/tool-provider-fixture'
|
||||
import { createDeferred } from '@/test/deferred'
|
||||
import { createPluginEntity } from '@/test/fixtures/plugin'
|
||||
import { renderWithNuqs } from '@/test/nuqs-testing'
|
||||
import ProviderList from '../tool-provider-list'
|
||||
|
||||
const api = vi.hoisted(() => ({
|
||||
createMCP:
|
||||
vi.fn<
|
||||
typeof import('@/service/console').consoleClient.workspaces.current.toolProvider.mcp.post
|
||||
>(),
|
||||
authorizeMCP:
|
||||
vi.fn<
|
||||
typeof import('@/service/console').consoleClient.workspaces.current.toolProvider.mcp.auth.post
|
||||
>(),
|
||||
updateMCPTools:
|
||||
vi.fn<
|
||||
typeof import('@/service/console').consoleClient.workspaces.current.toolProvider.mcp.update.byProviderId.get
|
||||
>(),
|
||||
mcpTools:
|
||||
vi.fn<
|
||||
typeof import('@/service/console').consoleClient.workspaces.current.toolProvider.mcp.tools.byProviderId.get
|
||||
>(),
|
||||
installed:
|
||||
vi.fn<
|
||||
typeof import('@/service/console').consoleClient.workspaces.current.plugin.list.installations.ids.post
|
||||
>(),
|
||||
uninstall:
|
||||
vi.fn<
|
||||
typeof import('@/service/console').consoleClient.workspaces.current.plugin.uninstall.post
|
||||
>(),
|
||||
|
||||
providers:
|
||||
vi.fn<typeof import('@/service/console').consoleClient.workspaces.current.toolProviders.get>(),
|
||||
custom:
|
||||
vi.fn<typeof import('@/service/console').consoleClient.workspaces.current.tools.api.get>(),
|
||||
workflow:
|
||||
vi.fn<typeof import('@/service/console').consoleClient.workspaces.current.tools.workflow.get>(),
|
||||
builtinTools:
|
||||
vi.fn<
|
||||
typeof import('@/service/console').consoleClient.workspaces.current.toolProvider.builtin.byProvider.tools.get
|
||||
>(),
|
||||
createCustom:
|
||||
vi.fn<
|
||||
typeof import('@/service/console').consoleClient.workspaces.current.toolProvider.api.add.post
|
||||
>(),
|
||||
parseSchema:
|
||||
vi.fn<
|
||||
typeof import('@/service/console').consoleClient.workspaces.current.toolProvider.api.schema.post
|
||||
>(),
|
||||
deleteMCP:
|
||||
vi.fn<
|
||||
typeof import('@/service/console').consoleClient.workspaces.current.toolProvider.mcp.delete
|
||||
>(),
|
||||
collections: vi.fn<typeof import('@/service/marketplace').marketplaceClient.collections>(),
|
||||
}))
|
||||
|
||||
vi.mock('@/service/console', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('@/service/console')>()
|
||||
const { withConsoleResponses, withConsoleClientResponses } =
|
||||
await import('@/test/console/service-responses')
|
||||
return {
|
||||
...actual,
|
||||
consoleQuery: withConsoleResponses(actual.consoleQuery, {
|
||||
'remoteFiles.upload.post': async () => ({
|
||||
id: 'favicon',
|
||||
name: 'favicon.png',
|
||||
size: 10,
|
||||
mime_type: 'image/png',
|
||||
url: '/favicon.png',
|
||||
created_at: null,
|
||||
created_by: null,
|
||||
extension: null,
|
||||
}),
|
||||
'workspaces.current.plugin.uninstall.post': api.uninstall,
|
||||
'workspaces.current.toolProviders.get': api.providers,
|
||||
'workspaces.current.plugin.list.installations.ids.post': api.installed,
|
||||
'workspaces.current.toolProvider.builtin.byProvider.tools.get': api.builtinTools,
|
||||
'workspaces.current.tools.api.get': api.custom,
|
||||
'workspaces.current.tools.workflow.get': api.workflow,
|
||||
'workspaces.current.toolProvider.mcp.delete': api.deleteMCP,
|
||||
'workspaces.current.toolProvider.mcp.post': api.createMCP,
|
||||
'workspaces.current.toolProvider.mcp.auth.post': api.authorizeMCP,
|
||||
'workspaces.current.toolProvider.mcp.update.byProviderId.get': api.updateMCPTools,
|
||||
'workspaces.current.toolProvider.mcp.tools.byProviderId.get': api.mcpTools,
|
||||
'workspaces.current.plugin.installedIds.get': async () => ({ plugin_ids: [] }),
|
||||
}),
|
||||
consoleClient: withConsoleClientResponses(actual.consoleClient, {
|
||||
'workspaces.current.toolProvider.builtin.byProvider.tools.get': api.builtinTools,
|
||||
'workspaces.current.toolProvider.api.add.post': api.createCustom,
|
||||
'workspaces.current.plugin.tasks.get': async () => ({ tasks: [] }),
|
||||
'workspaces.current.toolProvider.api.schema.post': api.parseSchema,
|
||||
'workspaces.current.plugin.permission.fetch.get': async () => ({
|
||||
install_permission: 'everyone',
|
||||
debug_permission: 'everyone',
|
||||
}),
|
||||
'workspaces.current.plugin.autoUpgrade.fetch.get': async () => ({
|
||||
category: 'tool',
|
||||
auto_upgrade: {
|
||||
strategy_setting: 'fix_only',
|
||||
upgrade_time_of_day: 0,
|
||||
upgrade_mode: 'all',
|
||||
exclude_plugins: [],
|
||||
include_plugins: [],
|
||||
},
|
||||
}),
|
||||
}),
|
||||
}
|
||||
})
|
||||
vi.mock('@/service/marketplace', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('@/service/marketplace')>()
|
||||
return {
|
||||
...actual,
|
||||
marketplaceClient: { ...actual.marketplaceClient, collections: api.collections },
|
||||
}
|
||||
})
|
||||
vi.mock('@/next/navigation', async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import('@/next/navigation')>()),
|
||||
useRouter: () => ({ push: vi.fn() }),
|
||||
}))
|
||||
|
||||
vi.mock('@/service/base', async (importOriginal) => ({
|
||||
...(await importOriginal<typeof import('@/service/base')>()),
|
||||
get: async (url: string) => {
|
||||
if (
|
||||
url ===
|
||||
'/workspaces/current/tool-provider/builtin/langgenius/plugin-entity/plugin-entity/credential/info'
|
||||
)
|
||||
return {
|
||||
supported_credential_types: [],
|
||||
credentials: [],
|
||||
is_oauth_custom_client_enabled: false,
|
||||
}
|
||||
throw new Error(`Unexpected service request: ${url}`)
|
||||
},
|
||||
}))
|
||||
|
||||
const pluginEntity = createPluginEntity()
|
||||
pluginEntity.declaration.tool = {
|
||||
credentials_schema: [],
|
||||
identity: {
|
||||
author: 'Dify',
|
||||
name: 'plugin-entity',
|
||||
icon: 'icon.svg',
|
||||
label: { en_US: 'Plugin label' },
|
||||
description: { en_US: 'Plugin description' },
|
||||
},
|
||||
}
|
||||
const pluginProvider = createToolProviderFixture({
|
||||
id: 'plugin-provider',
|
||||
name: 'langgenius/plugin-entity/plugin-entity',
|
||||
label: { en_US: 'Installed Plugin' },
|
||||
plugin_id: pluginEntity.plugin_id,
|
||||
})
|
||||
|
||||
const builtin = [
|
||||
createToolProviderFixture({
|
||||
id: 'google',
|
||||
name: 'google-search',
|
||||
label: { en_US: 'Google Search', zh_Hans: '谷歌搜索' },
|
||||
description: { en_US: 'Search the web' },
|
||||
labels: ['search'],
|
||||
allow_delete: false,
|
||||
}),
|
||||
createToolProviderFixture({
|
||||
id: 'weather',
|
||||
name: 'weather-tool',
|
||||
label: { en_US: 'Weather Tool' },
|
||||
description: { en_US: 'Weather forecast' },
|
||||
labels: ['utilities'],
|
||||
allow_delete: false,
|
||||
}),
|
||||
]
|
||||
const custom = createToolProviderFixture({
|
||||
id: 'custom',
|
||||
name: 'my-api',
|
||||
type: 'api',
|
||||
label: { en_US: 'My API Tool' },
|
||||
author: 'Custom Author',
|
||||
labels: ['api'],
|
||||
})
|
||||
const workflow = createToolProviderFixture({
|
||||
id: 'workflow',
|
||||
name: 'workflow-tool',
|
||||
type: 'workflow',
|
||||
label: { en_US: 'Workflow Tool' },
|
||||
author: 'Workflow Author',
|
||||
labels: ['productivity'],
|
||||
})
|
||||
const mcp = createToolProviderFixture({
|
||||
id: 'mcp-database-id',
|
||||
name: 'MCP Server',
|
||||
type: 'mcp',
|
||||
server_identifier: 'mcp-server',
|
||||
label: { en_US: 'MCP Server' },
|
||||
server_url: 'https://mcp.example.com',
|
||||
})
|
||||
|
||||
type RenderOptions = {
|
||||
category?: ComponentProps<typeof ProviderList>['category']
|
||||
searchParams?: Record<string, string>
|
||||
permissions?: string[]
|
||||
providers?: typeof builtin
|
||||
customTools?: typeof builtin
|
||||
workflowTools?: typeof builtin
|
||||
pending?: boolean
|
||||
marketplace?: boolean
|
||||
}
|
||||
const renderProviderList = ({
|
||||
category,
|
||||
searchParams,
|
||||
permissions = ['tool.manage', 'mcp.manage'],
|
||||
providers = builtin,
|
||||
customTools = [custom],
|
||||
workflowTools = [workflow],
|
||||
pending = false,
|
||||
marketplace = false,
|
||||
}: RenderOptions = {}) => {
|
||||
const { wrapper: Wrapper, queryClient } = createConsoleQueryWrapper({
|
||||
workspacePermissionKeys: permissions,
|
||||
systemFeatures: { enable_marketplace: marketplace, rbac_enabled: true },
|
||||
})
|
||||
seedModelProviderQueries(queryClient)
|
||||
if (!pending) {
|
||||
queryClient.setQueryData(
|
||||
consoleQuery.workspaces.current.toolProviders.get.queryKey({ input: { query: {} } }),
|
||||
providers,
|
||||
)
|
||||
queryClient.setQueryData(
|
||||
consoleQuery.workspaces.current.toolProviders.get.queryKey({
|
||||
input: { query: { type: 'mcp' } },
|
||||
}),
|
||||
providers.filter((item) => item.type === 'mcp'),
|
||||
)
|
||||
queryClient.setQueryData(consoleQuery.workspaces.current.tools.api.get.queryKey(), customTools)
|
||||
queryClient.setQueryData(
|
||||
consoleQuery.workspaces.current.tools.workflow.get.queryKey(),
|
||||
workflowTools,
|
||||
)
|
||||
}
|
||||
return renderWithNuqs(
|
||||
<Wrapper>
|
||||
<ProviderList category={category} contentInset="compact" />
|
||||
</Wrapper>,
|
||||
{ searchParams },
|
||||
)
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
api.createMCP.mockReset().mockResolvedValue(mcp)
|
||||
api.authorizeMCP.mockReset().mockResolvedValue({ result: 'success' })
|
||||
api.updateMCPTools.mockReset().mockResolvedValue(mcp)
|
||||
api.mcpTools.mockReset().mockResolvedValue(mcp)
|
||||
api.installed.mockReset().mockResolvedValue({ plugins: [pluginEntity] })
|
||||
api.uninstall.mockReset().mockResolvedValue({ success: true })
|
||||
api.providers.mockReset().mockResolvedValue(builtin)
|
||||
api.custom.mockReset().mockResolvedValue([custom])
|
||||
api.workflow.mockReset().mockResolvedValue([workflow])
|
||||
api.builtinTools.mockReset().mockResolvedValue([])
|
||||
api.createCustom.mockReset().mockResolvedValue({ result: 'success' })
|
||||
api.parseSchema.mockReset().mockResolvedValue({
|
||||
parameters_schema: [],
|
||||
credentials_schema: [],
|
||||
warning: {},
|
||||
schema_type: 'openapi',
|
||||
})
|
||||
api.deleteMCP.mockReset().mockResolvedValue({ result: 'success' })
|
||||
api.collections.mockReset().mockResolvedValue({ data: { collections: [] } })
|
||||
})
|
||||
afterEach(async () => {
|
||||
await act(async () => cleanup())
|
||||
})
|
||||
|
||||
it('lets read-only users browse every category and synchronizes the selected category to the URL', async () => {
|
||||
const user = userEvent.setup()
|
||||
const { onUrlUpdate } = renderProviderList({ permissions: [], providers: [...builtin, mcp] })
|
||||
expect(screen.getByRole('radio', { name: 'tools.type.builtIn' })).toBeChecked()
|
||||
expect(screen.getByRole('button', { name: /Google Search/ })).toBeInTheDocument()
|
||||
for (const [tab, label, category] of [
|
||||
['tools.type.custom', 'My API Tool', 'api'],
|
||||
['tools.type.workflow', 'Workflow Tool', 'workflow'],
|
||||
['MCP', 'MCP Server', 'mcp'],
|
||||
] as const) {
|
||||
await user.click(screen.getByRole('radio', { name: tab }))
|
||||
expect(await screen.findByRole('button', { name: new RegExp(label) })).toBeInTheDocument()
|
||||
await waitFor(() =>
|
||||
expect(onUrlUpdate).toHaveBeenLastCalledWith(
|
||||
expect.objectContaining({ queryString: `?category=${category}` }),
|
||||
),
|
||||
)
|
||||
expect(
|
||||
screen.queryByRole('button', {
|
||||
name: /tools\.(addSwaggerAPIAsTool|createSwaggerAPIAsTool|mcp.create.cardTitle)/,
|
||||
}),
|
||||
).not.toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: 'common.tag.tags' })).not.toBeInTheDocument()
|
||||
expect(
|
||||
screen.queryByRole('button', { name: /plugin.autoUpdate.autoUpdate/ }),
|
||||
).not.toBeInTheDocument()
|
||||
}
|
||||
expect(screen.queryByRole('button', { name: 'common.operation.more' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('uses the route category instead of a conflicting query parameter', () => {
|
||||
renderProviderList({ category: 'workflow', searchParams: { category: 'api' } })
|
||||
expect(screen.getByRole('button', { name: /Workflow Tool/ })).toHaveTextContent('Workflow Author')
|
||||
expect(screen.getByRole('button', { name: /Workflow Tool/ })).toHaveTextContent('productivity')
|
||||
expect(screen.queryByRole('radiogroup')).not.toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: /My API Tool/ })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('matches localized labels within the category and restores the list when search is cleared', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderProviderList({ category: 'builtin' })
|
||||
await user.type(screen.getByRole('searchbox'), '谷歌')
|
||||
expect(screen.getByRole('button', { name: /Google Search/ })).toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: /Weather Tool/ })).not.toBeInTheDocument()
|
||||
await user.clear(screen.getByRole('searchbox'))
|
||||
await user.type(screen.getByRole('searchbox'), 'My API')
|
||||
expect(
|
||||
screen.queryByRole('button', { name: /Google Search|My API Tool/ }),
|
||||
).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('tools.noTools')).not.toBeInTheDocument()
|
||||
await user.click(screen.getByRole('button', { name: 'common.operation.clear' }))
|
||||
expect(screen.getByRole('button', { name: /Weather Tool/ })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('applies and clears builtin tags without filtering other categories', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderProviderList()
|
||||
await user.click(screen.getByRole('button', { name: 'common.tag.tags' }))
|
||||
await user.click(await screen.findByRole('button', { name: 'pluginTags.tags.search' }))
|
||||
await user.keyboard('{Escape}')
|
||||
expect(screen.queryByRole('button', { name: /Weather Tool/ })).not.toBeInTheDocument()
|
||||
await user.click(screen.getByRole('radio', { name: 'tools.type.custom' }))
|
||||
expect(screen.getByRole('button', { name: /My API Tool/ })).toBeInTheDocument()
|
||||
await user.click(screen.getByRole('radio', { name: 'tools.type.builtIn' }))
|
||||
expect(screen.queryByRole('button', { name: /Weather Tool/ })).not.toBeInTheDocument()
|
||||
await user.click(screen.getByRole('button', { name: 'common.operation.clear' }))
|
||||
expect(screen.getByRole('button', { name: /Weather Tool/ })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('opens the builtin provider details and clears selection when changing categories', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderProviderList()
|
||||
await user.click(screen.getByRole('button', { name: /Google Search/ }))
|
||||
const detail = await screen.findByRole('dialog')
|
||||
expect(within(detail).getByText('Google Search')).toBeInTheDocument()
|
||||
await waitFor(() =>
|
||||
expect(api.builtinTools).toHaveBeenCalledWith({ params: { provider: 'google-search' } }),
|
||||
)
|
||||
await user.click(screen.getByRole('radio', { name: 'tools.type.builtIn' }))
|
||||
expect(screen.getByRole('dialog')).toBeInTheDocument()
|
||||
await user.click(screen.getByRole('radio', { name: 'tools.type.custom' }))
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())
|
||||
await user.click(screen.getByRole('radio', { name: 'tools.type.builtIn' }))
|
||||
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('closes provider details from its close control', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderProviderList()
|
||||
await user.click(screen.getByRole('button', { name: /Google Search/ }))
|
||||
const detail = await screen.findByRole('dialog')
|
||||
await user.click(within(detail).getByRole('button', { name: 'common.operation.close' }))
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())
|
||||
expect(screen.getByRole('button', { name: /Google Search/ })).not.toHaveAttribute('aria-current')
|
||||
})
|
||||
|
||||
it('waits for the builtin catalog before showing the empty state', async () => {
|
||||
const request = createDeferred<Awaited<ReturnType<typeof api.providers>>>()
|
||||
api.providers.mockReturnValue(request.promise)
|
||||
renderProviderList({ pending: true })
|
||||
expect(screen.queryByText('tools.noTools')).not.toBeInTheDocument()
|
||||
await act(async () => request.resolve([]))
|
||||
expect(await screen.findByText('tools.noTools')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('distinguishes an empty workflow catalog from a search with no matches', async () => {
|
||||
const user = userEvent.setup()
|
||||
const { unmount } = renderProviderList({ category: 'workflow', workflowTools: [] })
|
||||
expect(screen.getByRole('link', { name: /tools.workflowToolEmpty.goToStudio/ })).toHaveAttribute(
|
||||
'href',
|
||||
'/apps',
|
||||
)
|
||||
unmount()
|
||||
renderProviderList({ category: 'workflow' })
|
||||
await user.type(screen.getByRole('searchbox'), 'not-found')
|
||||
expect(screen.queryByRole('button', { name: /Workflow Tool/ })).not.toBeInTheDocument()
|
||||
expect(
|
||||
screen.queryByRole('link', { name: /tools.workflowToolEmpty.goToStudio/ }),
|
||||
).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it.each([
|
||||
{ initial: [], entry: 'tools.createSwaggerAPIAsTool' },
|
||||
{ initial: [custom], entry: 'tools.addSwaggerAPIAsTool' },
|
||||
])('creates a custom tool through $entry and refreshes the catalog', async ({ initial, entry }) => {
|
||||
const user = userEvent.setup()
|
||||
const created = createToolProviderFixture({
|
||||
id: 'created',
|
||||
name: 'New Collection',
|
||||
type: 'api',
|
||||
label: { en_US: 'New Collection' },
|
||||
})
|
||||
api.custom.mockResolvedValue([...initial, created])
|
||||
renderProviderList({ category: 'api', customTools: initial })
|
||||
await user.click(screen.getByRole('button', { name: entry }))
|
||||
const drawer = await screen.findByRole('dialog', { name: 'tools.createTool.title' })
|
||||
await user.type(
|
||||
within(drawer).getByRole('textbox', { name: /tools.createTool.name/ }),
|
||||
'New Collection',
|
||||
)
|
||||
const schema = JSON.stringify({
|
||||
openapi: '3.0.0',
|
||||
info: { title: 'Weather', version: '1.0.0' },
|
||||
servers: [{ url: 'https://weather.example.com' }],
|
||||
paths: {},
|
||||
})
|
||||
await user.click(within(drawer).getByPlaceholderText('tools.createTool.schemaPlaceHolder'))
|
||||
await user.paste(schema)
|
||||
await waitFor(() => expect(api.parseSchema).toHaveBeenCalledWith({ body: { schema } }))
|
||||
await user.click(within(drawer).getByRole('button', { name: 'common.operation.save' }))
|
||||
await waitFor(() =>
|
||||
expect(api.createCustom).toHaveBeenCalledWith({
|
||||
body: expect.objectContaining({
|
||||
provider: 'New Collection',
|
||||
schema,
|
||||
schema_type: 'openapi',
|
||||
credentials: { auth_type: 'none' },
|
||||
}),
|
||||
}),
|
||||
)
|
||||
expect(await screen.findByRole('button', { name: /New Collection/ })).toBeInTheDocument()
|
||||
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
|
||||
expect(
|
||||
screen.queryByRole('button', { name: 'tools.createSwaggerAPIAsTool' }),
|
||||
).not.toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: 'tools.addSwaggerAPIAsTool' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it.each([
|
||||
{ state: 'empty', providers: [] },
|
||||
{ state: 'populated', providers: [mcp] },
|
||||
])('creates and authorizes an MCP provider from the $state catalog', async ({ providers }) => {
|
||||
const user = userEvent.setup()
|
||||
const created = createToolProviderFixture({
|
||||
...mcp,
|
||||
id: 'created-mcp-id',
|
||||
name: 'New MCP',
|
||||
server_identifier: 'new-mcp',
|
||||
server_url: 'https://new.example.com',
|
||||
})
|
||||
const connected = createToolProviderFixture({ ...created, is_team_authorization: true })
|
||||
api.createMCP.mockResolvedValue(created)
|
||||
api.providers.mockResolvedValue([...providers, created])
|
||||
api.updateMCPTools.mockImplementation(async () => {
|
||||
api.providers.mockResolvedValue([...providers, connected])
|
||||
return connected
|
||||
})
|
||||
api.mcpTools.mockResolvedValue(connected)
|
||||
renderProviderList({ searchParams: { category: 'mcp' }, providers })
|
||||
await user.click(screen.getByRole('button', { name: 'tools.mcp.create.cardTitle' }))
|
||||
const form = await screen.findByRole('dialog', { name: 'tools.mcp.modal.title' })
|
||||
await user.type(
|
||||
within(form).getByRole('textbox', { name: 'tools.mcp.modal.serverUrl' }),
|
||||
'https://new.example.com',
|
||||
)
|
||||
await user.type(within(form).getByRole('textbox', { name: 'tools.mcp.modal.name' }), 'New MCP')
|
||||
await user.type(
|
||||
within(form).getByRole('textbox', { name: 'tools.mcp.modal.serverIdentifier' }),
|
||||
'new-mcp',
|
||||
)
|
||||
await waitFor(() =>
|
||||
expect(within(form).getByRole('button', { name: 'tools.mcp.modal.confirm' })).toBeEnabled(),
|
||||
)
|
||||
await user.click(within(form).getByRole('button', { name: 'tools.mcp.modal.confirm' }))
|
||||
await waitFor(() =>
|
||||
expect(api.createMCP).toHaveBeenCalledWith({
|
||||
body: expect.objectContaining({
|
||||
name: 'New MCP',
|
||||
server_url: 'https://new.example.com',
|
||||
server_identifier: 'new-mcp',
|
||||
}),
|
||||
}),
|
||||
)
|
||||
await waitFor(() =>
|
||||
expect(screen.queryByRole('dialog', { name: 'tools.mcp.modal.title' })).not.toBeInTheDocument(),
|
||||
)
|
||||
const detail = await screen.findByRole('dialog')
|
||||
expect(within(detail).getByText('New MCP')).toBeInTheDocument()
|
||||
expect(
|
||||
await within(detail).findByRole('button', { name: 'tools.auth.authorized' }),
|
||||
).toBeInTheDocument()
|
||||
expect(api.authorizeMCP).toHaveBeenCalledExactlyOnceWith({
|
||||
body: { provider_id: 'created-mcp-id' },
|
||||
})
|
||||
await user.click(within(detail).getByRole('button', { name: 'common.operation.close' }))
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())
|
||||
await user.click(screen.getByRole('button', { name: /New MCP/ }))
|
||||
expect(await screen.findByRole('dialog')).toBeInTheDocument()
|
||||
expect(api.authorizeMCP).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('discards an unfinished MCP creation when cancelled and keeps the documentation link available', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderProviderList({ searchParams: { category: 'mcp' }, providers: [] })
|
||||
expect(screen.getByRole('link', { name: 'tools.mcp.create.cardLink' })).toHaveAttribute(
|
||||
'href',
|
||||
expect.stringContaining('/workspace/tools#mcp'),
|
||||
)
|
||||
await user.click(screen.getByRole('button', { name: 'tools.mcp.create.cardTitle' }))
|
||||
let form = await screen.findByRole('dialog', { name: 'tools.mcp.modal.title' })
|
||||
await user.type(within(form).getByRole('textbox', { name: 'tools.mcp.modal.name' }), 'Unfinished')
|
||||
await user.click(within(form).getByRole('button', { name: 'tools.mcp.modal.cancel' }))
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())
|
||||
await user.click(screen.getByRole('button', { name: 'tools.mcp.create.cardTitle' }))
|
||||
form = await screen.findByRole('dialog', { name: 'tools.mcp.modal.title' })
|
||||
expect(within(form).getByRole('textbox', { name: 'tools.mcp.modal.name' })).toHaveValue('')
|
||||
expect(api.createMCP).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('deletes an MCP provider using its database id and removes it after refresh', async () => {
|
||||
const user = userEvent.setup()
|
||||
api.providers.mockResolvedValue([])
|
||||
renderProviderList({ category: 'mcp', providers: [mcp] })
|
||||
await user.click(screen.getByRole('button', { name: 'common.operation.more' }))
|
||||
await user.click(await screen.findByRole('menuitem', { name: 'tools.mcp.operation.remove' }))
|
||||
const dialog = await screen.findByRole('alertdialog', { name: 'tools.mcp.delete' })
|
||||
await user.click(within(dialog).getByRole('button', { name: 'common.operation.confirm' }))
|
||||
await waitFor(() =>
|
||||
expect(api.deleteMCP).toHaveBeenCalledWith({ body: { provider_id: 'mcp-database-id' } }),
|
||||
)
|
||||
await waitFor(() =>
|
||||
expect(screen.queryByRole('button', { name: /MCP Server/ })).not.toBeInTheDocument(),
|
||||
)
|
||||
expect(screen.queryByRole('alertdialog')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('allows plugin preferences from the builtin toolbar with the matching permission', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderProviderList({ category: 'builtin', permissions: ['plugin.plugin_preferences'] })
|
||||
await user.click(screen.getByRole('button', { name: /plugin.autoUpdate.autoUpdate/ }))
|
||||
const dialog = await screen.findByRole('dialog', { name: 'plugin.autoUpdate.autoUpdateSettings' })
|
||||
expect(
|
||||
await within(dialog).findByText('plugin.autoUpdate.strategy.fixOnly.name'),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it.each([
|
||||
{ category: 'builtin', permissions: [] },
|
||||
{ category: 'api', permissions: ['plugin.plugin_preferences'] },
|
||||
] as const)(
|
||||
'does not offer plugin settings for $category with $permissions',
|
||||
({ category, permissions }) => {
|
||||
renderProviderList({ category, permissions: [...permissions] })
|
||||
expect(
|
||||
screen.queryByRole('button', { name: /plugin.autoUpdate.autoUpdate/ }),
|
||||
).not.toBeInTheDocument()
|
||||
},
|
||||
)
|
||||
|
||||
it.each([
|
||||
{ category: 'builtin', marketplace: false },
|
||||
{ category: 'api', marketplace: true },
|
||||
] as const)(
|
||||
'does not load marketplace for $category when enabled=$marketplace',
|
||||
async (options) => {
|
||||
renderProviderList(options)
|
||||
await act(async () => {})
|
||||
expect(screen.queryByText('plugin.marketplace.moreFrom')).not.toBeInTheDocument()
|
||||
expect(api.collections).not.toHaveBeenCalled()
|
||||
},
|
||||
)
|
||||
|
||||
it('loads the tool marketplace when the user expands it', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderProviderList({ marketplace: true })
|
||||
await user.click(screen.getByRole('button', { name: 'plugin.marketplace.moreFrom' }))
|
||||
await waitFor(() =>
|
||||
expect(api.collections).toHaveBeenCalledWith(
|
||||
{ query: expect.objectContaining({ category: 'tool', exclude: [] }) },
|
||||
expect.anything(),
|
||||
),
|
||||
)
|
||||
expect(screen.getByText('plugin.marketplace.moreFrom')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('loads an installed plugin detail and closes it without losing the catalog', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderProviderList({ providers: [pluginProvider], permissions: [] })
|
||||
await user.click(screen.getByRole('button', { name: /Installed Plugin/ }))
|
||||
const detail = await screen.findByRole('dialog')
|
||||
expect(within(detail).getByText('Plugin label')).toBeInTheDocument()
|
||||
expect(api.installed).toHaveBeenCalledWith({ body: { plugin_ids: ['langgenius/plugin-entity'] } })
|
||||
await user.click(
|
||||
within(detail).getByRole('button', { name: 'plugin.detailPanel.operation.moreActions' }),
|
||||
)
|
||||
expect(
|
||||
screen.queryByRole('menuitem', { name: 'plugin.detailPanel.operation.remove' }),
|
||||
).not.toBeInTheDocument()
|
||||
await user.keyboard('{Escape}')
|
||||
await user.click(within(detail).getByRole('button', { name: 'common.operation.close' }))
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())
|
||||
expect(screen.getByRole('button', { name: /Installed Plugin/ })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('uninstalls a plugin from its real details and refreshes the tool catalog', async () => {
|
||||
const user = userEvent.setup()
|
||||
api.providers.mockResolvedValue([])
|
||||
renderProviderList({ providers: [pluginProvider], permissions: ['plugin.delete'] })
|
||||
await user.click(screen.getByRole('button', { name: /Installed Plugin/ }))
|
||||
const detail = await screen.findByRole('dialog')
|
||||
await user.click(
|
||||
within(detail).getByRole('button', { name: 'plugin.detailPanel.operation.moreActions' }),
|
||||
)
|
||||
await user.click(
|
||||
await screen.findByRole('menuitem', { name: 'plugin.detailPanel.operation.remove' }),
|
||||
)
|
||||
const confirm = await screen.findByRole('alertdialog', { name: 'plugin.action.delete' })
|
||||
await user.click(within(confirm).getByRole('button', { name: 'common.operation.confirm' }))
|
||||
await waitFor(() =>
|
||||
expect(api.uninstall).toHaveBeenCalledWith({
|
||||
body: { plugin_installation_id: pluginEntity.id, preserve_credentials: false },
|
||||
}),
|
||||
)
|
||||
expect(await screen.findByText('tools.noTools')).toBeInTheDocument()
|
||||
expect(screen.queryByRole('dialog')).not.toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: /Installed Plugin/ })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('discards an unfinished custom tool and links to the API tool documentation', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderProviderList({ category: 'api', customTools: [] })
|
||||
expect(screen.getByRole('link', { name: 'tools.swaggerAPIAsToolTip' })).toHaveAttribute(
|
||||
'href',
|
||||
expect.stringContaining('/workspace/tools#swagger-api'),
|
||||
)
|
||||
await user.click(screen.getByRole('button', { name: 'tools.createSwaggerAPIAsTool' }))
|
||||
let form = await screen.findByRole('dialog', { name: 'tools.createTool.title' })
|
||||
await user.type(
|
||||
within(form).getByRole('textbox', { name: /tools.createTool.name/ }),
|
||||
'Unfinished',
|
||||
)
|
||||
await user.click(within(form).getByRole('button', { name: 'common.operation.cancel' }))
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument())
|
||||
await user.click(screen.getByRole('button', { name: 'tools.createSwaggerAPIAsTool' }))
|
||||
form = await screen.findByRole('dialog', { name: 'tools.createTool.title' })
|
||||
expect(within(form).getByRole('textbox', { name: /tools.createTool.name/ })).toHaveValue('')
|
||||
expect(api.createCustom).not.toHaveBeenCalled()
|
||||
})
|
||||
Reference in new issue
Block a user