Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

chore: improve Custom Endpoint accessibility (SNP-876) (#43060)

Joel702012019723
diff --git a/web/app/components/header/account-setting/api-based-extension-page/__tests__/index.spec.tsx b/web/app/components/header/account-setting/api-based-extension-page/__tests__/index.spec.tsx
index 7e9d6d163d9..f9e7a3b2107 100644
--- a/web/app/components/header/account-setting/api-based-extension-page/__tests__/index.spec.tsx
+++ b/web/app/components/header/account-setting/api-based-extension-page/__tests__/index.spec.tsx
@@ -1,5 +1,6 @@
import type { ApiBasedExtensionResponse } from '@dify/contracts/api/console/api-based-extension/types.gen'
import { fireEvent, screen, waitFor } from '@testing-library/react'
+import userEvent from '@testing-library/user-event'
import { renderWithConsoleQuery as render } from '@/test/console/query-data'
import { ApiBasedExtensionPage } from '../index'
@@ -181,7 +182,7 @@ describe('ApiBasedExtensionPage', () => {
expect(screen.queryByText('Beta Extension')).not.toBeInTheDocument()
})
- it('should render a search empty state without showing the onboarding empty state', () => {
+ it('should announce an empty search result without showing the onboarding empty state', async () => {
// Arrange
const mockData: ApiBasedExtensionResponse[] = [
{
@@ -198,14 +199,13 @@ describe('ApiBasedExtensionPage', () => {
// Act
render(<ApiBasedExtensionPage />)
- fireEvent.change(screen.getByPlaceholderText('common.operation.search'), {
- target: { value: 'missing' },
- })
+ const user = userEvent.setup()
+ await user.type(screen.getByPlaceholderText('common.operation.search'), 'missing')
// Assert
- expect(
- screen.getByText('common.dataSource.notion.selector.noSearchResult'),
- )!.toBeInTheDocument()
+ expect(screen.getByRole('status')).toHaveTextContent(
+ 'common.dataSource.notion.selector.noSearchResult',
+ )
expect(screen.queryByText('common.apiBasedExtension.title')).not.toBeInTheDocument()
expect(screen.queryByText('Alpha Extension')).not.toBeInTheDocument()
})
@@ -245,8 +245,12 @@ describe('ApiBasedExtensionPage', () => {
// Assert
expect(screen.getByRole('button', { name: 'common.apiBasedExtension.add' })).toBeDisabled()
- expect(screen.getByRole('button', { name: 'common.operation.edit' })).toBeDisabled()
- expect(screen.getByRole('button', { name: 'common.operation.delete' })).toBeDisabled()
+ expect(
+ screen.getByRole('button', { name: /common\.operation\.edit.*Extension 1/i }),
+ ).toBeDisabled()
+ expect(
+ screen.getByRole('button', { name: /common\.operation\.delete.*Extension 1/i }),
+ ).toBeDisabled()
})
})
diff --git a/web/app/components/header/account-setting/api-based-extension-page/__tests__/item.spec.tsx b/web/app/components/header/account-setting/api-based-extension-page/__tests__/item.spec.tsx
index f0fe296cd72..c84d668b983 100644
--- a/web/app/components/header/account-setting/api-based-extension-page/__tests__/item.spec.tsx
+++ b/web/app/components/header/account-setting/api-based-extension-page/__tests__/item.spec.tsx
@@ -54,6 +54,31 @@ describe('Item Component', () => {
expect(screen.getByText('https://api.example.com'))!.toBeInTheDocument()
})
+ it('should distinguish the edit and delete buttons for each extension by name', () => {
+ render(
+ <>
+ <Item apiBasedExtension={mockData} onEdit={mockOnEdit} />
+ <Item
+ apiBasedExtension={{ ...mockData, id: '2', name: 'Another Extension' }}
+ onEdit={mockOnEdit}
+ />
+ </>,
+ )
+
+ expect(
+ screen.getByRole('button', { name: /common\.operation\.edit.*Test Extension/i }),
+ ).toBeInTheDocument()
+ expect(
+ screen.getByRole('button', { name: /common\.operation\.delete.*Test Extension/i }),
+ ).toBeInTheDocument()
+ expect(
+ screen.getByRole('button', { name: /common\.operation\.edit.*Another Extension/i }),
+ ).toBeInTheDocument()
+ expect(
+ screen.getByRole('button', { name: /common\.operation\.delete.*Another Extension/i }),
+ ).toBeInTheDocument()
+ })
+
it('should render with minimal extension data', () => {
// Arrange
const minimalData: ApiBasedExtensionResponse = {
@@ -88,8 +113,12 @@ describe('Item Component', () => {
render(<Item apiBasedExtension={mockData} onEdit={mockOnEdit} canManage={false} />)
// Assert
- expect(screen.getByRole('button', { name: 'common.operation.edit' })).toBeDisabled()
- expect(screen.getByRole('button', { name: 'common.operation.delete' })).toBeDisabled()
+ expect(
+ screen.getByRole('button', { name: /common\.operation\.edit.*Test Extension/i }),
+ ).toBeDisabled()
+ expect(
+ screen.getByRole('button', { name: /common\.operation\.delete.*Test Extension/i }),
+ ).toBeDisabled()
})
it('should not open edit or delete flows when management is not allowed', () => {
@@ -207,10 +236,7 @@ describe('Item Component', () => {
// Act
render(<Item apiBasedExtension={mockData} onEdit={mockOnEdit} />)
- const allButtons = screen.getAllByRole('button')
- const editBtn = screen.getByText('common.operation.edit')
- const deleteBtn = allButtons.find((btn) => btn !== editBtn)
- if (deleteBtn) fireEvent.click(deleteBtn)
+ fireEvent.click(screen.getByRole('button', { name: 'Test Extension' }))
// Assert
// Assert
diff --git a/web/app/components/header/account-setting/api-based-extension-page/index.tsx b/web/app/components/header/account-setting/api-based-extension-page/index.tsx
index c01220eedce..295e84fb119 100644
--- a/web/app/components/header/account-setting/api-based-extension-page/index.tsx
+++ b/web/app/components/header/account-setting/api-based-extension-page/index.tsx
@@ -78,6 +78,8 @@ export function ApiBasedExtensionPage({ layout }: ApiBasedExtensionPageProps = {
}, [apiBasedExtensions, keywords])
const hasApiBasedExtensions = apiBasedExtensions.length > 0
const hasSearchKeywords = keywords.trim().length > 0
+ const hasNoSearchResults =
+ !isLoading && hasApiBasedExtensions && hasSearchKeywords && !filteredApiBasedExtensions.length
const handleOpenApiBasedExtensionModal = () => {
if (!canManage) return
@@ -115,14 +117,17 @@ export function ApiBasedExtensionPage({ layout }: ApiBasedExtensionPageProps = {
<>
{isLoading && <ApiBasedExtensionListSkeleton />}
{!isLoading && !hasApiBasedExtensions && <Empty />}
- {!isLoading &&
- hasApiBasedExtensions &&
- hasSearchKeywords &&
- !filteredApiBasedExtensions.length && (
- <div className="py-10 text-center system-sm-regular text-text-tertiary">
- {t(($) => $['dataSource.notion.selector.noSearchResult'], { ns: 'common' })}
- </div>
- )}
+ <div
+ role="status"
+ aria-atomic="true"
+ className={
+ hasNoSearchResults ? 'py-10 text-center system-sm-regular text-text-tertiary' : 'sr-only'
+ }
+ >
+ {hasNoSearchResults
+ ? t(($) => $['dataSource.notion.selector.noSearchResult'], { ns: 'common' })
+ : ''}
+ </div>
{!isLoading &&
!!filteredApiBasedExtensions.length &&
filteredApiBasedExtensions.map((item, index) => (
diff --git a/web/app/components/header/account-setting/api-based-extension-page/item.tsx b/web/app/components/header/account-setting/api-based-extension-page/item.tsx
index adf6e53f22e..d21a1b81fc1 100644
--- a/web/app/components/header/account-setting/api-based-extension-page/item.tsx
+++ b/web/app/components/header/account-setting/api-based-extension-page/item.tsx
@@ -9,7 +9,7 @@ import {
} from '@langgenius/dify-ui/alert-dialog'
import { Button } from '@langgenius/dify-ui/button'
import { useMutation } from '@tanstack/react-query'
-import { useState } from 'react'
+import { useId, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { consoleQuery } from '@/service/console'
@@ -20,6 +20,9 @@ type ItemProps = {
}
export function Item({ apiBasedExtension, onEdit, canManage = true }: ItemProps) {
const { t } = useTranslation(['common'])
+ const nameId = useId()
+ const editLabelId = useId()
+ const deleteLabelId = useId()
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false)
const deleteApiBasedExtensionMutation = useMutation(
consoleQuery.apiBasedExtension.byId.delete.mutationOptions(),
@@ -50,19 +53,27 @@ export function Item({ apiBasedExtension, onEdit, canManage = true }: ItemProps)
return (
<div className="group mb-2 flex items-center rounded-xl border-[0.5px] border-transparent bg-components-input-bg-normal px-4 py-2 focus-within:border-components-input-border-active focus-within:shadow-xs hover:border-components-input-border-active hover:shadow-xs">
<div className="min-w-0 grow">
- <div className="mb-0.5 text-[13px] font-medium text-text-secondary">
+ <div id={nameId} className="mb-0.5 text-[13px] font-medium text-text-secondary">
{apiBasedExtension.name}
</div>
<div className="truncate text-xs text-text-tertiary">{apiBasedExtension.api_endpoint}</div>
</div>
<div className="pointer-events-none flex shrink-0 items-center gap-1 opacity-0 transition-opacity group-focus-within:pointer-events-auto group-focus-within:opacity-100 group-hover:pointer-events-auto group-hover:opacity-100">
- <Button disabled={!canManage} onClick={handleOpenApiBasedExtensionModal}>
+ <Button
+ aria-labelledby={`${editLabelId} ${nameId}`}
+ disabled={!canManage}
+ onClick={handleOpenApiBasedExtensionModal}
+ >
<span className="i-ri-edit-line size-4" aria-hidden="true" />
- {t(($) => $['operation.edit'], { ns: 'common' })}
+ <span id={editLabelId}>{t(($) => $['operation.edit'], { ns: 'common' })}</span>
</Button>
- <Button disabled={!canManage} onClick={() => canManage && setShowDeleteConfirm(true)}>
+ <Button
+ aria-labelledby={`${deleteLabelId} ${nameId}`}
+ disabled={!canManage}
+ onClick={() => canManage && setShowDeleteConfirm(true)}
+ >
<span className="i-ri-delete-bin-line size-4" aria-hidden="true" />
- {t(($) => $['operation.delete'], { ns: 'common' })}
+ <span id={deleteLabelId}>{t(($) => $['operation.delete'], { ns: 'common' })}</span>
</Button>
</div>
<AlertDialog