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.

fix(web): improve app access point accessibility (#44220)

Wu Tianwei3b7c8b356bdf
diff --git a/.github/workflows/accessibility-e2e.yml b/.github/workflows/accessibility-e2e.yml
index 1ed08e25704..972fe9c8258 100644
--- a/.github/workflows/accessibility-e2e.yml
+++ b/.github/workflows/accessibility-e2e.yml
@@ -14,6 +14,7 @@ on:
- sign-in
- studio
- agents
+ - app-access-point
- knowledge
- integrations
- all
diff --git a/e2e/features/accessibility/app-access-point.feature b/e2e/features/accessibility/app-access-point.feature
new file mode 100644
index 00000000000..9fea8f94a26
--- /dev/null
+++ b/e2e/features/accessibility/app-access-point.feature
@@ -0,0 +1,210 @@
+@accessibility @axe @authenticated
+Feature: App access point automated WCAG checks
+ Axe checks only automatically detectable issues and does not establish WCAG conformance.
+
+ Scenario Outline: Unpublished <mode> access points have no automatically detectable WCAG Level <level> violations
+ Given I am signed in as the default E2E admin
+ And a "<mode>" app has been created via API
+ When I navigate to the app access point page
+ Then the app access point page should be ready
+ And the current page should have no automatically detectable WCAG Level <level> violations
+
+ @wcag-a @wcag-page-app-access-point
+ Examples: Unpublished apps at Level A
+ | mode | level |
+ | workflow | A |
+ | advanced-chat | A |
+ | chat | A |
+ | completion | A |
+
+ @wcag-aa @wcag-page-app-access-point
+ Examples: Unpublished apps at Level AA
+ | mode | level |
+ | workflow | AA |
+ | advanced-chat | AA |
+ | chat | AA |
+ | completion | AA |
+
+ Scenario Outline: Published workflow access points have no automatically detectable WCAG Level <level> violations
+ Given I am signed in as the default E2E admin
+ And a new runnable workflow app has been published
+ When I navigate to the app access point page
+ Then the app access point page should be ready
+ And the current page should have no automatically detectable WCAG Level <level> violations
+
+ @wcag-a @wcag-page-app-access-point
+ Examples: Published workflow at Level A
+ | level |
+ | A |
+
+ @wcag-aa @wcag-page-app-access-point
+ Examples: Published workflow at Level AA
+ | level |
+ | AA |
+
+ Scenario Outline: App access point <surface> has no automatically detectable WCAG Level <level> violations
+ Given I am signed in as the default E2E admin
+ And a new runnable workflow app has been published
+ When I navigate to the app access point page
+ Then the app access point page should be ready
+ When I open the "<surface>" app access point dialog
+ Then the current page should have no automatically detectable WCAG Level <level> violations
+
+ @wcag-a @wcag-page-app-access-point
+ Examples: Dialogs at Level A
+ | surface | level |
+ | API Key | A |
+ | MCP configuration | A |
+
+ @wcag-aa @wcag-page-app-access-point
+ Examples: Dialogs at Level AA
+ | surface | level |
+ | API Key | AA |
+ | MCP configuration | AA |
+
+ Scenario Outline: API Key creation and deletion dialogs have no automatically detectable WCAG Level <level> violations
+ Given I am signed in as the default E2E admin
+ And a new runnable workflow app has been published
+ And the app has a secret key
+ When I navigate to the app access point page
+ Then the app access point page should be ready
+ When I open the "API Key" app access point dialog
+ Then the app API Key list should contain 1 key
+ And the current page should have no automatically detectable WCAG Level <level> violations
+ When I create a secret key from the app API Key dialog
+ Then only the created API Key dialog should receive keyboard focus
+ And the current page should have no automatically detectable WCAG Level <level> violations
+ When I acknowledge the created app API Key
+ Then the app API Key list should contain 2 keys
+ When I request deletion of the first listed app API Key
+ Then only the app API Key deletion dialog should receive keyboard focus
+ And the current page should have no automatically detectable WCAG Level <level> violations
+ When I cancel deletion of the app API Key
+ Then the app API Key list should contain 2 keys
+ When I request deletion of the first listed app API Key
+ And I confirm deletion of the app API Key
+ Then the app API Key list should contain 1 key
+ And focus should return to the app API Key creation button
+
+ @wcag-a @wcag-page-app-access-point
+ Examples: API Key management at Level A
+ | level |
+ | A |
+
+ @wcag-aa @wcag-page-app-access-point
+ Examples: API Key management at Level AA
+ | level |
+ | AA |
+
+ Scenario Outline: Web App settings <state> have no automatically detectable WCAG Level <level> violations
+ Given I am signed in as the default E2E admin
+ And a published chatflow app with hidden access point inputs
+ When I navigate to the app access point page
+ Then the app access point page should be ready
+ When I open the "Web App settings" app access point dialog
+ And I inspect the Web App settings "<state>"
+ Then the current page should have no automatically detectable WCAG Level <level> violations
+
+ @wcag-a @wcag-page-app-access-point
+ Examples: Web App settings at Level A
+ | state | level |
+ | form | A |
+ | validation errors | A |
+
+ @wcag-aa @wcag-page-app-access-point
+ Examples: Web App settings at Level AA
+ | state | level |
+ | form | AA |
+ | validation errors | AA |
+
+ Scenario Outline: Web App settings <state> popup has no automatically detectable WCAG Level <level> violations
+ Given I am signed in as the default E2E admin
+ And a published chatflow app with hidden access point inputs
+ When I navigate to the app access point page
+ Then the app access point page should be ready
+ When I open the "Web App settings" app access point dialog
+ And I inspect the Web App settings "<state>"
+ Then the current page should have no automatically detectable WCAG Level <level> violations
+ And the Web App settings "<state>" should restore focus after popup dismissal
+
+ @wcag-a @wcag-page-app-access-point
+ Examples: Web App settings popups at Level A
+ | state | level |
+ | language options | A |
+ | icon picker | A |
+
+ @wcag-aa @wcag-page-app-access-point
+ Examples: Web App settings popups at Level AA
+ | state | level |
+ | language options | AA |
+ | icon picker | AA |
+
+ Scenario Outline: Chatflow embedding previews with hidden inputs have no automatically detectable WCAG Level <level> violations
+ Given I am signed in as the default E2E admin
+ And a published chatflow app with hidden access point inputs
+ When I navigate to the app access point page
+ Then the app access point page should be ready
+ And the current page should have no automatically detectable WCAG Level <level> violations
+ When I open the "Embedding" app access point dialog
+ And I expand the embedding hidden input fields
+ And I select the "iframe" embedding preview
+ Then the selected embedding should expose its preview and copy action
+ And the current page should have no automatically detectable WCAG Level <level> violations
+ When I select the "scripts" embedding preview
+ Then the selected embedding should expose its preview and copy action
+ And the current page should have no automatically detectable WCAG Level <level> violations
+ When I select the "Chrome extension" embedding preview
+ Then the selected embedding should expose its preview and copy action
+ And the current page should have no automatically detectable WCAG Level <level> violations
+
+ @wcag-a @wcag-page-app-access-point
+ Examples: Embedding at Level A
+ | level |
+ | A |
+
+ @wcag-aa @wcag-page-app-access-point
+ Examples: Embedding at Level AA
+ | level |
+ | AA |
+
+ Scenario Outline: Workflow hidden input configuration has no automatically detectable WCAG Level <level> violations
+ Given I am signed in as the default E2E admin
+ And a published workflow app with hidden access point inputs
+ When I navigate to the app access point page
+ Then the app access point page should be ready
+ When I open the "Workflow hidden inputs" app access point dialog
+ And I fill the app access point hidden input form
+ Then the current page should have no automatically detectable WCAG Level <level> violations
+ When I open the hidden input language options
+ Then the current page should have no automatically detectable WCAG Level <level> violations
+ And the hidden input language options should dismiss back to the configuration dialog
+
+ @wcag-a @wcag-page-app-access-point
+ Examples: Workflow hidden inputs at Level A
+ | level |
+ | A |
+
+ @wcag-aa @wcag-page-app-access-point
+ Examples: Workflow hidden inputs at Level AA
+ | level |
+ | AA |
+
+ Scenario Outline: Configured MCP parameter descriptions have no automatically detectable WCAG Level <level> violations
+ Given I am signed in as the default E2E admin
+ And a published workflow app with hidden access point inputs
+ And the app has a configured MCP server with parameter descriptions
+ When I navigate to the app access point page
+ Then the app access point page should be ready
+ When I open the "MCP description" app access point dialog
+ Then the configured MCP parameter descriptions should be labelled and populated
+ And the current page should have no automatically detectable WCAG Level <level> violations
+
+ @wcag-a @wcag-page-app-access-point
+ Examples: Configured MCP at Level A
+ | level |
+ | A |
+
+ @wcag-aa @wcag-page-app-access-point
+ Examples: Configured MCP at Level AA
+ | level |
+ | AA |
diff --git a/e2e/features/step-definitions/accessibility/app-access-point.steps.ts b/e2e/features/step-definitions/accessibility/app-access-point.steps.ts
new file mode 100644
index 00000000000..f9cf9f9f11f
--- /dev/null
+++ b/e2e/features/step-definitions/accessibility/app-access-point.steps.ts
@@ -0,0 +1,469 @@
+import type { Locator, Page } from '@playwright/test'
+import type { DifyWorld } from '../../support/world.ts'
+import { Given, Then, When } from '@cucumber/cucumber'
+import { expect } from '@playwright/test'
+import { createTestApp } from '../../../support/api/apps.ts'
+import { syncRunnableWorkflowDraft } from '../../../support/api/workflows.ts'
+import { createE2EResourceName } from '../../../support/naming.ts'
+
+const getAppId = (world: DifyWorld) => {
+ const appId = world.createdAppIds.at(-1)
+ if (!appId) throw new Error('No app has been created for the access point scenario.')
+ return appId
+}
+
+const activateWithKeyboard = async (control: Locator) => {
+ await control.focus()
+ await expect(control).toBeFocused()
+ await control.press('Enter')
+}
+
+const expectDialogFocus = async (page: Page, dialog: Locator) => {
+ await expect(dialog).toBeVisible()
+ await expect(dialog.locator(':focus')).toHaveCount(1)
+ for (const key of ['Tab', 'Shift+Tab']) {
+ await page.keyboard.press(key)
+ await expect(dialog.locator(':focus')).toHaveCount(1)
+ const first = await dialog.locator(':focus').elementHandle()
+ if (!first) throw new Error('The dialog must contain the keyboard focus.')
+ try {
+ let completedCycle = false
+ for (let index = 0; index < 100; index++) {
+ await page.keyboard.press(key)
+ await expect(dialog.locator(':focus')).toHaveCount(1)
+ if (await first.evaluate((element) => element === element.ownerDocument.activeElement)) {
+ completedCycle = true
+ break
+ }
+ }
+ expect(completedCycle, `${key} should complete a focus cycle inside the dialog`).toBe(true)
+ } finally {
+ await first.dispose()
+ }
+ }
+}
+
+const expectExpandedPopup = async (page: Page, control: Locator, popup: Locator) => {
+ await expect(control).toHaveAttribute('aria-expanded', 'true')
+ const controlledId = await control.getAttribute('aria-controls')
+ if (!controlledId) throw new Error('The expanded control must reference its popup.')
+ await expect(popup).toBeVisible()
+ await expect(popup).toHaveAttribute('id', controlledId)
+ await expect(page.locator(`[id=${JSON.stringify(controlledId)}]`)).toHaveCount(1)
+}
+
+Given(
+ 'a published {word} app with hidden access point inputs',
+ async function (this: DifyWorld, kind: string) {
+ if (kind !== 'workflow' && kind !== 'chatflow')
+ throw new Error(`Unsupported access point app kind "${kind}".`)
+ const mode = kind === 'chatflow' ? 'advanced-chat' : 'workflow'
+ const client = this.getConsoleClient()
+ const app = await createTestApp(client, createE2EResourceName('App', 'AccessPoint'), mode)
+ this.createdAppIds.push(app.id)
+ this.lastCreatedAppName = app.name
+ await syncRunnableWorkflowDraft(client, app.id, {
+ mode,
+ variables: [
+ {
+ variable: 'visitor_name',
+ label: 'Visitor name',
+ type: 'text-input',
+ max_length: 80,
+ required: false,
+ hide: true,
+ default: 'E2E visitor',
+ },
+ {
+ variable: 'reply_language',
+ label: 'Reply language',
+ type: 'select',
+ options: ['English', 'French'],
+ required: false,
+ hide: true,
+ default: 'English',
+ },
+ {
+ variable: 'include_details',
+ label: 'Include details',
+ type: 'checkbox',
+ required: false,
+ hide: true,
+ default: false,
+ },
+ ],
+ })
+ await client.apps.byAppId.workflows.publish.post({
+ params: { app_id: app.id },
+ body: { marked_comment: '', marked_name: '' },
+ })
+ },
+)
+
+Given('the app has a secret key', async function (this: DifyWorld) {
+ await this.getConsoleClient().apps.byResourceId.apiKeys.post({
+ params: { resource_id: getAppId(this) },
+ })
+})
+
+Given(
+ 'the app has a configured MCP server with parameter descriptions',
+ async function (this: DifyWorld) {
+ await this.getConsoleClient().apps.byAppId.server.post({
+ params: { app_id: getAppId(this) },
+ body: {
+ description: 'E2E access point tool',
+ parameters: {
+ visitor_name: 'Name of the visitor',
+ reply_language: 'Language for the reply',
+ include_details: 'Whether to include details',
+ },
+ },
+ })
+ },
+)
+
+const getAccessPointDialog = (page: Page, surface: string) => {
+ if (surface === 'API Key') {
+ return {
+ dialog: page.getByRole('dialog', { name: 'API Key', exact: true }),
+ trigger: page
+ .getByRole('region', { name: 'Backend Service API', exact: true })
+ .getByRole('button', { name: /^API Key/ }),
+ }
+ }
+ if (surface === 'MCP configuration') {
+ return {
+ dialog: page.getByRole('dialog', {
+ name: 'Add description to enable MCP server',
+ exact: true,
+ }),
+ trigger: page
+ .getByRole('region', { name: 'MCP Server', exact: true })
+ .getByRole('button', { name: 'Add description', exact: true }),
+ }
+ }
+ if (surface === 'MCP description') {
+ return {
+ dialog: page.getByRole('dialog', { name: 'Edit description', exact: true }),
+ trigger: page
+ .getByRole('region', { name: 'MCP Server', exact: true })
+ .getByRole('button', { name: 'Edit description', exact: true }),
+ }
+ }
+ const webApp = page.getByRole('region', { name: 'Web App', exact: true })
+ if (surface === 'Web App settings') {
+ return {
+ dialog: page.getByRole('dialog', { name: 'Branding', exact: true }),
+ trigger: webApp.getByRole('button', { name: 'Settings', exact: true }),
+ }
+ }
+ if (surface === 'Embedding') {
+ return {
+ dialog: page.getByRole('dialog', { name: 'Embed on website', exact: true }),
+ trigger: webApp.getByRole('button', { name: 'Embed Into Site', exact: true }),
+ }
+ }
+ if (surface === 'Workflow hidden inputs') {
+ return {
+ dialog: page.getByRole('dialog', { name: 'Pre-Fill Hidden Fields', exact: true }),
+ trigger: webApp.getByRole('button', { name: 'Configure', exact: true }),
+ }
+ }
+ throw new Error(`Unknown app access point dialog "${surface}".`)
+}
+
+Then('the app access point page should be ready', async function (this: DifyWorld) {
+ const page = this.getPage()
+ await expect(page).toHaveURL(/\/app\/[^/]+\/access-point(?:\?.*)?$/)
+ await expect(page.getByRole('heading', { name: 'Access Point', level: 1 })).toBeVisible()
+ for (const name of ['Web App', 'Backend Service API', 'MCP Server']) {
+ await expect(page.getByRole('region', { name, exact: true })).toBeVisible()
+ }
+
+ const accessPointCards = page
+ .getByRole('main')
+ .getByRole('region')
+ .filter({ has: page.getByRole('heading', { level: 2 }) })
+ await expect(accessPointCards.and(page.locator('[aria-busy="true"]'))).toHaveCount(0)
+})
+
+When(
+ 'I open the {string} app access point dialog',
+ async function (this: DifyWorld, surface: string) {
+ const { dialog, trigger } = getAccessPointDialog(this.getPage(), surface)
+ await activateWithKeyboard(trigger)
+ await expect(dialog).toBeVisible()
+ if (surface === 'API Key') {
+ await expect(dialog.getByRole('button', { name: 'Create new Secret key' })).toBeVisible()
+ }
+ },
+)
+
+Then(
+ 'the app API Key list should contain {int} key(s)',
+ async function (this: DifyWorld, count: number) {
+ const { dialog } = getAccessPointDialog(this.getPage(), 'API Key')
+ await expect(dialog).toBeVisible()
+ await expect(
+ dialog.getByRole('table', { name: 'API Key', exact: true }).getByRole('row'),
+ ).toHaveCount(count + 1)
+ await expect(dialog.getByRole('button', { name: /^Delete / })).toHaveCount(count)
+ },
+)
+
+When('I create a secret key from the app API Key dialog', async function (this: DifyWorld) {
+ const { dialog } = getAccessPointDialog(this.getPage(), 'API Key')
+ await activateWithKeyboard(
+ dialog.getByRole('button', { name: 'Create new Secret key', exact: true }),
+ )
+})
+
+Then(
+ 'only the created API Key dialog should receive keyboard focus',
+ async function (this: DifyWorld) {
+ const page = this.getPage()
+ const created = page.getByRole('dialog', { name: 'API key created', exact: true })
+ await expectDialogFocus(page, created)
+ await expect(page.getByRole('dialog')).toHaveCount(1)
+ await expect(created.getByRole('textbox', { name: 'Secret Key', exact: true })).toHaveAttribute(
+ 'readonly',
+ '',
+ )
+ },
+)
+
+When('I acknowledge the created app API Key', async function (this: DifyWorld) {
+ const page = this.getPage()
+ const created = page.getByRole('dialog', { name: 'API key created', exact: true })
+ await activateWithKeyboard(
+ created.getByRole('button', { name: 'I have saved this key', exact: true }),
+ )
+ await expect(created).toBeHidden()
+ const { dialog } = getAccessPointDialog(page, 'API Key')
+ await expect(
+ dialog.getByRole('button', { name: 'Create new Secret key', exact: true }),
+ ).toBeFocused()
+})
+
+When('I request deletion of the first listed app API Key', async function (this: DifyWorld) {
+ const { dialog } = getAccessPointDialog(this.getPage(), 'API Key')
+ await activateWithKeyboard(dialog.getByRole('button', { name: /^Delete / }).first())
+})
+
+Then(
+ 'only the app API Key deletion dialog should receive keyboard focus',
+ async function (this: DifyWorld) {
+ const page = this.getPage()
+ const confirmation = page.getByRole('alertdialog', {
+ name: 'Delete this secret key?',
+ exact: true,
+ })
+ await expectDialogFocus(page, confirmation)
+ await expect(page.getByRole('dialog')).toHaveCount(0)
+ await expect(page.getByRole('alertdialog')).toHaveCount(1)
+ },
+)
+
+When('I cancel deletion of the app API Key', async function (this: DifyWorld) {
+ const page = this.getPage()
+ const confirmation = page.getByRole('alertdialog', {
+ name: 'Delete this secret key?',
+ exact: true,
+ })
+ await activateWithKeyboard(confirmation.getByRole('button', { name: 'Cancel', exact: true }))
+ await expect(confirmation).toBeHidden()
+ const { dialog } = getAccessPointDialog(page, 'API Key')
+ await expect(dialog.getByRole('button', { name: /^Delete / }).first()).toBeFocused()
+})
+
+When('I confirm deletion of the app API Key', async function (this: DifyWorld) {
+ const confirmation = this.getPage().getByRole('alertdialog', {
+ name: 'Delete this secret key?',
+ exact: true,
+ })
+ await activateWithKeyboard(confirmation.getByRole('button', { name: 'Delete', exact: true }))
+ await expect(confirmation).toBeHidden()
+})
+
+Then('focus should return to the app API Key creation button', async function (this: DifyWorld) {
+ const { dialog } = getAccessPointDialog(this.getPage(), 'API Key')
+ await expect(
+ dialog.getByRole('button', { name: 'Create new Secret key', exact: true }),
+ ).toBeFocused()
+})
+
+When('I inspect the Web App settings {string}', async function (this: DifyWorld, state: string) {
+ const page = this.getPage()
+ const { dialog } = getAccessPointDialog(page, 'Web App settings')
+ const title = dialog.getByRole('textbox', { name: 'Web App Name', exact: true })
+ await expect(title).toBeVisible()
+ if (state === 'form') {
+ await expect(
+ dialog.getByRole('switch', { name: /^Use web app icon to replace / }),
+ ).toBeVisible()
+ return
+ }
+ if (state === 'validation errors') {
+ const color = dialog.getByRole('textbox', { name: 'Chat color theme', exact: true })
+ const privacy = dialog.getByRole('textbox', { name: 'Privacy Policy', exact: true })
+ await title.fill('')
+ await color.fill('invalid-color')
+ await privacy.fill('invalid-link')
+ await activateWithKeyboard(dialog.getByRole('button', { name: 'Save', exact: true }))
+ await expect(title).toHaveAttribute('aria-invalid', 'true')
+ await expect(title).toHaveAccessibleDescription('Name cannot be empty')
+ await expect(color).toHaveAttribute('aria-invalid', 'true')
+ await expect(color).toHaveAccessibleDescription(/Invalid hex value/)
+ await expect(privacy).toHaveAttribute('aria-invalid', 'true')
+ await expect(privacy).toHaveAccessibleDescription(/Invalid privacy policy link/)
+ await expect(title).toBeFocused()
+ return
+ }
+ if (state === 'language options') {
+ const language = dialog.getByRole('combobox', { name: 'Language', exact: true })
+ await activateWithKeyboard(language)
+ await expectExpandedPopup(page, language, page.getByRole('listbox'))
+ return
+ }
+ if (state === 'icon picker') {
+ await activateWithKeyboard(dialog.getByRole('button', { name: 'Choose icon', exact: true }))
+ await expectDialogFocus(page, page.getByRole('dialog', { name: 'Choose icon', exact: true }))
+ await expect(page.getByRole('dialog')).toHaveCount(1)
+ await expectExpandedPopup(
+ page,
+ page.getByRole('combobox', { name: /^Search emoji/ }),
+ page.getByRole('grid', { name: 'Emoji', exact: true }),
+ )
+ return
+ }
+ throw new Error(`Unknown Web App settings state "${state}".`)
+})
+
+Then(
+ 'the Web App settings {string} should restore focus after popup dismissal',
+ async function (this: DifyWorld, state: string) {
+ const page = this.getPage()
+ const { dialog } = getAccessPointDialog(page, 'Web App settings')
+ if (state === 'language options') {
+ await page.keyboard.press('Escape')
+ await expect(page.getByRole('listbox')).toBeHidden()
+ await expect(dialog.getByRole('combobox', { name: 'Language', exact: true })).toBeFocused()
+ } else if (state === 'icon picker') {
+ await page.keyboard.press('Escape')
+ await expect(page.getByRole('dialog', { name: 'Choose icon', exact: true })).toBeHidden()
+ await expect(dialog.getByRole('button', { name: 'Choose icon', exact: true })).toBeFocused()
+ }
+ },
+)
+
+When('I fill the app access point hidden input form', async function (this: DifyWorld) {
+ const page = this.getPage()
+ const dialog = page.getByRole('dialog')
+ const name = dialog.getByRole('textbox', { name: 'Visitor name', exact: true })
+ await name.fill('Keyboard visitor')
+ const language = dialog.getByRole('combobox', { name: 'Reply language', exact: true })
+ await activateWithKeyboard(language)
+ await activateWithKeyboard(page.getByRole('option', { name: 'French', exact: true }))
+ await expect(language).toBeFocused()
+ await expect(language).toHaveText('French')
+ const details = dialog.getByRole('checkbox', { name: 'Include details', exact: true })
+ await details.focus()
+ await details.press('Space')
+ await expect(details).toBeChecked()
+ await expect(name).toHaveValue('Keyboard visitor')
+})
+
+When('I open the hidden input language options', async function (this: DifyWorld) {
+ const page = this.getPage()
+ const { dialog } = getAccessPointDialog(page, 'Workflow hidden inputs')
+ const language = dialog.getByRole('combobox', { name: 'Reply language', exact: true })
+ await activateWithKeyboard(language)
+ await expectExpandedPopup(page, language, page.getByRole('listbox'))
+ await expect(page.getByRole('option', { name: 'French', exact: true })).toHaveAttribute(
+ 'aria-selected',
+ 'true',
+ )
+})
+
+Then(
+ 'the hidden input language options should dismiss back to the configuration dialog',
+ async function (this: DifyWorld) {
+ const page = this.getPage()
+ const { dialog, trigger } = getAccessPointDialog(page, 'Workflow hidden inputs')
+ await page.keyboard.press('Escape')
+ await expect(page.getByRole('listbox')).toBeHidden()
+ await expect(
+ dialog.getByRole('combobox', { name: 'Reply language', exact: true }),
+ ).toBeFocused()
+ await activateWithKeyboard(dialog.getByRole('button', { name: 'Cancel', exact: true }))
+ await expect(dialog).toBeHidden()
+ await expect(trigger).toBeFocused()
+ },
+)
+
+When('I expand the embedding hidden input fields', async function (this: DifyWorld) {
+ const { dialog } = getAccessPointDialog(this.getPage(), 'Embedding')
+ const disclosure = dialog.getByRole('button', { name: /^Pre-Fill Hidden Fields/ })
+ await activateWithKeyboard(disclosure)
+ await expect(disclosure).toHaveAttribute('aria-expanded', 'true')
+})
+
+When(
+ 'I select the {string} embedding preview',
+ async function (this: DifyWorld, embedding: string) {
+ const { dialog } = getAccessPointDialog(this.getPage(), 'Embedding')
+ const tabNames: Record<string, string> = {
+ iframe: 'To add the chat app any where on your website, add this iframe to your html code.',
+ scripts: 'To add a chat app to the bottom right of your website add this code to your html.',
+ 'Chrome extension': 'Install Dify Chatbot Chrome Extension',
+ }
+ const tabName = tabNames[embedding]
+ if (!tabName) throw new Error(`Unknown embedding option "${embedding}".`)
+ const tab = dialog.getByRole('tab', { name: tabName, exact: true })
+ await activateWithKeyboard(tab)
+ await expect(tab).toHaveAttribute('aria-selected', 'true')
+ },
+)
+
+Then(
+ 'the selected embedding should expose its preview and copy action',
+ async function (this: DifyWorld) {
+ const { dialog } = getAccessPointDialog(this.getPage(), 'Embedding')
+ await expect(dialog.getByRole('textbox', { name: 'Visitor name', exact: true })).toBeVisible()
+ await expect(dialog.getByRole('combobox', { name: 'Reply language', exact: true })).toHaveText(
+ 'English',
+ )
+ await expect(
+ dialog.getByRole('checkbox', { name: 'Include details', exact: true }),
+ ).not.toBeChecked()
+ const panel = dialog.getByRole('tabpanel')
+ await expect(panel).toBeVisible()
+ await expect(panel).toContainText(/https?:\/\//)
+ const copy = panel.getByRole('button', { name: 'Copy', exact: true })
+ await expect(copy).toBeVisible()
+ await copy.focus()
+ await this.getPage().keyboard.press('Tab')
+ const preview = panel.getByRole('region')
+ await expect(preview).toBeFocused()
+ },
+)
+
+Then(
+ 'the configured MCP parameter descriptions should be labelled and populated',
+ async function (this: DifyWorld) {
+ const { dialog } = getAccessPointDialog(this.getPage(), 'MCP description')
+ await expect(dialog.getByRole('textbox', { name: 'Description', exact: true })).toHaveValue(
+ 'E2E access point tool',
+ )
+ await expect(dialog.getByRole('textbox', { name: 'Visitor name', exact: true })).toHaveValue(
+ 'Name of the visitor',
+ )
+ await expect(dialog.getByRole('textbox', { name: 'Reply language', exact: true })).toHaveValue(
+ 'Language for the reply',
+ )
+ await expect(dialog.getByRole('textbox', { name: 'Include details', exact: true })).toHaveValue(
+ 'Whether to include details',
+ )
+ },
+)
diff --git a/e2e/features/step-definitions/agent-v2/access-point-web-app.steps.ts b/e2e/features/step-definitions/agent-v2/access-point-web-app.steps.ts
index 90e7833b1c7..556010ef75f 100644
--- a/e2e/features/step-definitions/agent-v2/access-point-web-app.steps.ts
+++ b/e2e/features/step-definitions/agent-v2/access-point-web-app.steps.ts
@@ -138,7 +138,9 @@ Then('I should see the Agent v2 Embedded configuration dialog', async function (
await expect(dialog).toBeVisible()
await expect(dialog.getByText('Embed on website')).toBeVisible()
- await expect(dialog.getByText(/iframe|script/i)).toBeVisible()
+ const preview = dialog.getByRole('region', { name: /iframe/i })
+ await expect(preview).toBeVisible()
+ await expect(preview).toContainText('<iframe')
})
When('I open Agent v2 Web app customization', async function (this: DifyWorld) {
diff --git a/e2e/support/api/workflows.ts b/e2e/support/api/workflows.ts
index 08fca864a2f..726d1a3e072 100644
--- a/e2e/support/api/workflows.ts
+++ b/e2e/support/api/workflows.ts
@@ -27,6 +27,13 @@ export async function syncMinimalWorkflowDraft(
export async function syncRunnableWorkflowDraft(
client: ConsoleClient,
appId: string,
+ {
+ mode = 'workflow',
+ variables = [],
+ }: {
+ mode?: 'workflow' | 'advanced-chat'
+ variables?: Record<string, unknown>[]
+ } = {},
): Promise<void> {
const body = {
graph: {
@@ -35,18 +42,21 @@ export async function syncRunnableWorkflowDraft(
id: 'start',
type: 'custom',
position: { x: 80, y: 282 },
- data: { id: 'start', type: 'start', title: 'Start', variables: [] },
+ data: { id: 'start', type: 'start', title: 'Start', variables },
},
{
id: 'end',
type: 'custom',
position: { x: 480, y: 282 },
- data: {
- id: 'end',
- type: 'end',
- title: 'End',
- outputs: [{ variable: 'result', value_selector: ['sys', 'workflow_run_id'] }],
- },
+ data:
+ mode === 'advanced-chat'
+ ? { id: 'end', type: 'answer', title: 'Answer', answer: 'E2E response' }
+ : {
+ id: 'end',
+ type: 'end',
+ title: 'End',
+ outputs: [{ variable: 'result', value_selector: ['sys', 'workflow_run_id'] }],
+ },
},
],
edges: [
diff --git a/oxlint-suppressions.json b/oxlint-suppressions.json
index 7e3c911e057..e812444d6d8 100644
--- a/oxlint-suppressions.json
+++ b/oxlint-suppressions.json
@@ -1735,11 +1735,6 @@
"count": 1
}
},
- "web/app/components/tools/mcp/mcp-server-param-item.tsx": {
- "typescript/no-explicit-any": {
- "count": 1
- }
- },
"web/app/components/tools/setting/build-in/config-credentials.tsx": {
"typescript/no-explicit-any": {
"count": 3
diff --git a/web/app/components/app/access-point/__tests__/access-point-url.spec.tsx b/web/app/components/app/access-point/__tests__/access-point-url.spec.tsx
index b4d60da1a05..b0c95d3431c 100644
--- a/web/app/components/app/access-point/__tests__/access-point-url.spec.tsx
+++ b/web/app/components/app/access-point/__tests__/access-point-url.spec.tsx
@@ -64,4 +64,67 @@ describe('AccessPointUrl', () => {
expect(screen.queryByText(endpointProps.unavailableLabel)).not.toBeInTheDocument()
expect(screen.queryByText(endpointProps.value)).not.toBeInTheDocument()
})
+
+ it.each(['loading', 'unavailable'] as const)(
+ 'exposes disabled URL actions in the %s state without activating them',
+ async (state) => {
+ const user = userEvent.setup()
+ const onRegenerate = vi.fn()
+ render(
+ <AccessPointUrl
+ {...endpointProps}
+ enabled={false}
+ loading={state === 'loading'}
+ unavailable={state === 'unavailable'}
+ showOpen
+ showQrCode
+ showRegenerate
+ copyLabel="Copy URL"
+ openLabel="Open"
+ qrCodeLabel="Show QR code"
+ regenerateLabel="Regenerate URL"
+ onRegenerate={onRegenerate}
+ />,
+ )
+
+ for (const name of ['Copy URL', 'Show QR code', 'Regenerate URL', 'Open']) {
+ const action = screen.getByRole('button', { name })
+ expect(action).toBeDisabled()
+ await user.click(action)
+ }
+ expect(onRegenerate).not.toHaveBeenCalled()
+ },
+ )
+
+ it('retains the regenerate action and focus while a request is pending', async () => {
+ const user = userEvent.setup()
+ const onRegenerate = vi.fn()
+ const { rerender } = render(
+ <AccessPointUrl
+ {...endpointProps}
+ enabled
+ showRegenerate
+ regenerateLabel="Regenerate URL"
+ onRegenerate={onRegenerate}
+ />,
+ )
+ const regenerate = screen.getByRole('button', { name: 'Regenerate URL' })
+ await user.click(regenerate)
+
+ rerender(
+ <AccessPointUrl
+ {...endpointProps}
+ enabled
+ showRegenerate
+ regenerateLabel="Regenerate URL"
+ regenerating
+ onRegenerate={onRegenerate}
+ />,
+ )
+
+ expect(regenerate).toHaveFocus()
+ expect(regenerate).toHaveAttribute('aria-disabled', 'true')
+ await user.keyboard('{Enter}')
+ expect(onRegenerate).toHaveBeenCalledTimes(1)
+ })
})
diff --git a/web/app/components/app/access-point/__tests__/environment-tabs.browser.spec.tsx b/web/app/components/app/access-point/__tests__/environment-tabs.browser.spec.tsx
new file mode 100644
index 00000000000..f7d7ee5cbda
--- /dev/null
+++ b/web/app/components/app/access-point/__tests__/environment-tabs.browser.spec.tsx
@@ -0,0 +1,119 @@
+import type { AppEnvironment } from '@dify/contracts/enterprise-app-deploy/types.gen'
+import { EnvironmentStatus } from '@dify/contracts/enterprise-app-deploy/types.gen'
+import { NuqsTestingAdapter } from 'nuqs/adapters/testing'
+import { page, userEvent } from 'vite-plus/test/browser'
+import { render } from 'vitest-browser-react'
+import { consoleQuery } from '@/service/console'
+import { seedAccountProfileQuery } from '@/test/console/account-profile'
+import { QueryClientTestProvider } from '@/test/console/query-provider'
+import { createAppDetailFixture } from '@/test/fixtures/app'
+import { createTestQueryClient } from '@/test/query-client'
+import { AppACLPermission } from '@/utils/permission'
+import AccessPoint from '..'
+
+vi.mock('react-i18next', async () => {
+ const { createReactI18nextMock } = await import('@/test/i18n-mock')
+ return createReactI18nextMock({
+ 'workflow.nodes.common.memories.builtIn': 'Built-in',
+ })
+})
+
+vi.mock('@/context/permission-state', async () => {
+ const { createPermissionStateModuleMock } = await import('@/test/console/state-fixture')
+ return createPermissionStateModuleMock(() => ({
+ userProfile: { id: 'user-1' },
+ workspacePermissionKeys: [],
+ }))
+})
+
+// The page owns the tabs and scrollport; card contents are outside this regression.
+vi.mock('@/app/components/app/access-point/built-in-access-points', () => ({
+ BuiltInAccessPoints: () => null,
+}))
+vi.mock('@/app/components/app/access-point/deployed-environment-access-points', () => ({
+ DeployedEnvironmentAccessPoints: () => null,
+}))
+
+async function renderAccessPoint(names = ['test-1']) {
+ const queryClient = createTestQueryClient()
+ seedAccountProfileQuery(queryClient)
+ queryClient.setQueryData(
+ consoleQuery.apps.byAppId.get.queryKey({ input: { params: { app_id: 'app-1' } } }),
+ createAppDetailFixture({
+ id: 'app-1',
+ mode: 'workflow',
+ maintainer: 'user-2',
+ permission_keys: [AppACLPermission.AccessPointView],
+ }),
+ )
+ const environments: AppEnvironment[] = names.map((name, index) => ({
+ id: `environment-${index}`,
+ display_name: name,
+ description: '',
+ status: EnvironmentStatus.ENVIRONMENT_STATUS_READY,
+ in_use: true,
+ }))
+ queryClient.setQueryData(
+ consoleQuery.enterprise.appDeploy.deploymentService.listAppEnvironments.queryKey({
+ input: { params: { app_id: 'app-1' } },
+ }),
+ { data: environments },
+ )
+ const onUrlUpdate = vi.fn()
+ const screen = await render(
+ <QueryClientTestProvider queryClient={queryClient}>
+ <NuqsTestingAdapter onUrlUpdate={onUrlUpdate}>
+ <div style={{ width: 320, height: 480 }}>
+ <AccessPoint appId="app-1" />
+ </div>
+ </NuqsTestingAdapter>
+ </QueryClientTestProvider>,
+ )
+ return { screen, onUrlUpdate }
+}
+
+it('moves focus and activates the focused environment only with Enter', async () => {
+ const { screen, onUrlUpdate } = await renderAccessPoint()
+ const builtIn = screen.getByRole('tab', { name: 'Built-in' })
+ const deployed = screen.getByRole('tab', { name: 'test-1' })
+ await userEvent.tab()
+ await expect.element(builtIn).toHaveFocus()
+
+ await userEvent.keyboard('{ArrowRight}')
+ await expect.element(deployed).toHaveFocus()
+ await expect.element(builtIn).toHaveAttribute('aria-selected', 'true')
+ await expect.element(deployed).toHaveAttribute('aria-selected', 'false')
+ expect(onUrlUpdate).not.toHaveBeenCalled()
+
+ await userEvent.keyboard('{ArrowLeft}')
+ await expect.element(builtIn).toHaveFocus()
+ await userEvent.keyboard('{ArrowRight}')
+ await expect.element(deployed).toHaveFocus()
+ expect(onUrlUpdate).not.toHaveBeenCalled()
+
+ await userEvent.keyboard('{Enter}')
+ await expect.element(deployed).toHaveAttribute('aria-selected', 'true')
+ expect(onUrlUpdate).toHaveBeenCalledWith(
+ expect.objectContaining({ queryString: '?environment=environment-0' }),
+ )
+})
+
+it('focuses the first and last tabs with Home and End without activating them', async () => {
+ await page.viewport(320, 640)
+ const { screen, onUrlUpdate } = await renderAccessPoint([
+ 'Staging',
+ 'Canary',
+ 'Production with long name',
+ ])
+ await userEvent.tab()
+ await userEvent.keyboard('{End}')
+ const lastTab = screen.getByRole('tab', { name: 'Production with long name' })
+ await expect.element(lastTab).toHaveFocus()
+ await expect.element(lastTab).toHaveAttribute('aria-selected', 'false')
+ expect(onUrlUpdate).not.toHaveBeenCalled()
+
+ await userEvent.keyboard('{Home}')
+ const firstTab = screen.getByRole('tab', { name: 'Built-in' })
+ await expect.element(firstTab).toHaveFocus()
+ expect(onUrlUpdate).not.toHaveBeenCalled()
+})
diff --git a/web/app/components/app/access-point/__tests__/index.spec.tsx b/web/app/components/app/access-point/__tests__/index.spec.tsx
index 5ea1a003da9..feefc4ecb36 100644
--- a/web/app/components/app/access-point/__tests__/index.spec.tsx
+++ b/web/app/components/app/access-point/__tests__/index.spec.tsx
@@ -166,6 +166,33 @@ describe('AccessPoint', () => {
)
})
+ it('associates the selected environment tab with its content when navigating by keyboard', async () => {
+ const user = userEvent.setup()
+ const { onUrlUpdate } = renderAccessPoint()
+ const builtInTab = screen.getByRole('tab', { name: 'Built-in' })
+ const builtInPanel = screen.getByRole('tabpanel', { name: 'Built-in' })
+
+ expect(builtInTab).toHaveAttribute('aria-controls', builtInPanel.id)
+ await user.tab()
+ expect(builtInTab).toHaveFocus()
+ await user.keyboard('{ArrowRight}')
+
+ const stagingTab = screen.getByRole('tab', { name: 'Staging' })
+ expect(stagingTab).toHaveFocus()
+ expect(builtInTab).toHaveAttribute('aria-selected', 'true')
+ expect(stagingTab).toHaveAttribute('aria-selected', 'false')
+ expect(onUrlUpdate).not.toHaveBeenCalled()
+ await user.keyboard('{Enter}')
+
+ const stagingPanel = await screen.findByRole('tabpanel', { name: 'Staging' })
+ expect(stagingTab).toHaveFocus()
+ expect(stagingTab).toHaveAttribute('aria-selected', 'true')
+ expect(stagingTab).toHaveAttribute('aria-controls', stagingPanel.id)
+ expect(onUrlUpdate).toHaveBeenCalledWith(
+ expect.objectContaining({ queryString: '?environment=staging' }),
+ )
+ })
+
it('selects the target environment and highlights its access point from the URL', () => {
renderAccessPoint({
searchParams: '?environment=canary&accessPoint=serviceApi',
@@ -248,6 +275,8 @@ describe('AccessPoint', () => {
renderAccessPoint()
expect(screen.queryByRole('tab')).not.toBeInTheDocument()
+ expect(screen.queryByRole('tabpanel')).not.toBeInTheDocument()
+ expect(screen.getByRole('region', { name: 'common.appMenus.accessPoint' })).toBeInTheDocument()
expect(accessPointMocks.builtIn).toHaveBeenCalledTimes(1)
expect(accessPointMocks.deployed).not.toHaveBeenCalled()
})
diff --git a/web/app/components/app/access-point/built-in-access-points/trigger-card.tsx b/web/app/components/app/access-point/built-in-access-points/trigger-card.tsx
index d2093a71091..2edd9be663a 100644
--- a/web/app/components/app/access-point/built-in-access-points/trigger-card.tsx
+++ b/web/app/components/app/access-point/built-in-access-points/trigger-card.tsx
@@ -120,7 +120,7 @@ function TriggerAccessPointItem({
</span>
<span
className={`flex shrink-0 items-center gap-1 system-xs-semibold-uppercase ${
- enabled ? 'text-text-success' : 'text-text-tertiary'
+ enabled ? 'text-text-secondary' : 'text-text-tertiary'
}`}
>
<StatusDot size="small" status={enabled ? 'success' : 'disabled'} />
@@ -209,7 +209,7 @@ export function TriggerAccessPointCard({
href={docLink('/use-dify/nodes/trigger/overview')}
target="_blank"
rel="noopener noreferrer"
- className="text-text-accent hover:underline"
+ className="text-text-accent underline"
>
{t(($) => $['overview.triggerInfo.learnAboutTriggers'], {
ns: 'appOverview',
diff --git a/web/app/components/app/access-point/index.tsx b/web/app/components/app/access-point/index.tsx
index c20ab19dec0..f4361a25502 100644
--- a/web/app/components/app/access-point/index.tsx
+++ b/web/app/components/app/access-point/index.tsx
@@ -7,7 +7,7 @@ import {
ScrollAreaThumb,
ScrollAreaViewport,
} from '@langgenius/dify-ui/scroll-area'
-import { Tabs, TabsList, TabsTab } from '@langgenius/dify-ui/tabs'
+import { Tabs, TabsList, TabsPanel, TabsTab } from '@langgenius/dify-ui/tabs'
import { useSuspenseQueries } from '@tanstack/react-query'
import { useAtomValue } from 'jotai'
import { parseAsString, parseAsStringLiteral, useQueryStates } from 'nuqs'
@@ -66,7 +66,11 @@ function AccessPointContent({
environment === selectedEnvironment ? highlightedAccessPoint : null
return (
- <div className="flex h-full min-h-0 flex-col bg-components-panel-bg">
+ <Tabs
+ value={selectedEnvironment}
+ onValueChange={(environment) => void setQueryStates({ accessPoint: null, environment })}
+ className="flex h-full min-h-0 flex-col bg-components-panel-bg"
+ >
<header className="flex shrink-0 flex-col gap-3 px-6 pt-3 pb-2">
<div className="flex flex-col gap-0.5">
<div className="flex h-6 items-center">
@@ -79,42 +83,41 @@ function AccessPointContent({
</p>
</div>
{showEnvironmentTabs && (
- <Tabs
- value={selectedEnvironment}
- onValueChange={(environment) => void setQueryStates({ accessPoint: null, environment })}
+ <TabsList
+ activateOnFocus={false}
+ aria-label={t(($) => $['studio.environments'], { ns: 'deployments' })}
+ className="relative -m-0.5 scroll-p-0.5 gap-1 overflow-x-auto p-0.5"
>
- <div className="overflow-x-auto">
- <TabsList
- aria-label={t(($) => $['studio.environments'], { ns: 'deployments' })}
- className="min-w-max gap-1"
+ <TabsTab
+ value={BUILT_IN_ENVIRONMENT_ID}
+ className="h-8 shrink-0 rounded-lg border-b-0 px-2.5 py-0 system-sm-medium data-active:border-transparent data-active:bg-state-base-active data-active:system-sm-semibold data-active:text-text-secondary"
+ >
+ {t(($) => $['nodes.common.memories.builtIn'], { ns: 'workflow' })}
+ </TabsTab>
+ {environments.map((environment) => (
+ <TabsTab
+ key={environment.id}
+ value={environment.id}
+ className="h-8 shrink-0 rounded-lg border-b-0 px-2.5 py-0 system-sm-medium data-active:border-transparent data-active:bg-state-base-active data-active:system-sm-semibold data-active:text-text-secondary"
>
- <TabsTab
- value={BUILT_IN_ENVIRONMENT_ID}
- className="h-8 rounded-lg border-b-0 px-2.5 py-0 system-sm-medium data-active:border-transparent data-active:bg-state-base-active data-active:system-sm-semibold data-active:text-text-secondary"
- >
- {t(($) => $['nodes.common.memories.builtIn'], { ns: 'workflow' })}
- </TabsTab>
- {environments.map((environment) => (
- <TabsTab
- key={environment.id}
- value={environment.id}
- className="h-8 rounded-lg border-b-0 px-2.5 py-0 system-sm-medium data-active:border-transparent data-active:bg-state-base-active data-active:system-sm-semibold data-active:text-text-secondary"
- >
- {environment.display_name}
- </TabsTab>
- ))}
- </TabsList>
- </div>
- </Tabs>
+ {environment.display_name}
+ </TabsTab>
+ ))}
+ </TabsList>
)}
</header>
<ScrollArea className="relative min-h-0 flex-1 overflow-hidden">
<ScrollAreaViewport
- aria-labelledby="access-point-title"
+ render={
+ showEnvironmentTabs ? (
+ // ScrollArea paints the focus indicator above the viewport contents.
+ <TabsPanel value={selectedEnvironment} className="focus-visible:inset-ring-0" />
+ ) : undefined
+ }
+ {...(!showEnvironmentTabs && { 'aria-labelledby': 'access-point-title', role: 'region' })}
className="overscroll-contain"
data-environment={selectedEnvironment}
- role="region"
style={{ overflowX: 'hidden' }}
>
<ScrollAreaContent
@@ -143,7 +146,7 @@ function AccessPointContent({
<ScrollAreaThumb />
</ScrollAreaScrollbar>
</ScrollArea>
- </div>
+ </Tabs>
)
}
diff --git a/web/app/components/app/access-point/shared/web-app-access-control.tsx b/web/app/components/app/access-point/shared/web-app-access-control.tsx
index 31c8392023a..6b6796818d9 100644
--- a/web/app/components/app/access-point/shared/web-app-access-control.tsx
+++ b/web/app/components/app/access-point/shared/web-app-access-control.tsx
@@ -45,14 +45,16 @@ export function WebAppAccessControlEntry({
<div className="-mt-1 px-4 pb-3">
<button
type="button"
- className="flex h-9 w-full cursor-pointer items-center gap-x-0.5 rounded-lg border-[0.5px] border-divider-subtle bg-background-section py-1 pr-2 pl-2.5 text-left outline-hidden hover:bg-state-base-hover-alt focus-visible:ring-2 focus-visible:ring-state-accent-solid disabled:cursor-not-allowed disabled:hover:bg-background-section"
+ className="flex min-h-9 w-full cursor-pointer items-center gap-x-0.5 rounded-lg border-[0.5px] border-divider-subtle bg-background-section py-1 pr-2 pl-2.5 text-left outline-hidden hover:bg-state-base-hover-alt focus-visible:ring-2 focus-visible:ring-state-accent-solid disabled:cursor-not-allowed disabled:hover:bg-background-section"
disabled={disabled}
onClick={onClick}
>
<div className="flex grow items-center gap-x-1.5 overflow-hidden pr-1">
<span aria-hidden className={`${accessIcon} size-4 shrink-0 text-text-secondary`} />
- <div className="grow truncate">
- <span className="system-sm-regular text-text-secondary">{accessLabel}</span>
+ <div className="min-w-0 grow">
+ <span className="system-sm-regular wrap-break-word text-text-secondary">
+ {accessLabel}
+ </span>
</div>
</div>
{!accessConfigured && (
diff --git a/web/app/components/app/overview/embedded/__tests__/embedded-dialog.browser.spec.tsx b/web/app/components/app/overview/embedded/__tests__/embedded-dialog.browser.spec.tsx
index 882ce7dfffd..c4dbf2c3df6 100644
--- a/web/app/components/app/overview/embedded/__tests__/embedded-dialog.browser.spec.tsx
+++ b/web/app/components/app/overview/embedded/__tests__/embedded-dialog.browser.spec.tsx
@@ -1,11 +1,18 @@
import { Dialog, DialogTrigger } from '@langgenius/dify-ui/dialog'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
+import { page, userEvent } from 'vite-plus/test/browser'
import { render } from 'vitest-browser-react'
import { InputVarType } from '@/app/components/workflow/types'
+import appOverview from '@/i18n/locales/en-US/app-overview.json'
import { seedAccountProfileQuery } from '@/test/console/account-profile'
import { EmbeddedDialogContent } from '../index'
vi.mock('copy-to-clipboard', () => ({ default: vi.fn() }))
+vi.mock('react-i18next', async () => {
+ const { createReactI18nextMock } = await import('@/test/i18n-mock')
+ const { default: translations } = await import('@/i18n/locales/en-US/app-overview.json')
+ return createReactI18nextMock(translations)
+})
vi.mock('@/service/base', () => ({
get: vi.fn(),
post: vi.fn(),
@@ -29,7 +36,7 @@ vi.mock('@/service/base', () => ({
buildWebAppSigninUrlWithRedirect: vi.fn(),
}))
-const prefix = 'appOverview.overview.appInfo.embedded'
+const prefix = 'overview.appInfo.embedded'
const triggerLabel = 'deployments.studio.accessPoint.embedIntoSite'
const hiddenInputs = [
{
@@ -65,63 +72,69 @@ beforeEach(() => {
vi.clearAllMocks()
})
-afterEach(() => vi.unstubAllGlobals())
+it('reaches the copy action and code preview by keyboard at 320px', async () => {
+ await page.viewport(320, 900)
+ const queryClient = createClient()
+ seedAccountProfileQuery(queryClient)
+ const screen = await render(dialogView(queryClient))
+ await screen.getByRole('button', { name: triggerLabel }).click()
+ const dialog = screen.getByRole('dialog', { name: appOverview[`${prefix}.title`] })
+ await dialog
+ .getByRole('button', {
+ name: new RegExp(appOverview[`${prefix}.hiddenInputs.title`]),
+ })
+ .click()
+ const input = dialog.getByRole('textbox', { name: 'Secret' })
+ await input.fill('draft secret')
+ const panel = dialog.getByRole('tabpanel', { name: appOverview[`${prefix}.iframe`] })
+ const copyButton = panel.getByRole('button', { name: appOverview[`${prefix}.copy`], exact: true })
+ const preview = panel.getByRole('region', { name: appOverview[`${prefix}.iframe`] })
+ await expect.poll(() => preview.element().textContent).toContain('embed-token')
-it('preserves the hidden input, selected tab and copied preview through the exit animation', async () => {
- vi.stubGlobal('BASE_UI_ANIMATIONS_DISABLED', false)
+ await userEvent.tab()
+ await expect.element(dialog.getByRole('tab', { selected: true })).toHaveFocus()
+ await userEvent.tab()
+ await expect.element(copyButton).toHaveFocus()
+
+ await userEvent.tab()
+ await expect.element(preview).toHaveFocus()
+
+ await copyButton.click()
+ await expect
+ .element(
+ panel.getByRole('button', {
+ name: appOverview[`${prefix}.copied`],
+ exact: true,
+ }),
+ )
+ .toBeVisible()
+ queryClient.clear()
+})
+
+it('edits hidden inputs, switches previews, copies and restores focus on dismissal', async () => {
const queryClient = createClient()
seedAccountProfileQuery(queryClient)
const screen = await render(dialogView(queryClient))
const trigger = screen.getByRole('button', { name: triggerLabel })
await trigger.click()
- const dialog = screen.getByRole('dialog', { name: `${prefix}.title` })
+ const dialog = screen.getByRole('dialog', { name: appOverview[`${prefix}.title`] })
const disclosure = dialog.getByRole('button', {
- name: new RegExp(`${prefix}.hiddenInputs.title`),
+ name: new RegExp(appOverview[`${prefix}.hiddenInputs.title`]),
})
await expect.element(disclosure).toHaveAttribute('aria-expanded', 'false')
await disclosure.click()
const input = dialog.getByRole('textbox', { name: 'Secret' })
await input.fill('draft secret')
- const scriptsTab = dialog.getByRole('tab', { name: `${prefix}.scripts` })
+ const scriptsTab = dialog.getByRole('tab', { name: appOverview[`${prefix}.scripts`] })
await scriptsTab.click()
- const panel = dialog.getByRole('tabpanel', { name: `${prefix}.scripts` })
+ const panel = dialog.getByRole('tabpanel', { name: appOverview[`${prefix}.scripts`] })
await expect.poll(() => panel.element().textContent).toContain('draft secret')
- await panel.getByRole('button', { name: `${prefix}.copy`, exact: true }).click()
- const copied = panel.getByRole('button', { name: `${prefix}.copied`, exact: true })
+ await panel.getByRole('button', { name: appOverview[`${prefix}.copy`], exact: true }).click()
+ const copied = panel.getByRole('button', { name: appOverview[`${prefix}.copied`], exact: true })
await expect.element(copied).toBeVisible()
- const popup = dialog.element()
- const draftInput = input.element() as HTMLInputElement
- const activeTab = scriptsTab.element()
- const preview = panel.element()
- const copyButton = copied.element()
- await expect.poll(() => getComputedStyle(popup).opacity).toBe('1')
- const exitFrame = new Promise<{
- draft: string
- selected: string | null
- preview: string | null
- copied: string | null
- opacity: number
- }>((resolve) => {
- const onTransition = (event: Event) => {
- if (event.target !== popup || (event as TransitionEvent).propertyName !== 'opacity') return
- popup.removeEventListener('transitionrun', onTransition)
- resolve({
- draft: draftInput.value,
- selected: activeTab.getAttribute('aria-selected'),
- preview: preview.textContent,
- copied: copyButton.getAttribute('aria-label'),
- opacity: Number(getComputedStyle(popup).opacity),
- })
- }
- popup.addEventListener('transitionrun', onTransition)
- })
- await dialog.getByRole('button', { name: 'common.operation.close' }).click()
- const closing = await exitFrame
- expect(closing.opacity).toBeGreaterThan(0)
- expect(closing.draft).toBe('draft secret')
- expect(closing.selected).toBe('true')
- expect(closing.preview).toContain('draft secret')
- expect(closing.copied).toBe(`${prefix}.copied`)
+ await userEvent.keyboard('{Escape}')
await expect.element(dialog).not.toBeInTheDocument()
+ await expect.element(trigger).toHaveFocus()
+ queryClient.clear()
})
diff --git a/web/app/components/app/overview/embedded/index.tsx b/web/app/components/app/overview/embedded/index.tsx
index b2b25c24293..ec76533425c 100644
--- a/web/app/components/app/overview/embedded/index.tsx
+++ b/web/app/components/app/overview/embedded/index.tsx
@@ -16,11 +16,17 @@ import {
DialogTitle,
} from '@langgenius/dify-ui/dialog'
import { IconButton } from '@langgenius/dify-ui/icon-button'
+import {
+ ScrollArea,
+ ScrollAreaScrollbar,
+ ScrollAreaThumb,
+ ScrollAreaViewport,
+} from '@langgenius/dify-ui/scroll-area'
import { Tabs, TabsList, TabsPanel, TabsTab } from '@langgenius/dify-ui/tabs'
import { Tooltip, TooltipContent, TooltipTrigger } from '@langgenius/dify-ui/tooltip'
import { useSuspenseQuery } from '@tanstack/react-query'
import copy from 'copy-to-clipboard'
-import { Suspense, use, useMemo, useRef, useState } from 'react'
+import { Suspense, use, useId, useMemo, useRef, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { createTheme } from '@/app/components/base/chat/embedded-chatbot/theme/theme'
import { InputVarType } from '@/app/components/workflow/types'
@@ -130,6 +136,7 @@ const EmbeddedContent = ({
() => createWorkflowLaunchInitialValues(supportedHiddenInputs),
[supportedHiddenInputs],
)
+ const previewLabelId = useId()
const [option, setOption] = useState<Option>('iframe')
const [copiedOption, setCopiedOption] = useState<Option | null>(null)
const [hiddenInputValues, setHiddenInputValues] = useState<
@@ -303,13 +310,17 @@ const EmbeddedContent = ({
)}
>
<div className="inline-flex items-center justify-start gap-2 self-stretch rounded-t-lg bg-background-section-burn py-1 pr-1 pl-3">
- <div className="shrink-0 grow system-sm-medium text-text-secondary">
+ <div
+ id={`${previewLabelId}-${v}`}
+ className="min-w-0 flex-1 system-sm-medium wrap-break-word text-text-secondary"
+ >
{t(($) => $[`${prefixEmbedded}.${v}`], { ns: 'appOverview' })}
</div>
<Tooltip>
<TooltipTrigger
render={
<IconButton
+ className="shrink-0"
aria-label={
(copiedOption === v
? t(($) => $[`${prefixEmbedded}.copied`], { ns: 'appOverview' })
@@ -332,23 +343,36 @@ const EmbeddedContent = ({
</TooltipContent>
</Tooltip>
</div>
- <div className="flex max-h-[clamp(180px,calc(100dvh-320px),360px)] w-full items-start justify-start gap-2 overflow-auto p-3">
- <div className="shrink grow basis-0 font-mono text-[13px] leading-tight text-text-secondary">
- <pre className="select-text">
- {v === 'scripts' ? (
- scriptsContent
- ) : (
- <Suspense fallback={previewFallback}>
- <AsyncEmbeddedOptionContent
- option={v}
- iframeUrlPromise={previewIframeUrlPromise}
- latestResolvedIframeUrlRef={latestResolvedIframeUrlRef}
- />
- </Suspense>
- )}
- </pre>
- </div>
- </div>
+ <ScrollArea className="relative w-full rounded-b-lg">
+ <ScrollAreaViewport
+ role="region"
+ aria-labelledby={`${previewLabelId}-${v}`}
+ tabIndex={0}
+ className="flex max-h-[clamp(180px,calc(100dvh-320px),360px)] items-start justify-start gap-2 p-3"
+ >
+ <div className="shrink grow basis-0 font-mono text-[13px] leading-tight text-text-secondary">
+ <pre className="select-text">
+ {v === 'scripts' ? (
+ scriptsContent
+ ) : (
+ <Suspense fallback={previewFallback}>
+ <AsyncEmbeddedOptionContent
+ option={v}
+ iframeUrlPromise={previewIframeUrlPromise}
+ latestResolvedIframeUrlRef={latestResolvedIframeUrlRef}
+ />
+ </Suspense>
+ )}
+ </pre>
+ </div>
+ </ScrollAreaViewport>
+ <ScrollAreaScrollbar orientation="vertical" className="right-0">
+ <ScrollAreaThumb />
+ </ScrollAreaScrollbar>
+ <ScrollAreaScrollbar orientation="horizontal" className="bottom-0">
+ <ScrollAreaThumb />
+ </ScrollAreaScrollbar>
+ </ScrollArea>
</div>
</TabsPanel>
)
diff --git a/web/app/components/app/overview/settings/__tests__/settings-dialog.browser.spec.tsx b/web/app/components/app/overview/settings/__tests__/settings-dialog.browser.spec.tsx
index 3ac8f14d807..6b5f5ed8eba 100644
--- a/web/app/components/app/overview/settings/__tests__/settings-dialog.browser.spec.tsx
+++ b/web/app/components/app/overview/settings/__tests__/settings-dialog.browser.spec.tsx
@@ -1,8 +1,11 @@
import type { AppDetailWithSite } from '@dify/contracts/api/console/apps/types.gen'
import { QueryClient, useQuery } from '@tanstack/react-query'
+import { createInstance } from 'i18next'
import { NuqsTestingAdapter } from 'nuqs/adapters/testing'
+import { I18nextProvider } from 'react-i18next'
import { userEvent } from 'vite-plus/test/browser'
import { render } from 'vitest-browser-react'
+import appOverview from '@/i18n/locales/en-US/app-overview.json'
import { consoleQuery } from '@/service/console'
import { seedFeatures, seedSystemFeatures } from '@/test/console/query-data'
import { QueryClientTestProvider } from '@/test/console/query-provider'
@@ -13,6 +16,12 @@ const saveSite = vi.fn()
vi.mock('@/next/navigation', () => ({ useParams: () => ({}) }))
+vi.mock('react-i18next', async (importOriginal) => {
+ const actual = await importOriginal<typeof import('react-i18next')>()
+ const { createReactI18nextMock } = await import('@/test/i18n-mock')
+ return { ...actual, ...createReactI18nextMock(), Trans: actual.Trans }
+})
+
const settingsTitle = 'appOverview.overview.appInfo.settings.title'
const titleLabel = 'appOverview.overview.appInfo.settings.webName'
const triggerLabel = 'navigation.settings.settings'
@@ -49,6 +58,11 @@ function SettingsOwner() {
}
async function renderSettings() {
+ const i18n = createInstance()
+ await i18n.init({
+ lng: 'en-US',
+ resources: { 'en-US': { appOverview } },
+ })
const client = new QueryClient({
defaultOptions: { queries: { staleTime: Infinity, retry: false } },
})
@@ -57,20 +71,27 @@ async function renderSettings() {
seedFeatures(client, { webapp_copyright_enabled: true })
const screen = await render(
<QueryClientTestProvider queryClient={client}>
- <NuqsTestingAdapter>
- <SettingsOwner />
- </NuqsTestingAdapter>
+ <I18nextProvider i18n={i18n}>
+ <NuqsTestingAdapter>
+ <SettingsOwner />
+ </NuqsTestingAdapter>
+ </I18nextProvider>
</QueryClientTestProvider>,
)
return { screen, client }
}
-afterEach(() => {
- vi.unstubAllGlobals()
+it('links the privacy policy to its destination', async () => {
+ const { screen, client } = await renderSettings()
+ await screen.getByRole('button', { name: triggerLabel }).click()
+ const dialog = screen.getByRole('dialog', { name: settingsTitle })
+ const link = dialog.getByRole('link', { name: 'Privacy Policy', exact: true })
+
+ await expect.element(link).toHaveAttribute('href', 'https://dify.ai/privacy')
+ client.clear()
})
-it('keeps the draft through the exit animation', async () => {
- vi.stubGlobal('BASE_UI_ANIMATIONS_DISABLED', false)
+it('cancels a draft without saving and restores trigger focus', async () => {
const { screen, client } = await renderSettings()
const trigger = screen.getByRole('button', { name: triggerLabel })
await userEvent.tab()
@@ -79,22 +100,9 @@ it('keeps the draft through the exit animation', async () => {
const dialog = screen.getByRole('dialog', { name: settingsTitle })
const title = dialog.getByRole('textbox', { name: titleLabel })
await title.fill('Cancelled draft')
- const popup = dialog.element()
- const input = title.element() as HTMLInputElement
- await expect.poll(() => getComputedStyle(popup).opacity).toBe('1')
- const exitFrame = new Promise<{ value: string; opacity: number }>((resolve) => {
- const onTransition = (event: Event) => {
- if (event.target !== popup || (event as TransitionEvent).propertyName !== 'opacity') return
- popup.removeEventListener('transitionrun', onTransition)
- resolve({ value: input.value, opacity: Number(getComputedStyle(popup).opacity) })
- }
- popup.addEventListener('transitionrun', onTransition)
- })
await dialog.getByRole('button', { name: 'common.operation.cancel' }).click()
- const closing = await exitFrame
- expect(closing.value).toBe('Cancelled draft')
- expect(closing.opacity).toBeGreaterThan(0)
await expect.element(dialog).not.toBeInTheDocument()
+ await expect.element(trigger).toHaveFocus()
expect(saveSite).not.toHaveBeenCalled()
client.clear()
})
diff --git a/web/app/components/app/overview/settings/index.tsx b/web/app/components/app/overview/settings/index.tsx
index 8d4c629d9b7..949d07e9c3b 100644
--- a/web/app/components/app/overview/settings/index.tsx
+++ b/web/app/components/app/overview/settings/index.tsx
@@ -585,7 +585,7 @@ function SettingsForm({
href="https://dify.ai/privacy"
target="_blank"
rel="noopener noreferrer"
- className="text-text-accent"
+ className="text-text-accent underline"
/>
),
}}
diff --git a/web/app/components/base/access-point/card.tsx b/web/app/components/base/access-point/card.tsx
index aaf5e13277b..af23d6f57fc 100644
--- a/web/app/components/base/access-point/card.tsx
+++ b/web/app/components/base/access-point/card.tsx
@@ -77,7 +77,7 @@ export function AccessPointCard({
className,
)}
>
- <header className="flex min-h-14 shrink-0 items-center gap-2.5 py-2 pr-5 pl-2">
+ <header className="flex min-h-14 shrink-0 flex-wrap items-center gap-2.5 py-2 pr-5 pl-2">
{typeof icon === 'string' ? (
<span className="flex size-10 shrink-0 items-center justify-center rounded-[10px] border-[0.5px] border-divider-regular bg-components-panel-on-panel-item-bg text-text-secondary">
<span aria-hidden className={cn(icon, 'size-5')} />
@@ -85,10 +85,10 @@ export function AccessPointCard({
) : (
icon
)}
- <span className="min-w-0 flex-1">
+ <div className="min-w-28 flex-1">
<Heading
id={titleId}
- className="truncate system-md-semibold text-text-primary"
+ className="system-md-semibold wrap-break-word text-text-primary"
title={title}
>
{title}
@@ -96,14 +96,14 @@ export function AccessPointCard({
<span className="block truncate system-xs-regular text-text-tertiary" title={description}>
{description}
</span>
- </span>
+ </div>
{showStatus && (
- <>
+ <div className="ml-auto flex shrink-0 items-center gap-2.5">
<span
aria-live="polite"
className={cn(
'flex shrink-0 items-center gap-1 system-xs-semibold-uppercase',
- status === 'inService' ? 'text-text-success' : 'text-text-tertiary',
+ status === 'inService' ? 'text-text-secondary' : 'text-text-tertiary',
)}
>
{isLoading ? (
@@ -122,7 +122,7 @@ export function AccessPointCard({
) : (
switchControl
))}
- </>
+ </div>
)}
</header>
@@ -160,20 +160,20 @@ export function AccessPointEndpoint({
return (
<div aria-busy={loading || undefined} className="flex flex-col gap-1 px-4 py-3">
<div className="flex h-6 items-center system-xs-medium text-text-secondary">{label}</div>
- <div className="flex h-9 min-w-0 items-center gap-0.5 rounded-lg border-[0.5px] border-divider-subtle bg-components-input-bg-normal py-1 pr-1 pl-2">
+ <div className="flex min-h-9 min-w-0 flex-wrap items-center gap-0.5 rounded-lg border-[0.5px] border-divider-subtle bg-components-input-bg-normal py-1 pr-1 pl-2">
{unavailable && !loading && (
<span className="shrink-0 rounded-[5px] border border-divider-deep px-1 py-0.5 system-2xs-medium-uppercase text-text-tertiary">
{unavailableLabel}
</span>
)}
- <div className="flex min-w-0 flex-1 items-center px-1">
+ <div className="flex min-w-20 flex-1 items-center px-1">
{loading ? (
<span className="h-2 w-[42%] animate-pulse rounded-full bg-text-quaternary opacity-20 motion-reduce:animate-none" />
) : (
<span
className={cn(
'truncate system-sm-regular text-text-secondary',
- (dimmed || unavailable) && 'text-text-quaternary',
+ (dimmed || unavailable) && 'text-text-tertiary',
)}
translate="no"
>
@@ -181,7 +181,7 @@ export function AccessPointEndpoint({
</span>
)}
</div>
- <div className="flex shrink-0 items-center gap-0.5">{actions}</div>
+ <div className="ml-auto flex shrink-0 items-center gap-0.5">{actions}</div>
</div>
</div>
)
diff --git a/web/app/components/base/access-point/url.tsx b/web/app/components/base/access-point/url.tsx
index 8b5467a6b7c..3ed6445cc7f 100644
--- a/web/app/components/base/access-point/url.tsx
+++ b/web/app/components/base/access-point/url.tsx
@@ -60,7 +60,10 @@ export function AccessPointUrl({
unavailableLabel,
value,
}: AccessPointUrlProps) {
- const { t } = useTranslation(['common'])
+ const { t } = useTranslation(['common', 'appOverview'])
+ const copyActionLabel = copyLabel || t(($) => $['operation.copy'])
+ const qrCodeActionLabel =
+ qrCodeLabel || t(($) => $['overview.appInfo.qrcode.title'], { ns: 'appOverview' })
const regenerateActionLabel = regenerateLabel || t(($) => $['operation.regenerate'])
const detailsAvailable = !loading && !unavailable
const disabledOpenButton = (
@@ -86,26 +89,23 @@ export function AccessPointUrl({
const disabledActions = (
<div className="flex items-center gap-0.5">
- <div className="flex cursor-not-allowed items-center justify-center p-0.5">
- <span aria-hidden className="i-ri-file-copy-line size-4 text-text-disabled" />
- </div>
+ <IconButton aria-label={copyActionLabel} disabled>
+ <span aria-hidden className="i-ri-file-copy-line size-4" />
+ </IconButton>
{showQrCode && (
- <div className="flex cursor-not-allowed items-center justify-center p-0.5">
- <span aria-hidden className="i-ri-qr-code-line size-4 text-text-disabled" />
- </div>
+ <IconButton aria-label={qrCodeActionLabel} disabled>
+ <span aria-hidden className="i-ri-qr-code-line size-4" />
+ </IconButton>
)}
{showRegenerate && (
- <div className="flex cursor-not-allowed items-center justify-center p-0.5">
- <span aria-hidden className="i-ri-loop-left-line size-4 text-text-disabled" />
- </div>
+ <IconButton aria-label={regenerateActionLabel} disabled>
+ <span aria-hidden className="i-ri-loop-left-line size-4" />
+ </IconButton>
)}
{showOpen && (
<>
<span className="mx-1 h-3.5 w-px bg-divider-subtle" />
- <div className="flex h-6 cursor-not-allowed items-center gap-1 rounded-md border-[0.5px] border-components-button-secondary-border-disabled px-1.5 system-sm-medium text-components-button-secondary-text-disabled backdrop-blur-xs">
- <span aria-hidden className="i-ri-external-link-line size-3.5" />
- {openLabel}
- </div>
+ {disabledOpenAction}
</>
)}
</div>
@@ -114,9 +114,9 @@ export function AccessPointUrl({
const availableActions = (
<div className="flex items-center gap-0.5">
{copyDisabled ? (
- <div className="flex cursor-not-allowed items-center justify-center p-0.5">
- <span aria-hidden className="i-ri-file-copy-line size-4 text-text-disabled" />
- </div>
+ <IconButton aria-label={copyActionLabel} disabled>
+ <span aria-hidden className="i-ri-file-copy-line size-4" />
+ </IconButton>
) : (
<CopyFeedback
content={value}
@@ -127,9 +127,9 @@ export function AccessPointUrl({
)}
{showQrCode &&
(copyDisabled ? (
- <div className="flex cursor-not-allowed items-center justify-center p-0.5">
- <span aria-hidden className="i-ri-qr-code-line size-4 text-text-disabled" />
- </div>
+ <IconButton aria-label={qrCodeActionLabel} disabled>
+ <span aria-hidden className="i-ri-qr-code-line size-4" />
+ </IconButton>
) : (
<ShareQRCode
content={value}
@@ -150,7 +150,7 @@ export function AccessPointUrl({
>
<span
aria-hidden
- className={`i-ri-loop-left-line size-4 ${regenerating ? 'animate-spin' : ''}`}
+ className={`i-ri-loop-left-line size-4 ${regenerating ? 'animate-spin motion-reduce:animate-none' : ''}`}
/>
</IconButton>
}
diff --git a/web/app/components/tools/mcp/__tests__/mcp-server-modal.spec.tsx b/web/app/components/tools/mcp/__tests__/mcp-server-modal.spec.tsx
index ed4b51e5317..40d369b4c48 100644
--- a/web/app/components/tools/mcp/__tests__/mcp-server-modal.spec.tsx
+++ b/web/app/components/tools/mcp/__tests__/mcp-server-modal.spec.tsx
@@ -52,6 +52,11 @@ it.each([false, true])(
/>,
{ queryClient },
)
+ expect(
+ screen.getByRole('dialog', {
+ name: edit ? 'tools.mcp.server.modal.editTitle' : 'tools.mcp.server.modal.addTitle',
+ }),
+ ).toBeVisible()
const description = screen.getByRole('textbox', { name: 'tools.mcp.server.modal.description' })
const query = screen.getByRole('textbox', { name: 'Query' })
expect(description).toHaveValue(edit ? 'Saved description' : 'App description')
@@ -69,7 +74,7 @@ it.each([false, true])(
await user.clear(query)
await user.type(query, 'updated query')
await user.click(submit)
- await waitFor(() => expect(submit).toBeDisabled())
+ await waitFor(() => expect(submit).toHaveAttribute('aria-disabled', 'true'))
await user.click(submit)
expect(edit ? updateServer : createServer).toHaveBeenCalledExactlyOnceWith({
params: { app_id: 'app-123' },
@@ -92,6 +97,25 @@ it.each([false, true])(
},
)
+it('focuses description and parameter fields through their visible labels', async () => {
+ const user = userEvent.setup()
+ renderWithConsoleQuery(
+ <MCPServerModal
+ appID="app-123"
+ show
+ onHide={vi.fn()}
+ latestParams={[{ variable: 'query', label: 'Query', type: 'string' }]}
+ />,
+ )
+
+ await user.click(screen.getByText('tools.mcp.server.modal.description'))
+ const description = screen.getByRole('textbox', { name: 'tools.mcp.server.modal.description' })
+ expect(description).toHaveFocus()
+ expect(description).toBeRequired()
+ await user.click(screen.getByText('Query'))
+ expect(screen.getByRole('textbox', { name: 'Query' })).toHaveFocus()
+})
+
it.each(['tools.mcp.modal.cancel', 'common.operation.close'])(
'dismisses via %s without sending a request',
async (name) => {
diff --git a/web/app/components/tools/mcp/mcp-server-modal.tsx b/web/app/components/tools/mcp/mcp-server-modal.tsx
index af8c7c10017..186bca0f30b 100644
--- a/web/app/components/tools/mcp/mcp-server-modal.tsx
+++ b/web/app/components/tools/mcp/mcp-server-modal.tsx
@@ -1,4 +1,5 @@
'use client'
+import type { MCPServerParam } from './mcp-server-param-item'
import type { MCPServerDetail } from '@/app/components/tools/types'
import { Button } from '@langgenius/dify-ui/button'
import {
@@ -29,12 +30,6 @@ type ModalProps = {
}
}
-type MCPServerParam = {
- variable?: string
- label?: string
- type?: string
-}
-
const MCPServerModal = ({ appID, latestParams = [], data, show, onHide, appInfo }: ModalProps) => {
const { t } = useTranslation(['common', 'tools'])
const queryClient = useQueryClient()
@@ -54,6 +49,7 @@ const MCPServerModal = ({ appID, latestParams = [], data, show, onHide, appInfo
const defaultDescription = data?.description || appInfo?.description || ''
const [description, setDescription] = React.useState(defaultDescription)
const [params, setParams] = React.useState<Record<string, string>>(data?.parameters || {})
+ const descriptionId = React.useId()
const handleParamChange = (variable: string, value: string) => {
setParams((prev) => ({
@@ -109,79 +105,94 @@ const MCPServerModal = ({ appID, latestParams = [], data, show, onHide, appInfo
}}
>
<DialogContent className="w-130">
- <DialogHeader>
- <DialogTitle>
- {!data
- ? t(($) => $['mcp.server.modal.addTitle'], { ns: 'tools' })
- : t(($) => $['mcp.server.modal.editTitle'], { ns: 'tools' })}
- </DialogTitle>
- <DialogHeaderCloseButton aria-label={t(($) => $['operation.close'], { ns: 'common' })} />
- </DialogHeader>
- <DialogBody className="space-y-5">
- <div className="space-y-0.5">
- <div className="flex h-6 items-center gap-1">
- <div className="system-sm-medium text-text-secondary">
- {t(($) => $['mcp.server.modal.description'], { ns: 'tools' })}
+ <form
+ className="contents"
+ onSubmit={(event) => {
+ event.preventDefault()
+ if (!description || creating || updating) return
+ void submit()
+ }}
+ >
+ <DialogHeader>
+ <DialogTitle>
+ {!data
+ ? t(($) => $['mcp.server.modal.addTitle'], { ns: 'tools' })
+ : t(($) => $['mcp.server.modal.editTitle'], { ns: 'tools' })}
+ </DialogTitle>
+ <DialogHeaderCloseButton
+ aria-label={t(($) => $['operation.close'], { ns: 'common' })}
+ />
+ </DialogHeader>
+ <DialogBody className="min-w-0 space-y-5">
+ <div className="space-y-0.5">
+ <div className="flex h-6 items-center gap-1">
+ <label htmlFor={descriptionId} className="system-sm-medium text-text-secondary">
+ {t(($) => $['mcp.server.modal.description'], { ns: 'tools' })}
+ </label>
+ <span aria-hidden className="system-xs-regular text-text-destructive-secondary">
+ *
+ </span>
</div>
- <div className="system-xs-regular text-text-destructive-secondary">*</div>
+ <Textarea
+ id={descriptionId}
+ required
+ className="h-24 resize-none"
+ value={description}
+ placeholder={t(($) => $['mcp.server.modal.descriptionPlaceholder'], {
+ ns: 'tools',
+ })}
+ onValueChange={(value) => setDescription(value)}
+ />
</div>
- <Textarea
- aria-label={t(($) => $['mcp.server.modal.description'], { ns: 'tools' })}
- className="h-24 resize-none"
- value={description}
- placeholder={t(($) => $['mcp.server.modal.descriptionPlaceholder'], {
- ns: 'tools',
- })}
- onValueChange={(value) => setDescription(value)}
- />
- </div>
- {latestParams.length > 0 && (
- <div className="min-w-0">
- <div className="mb-1 flex items-center gap-2">
- <div className="shrink-0 system-xs-medium-uppercase text-text-primary">
- {t(($) => $['mcp.server.modal.parameters'], { ns: 'tools' })}
+ {latestParams.length > 0 && (
+ <div className="min-w-0">
+ <div className="mb-1 flex items-center gap-2">
+ <div className="shrink-0 system-xs-medium-uppercase text-text-primary">
+ {t(($) => $['mcp.server.modal.parameters'], { ns: 'tools' })}
+ </div>
+ <Separator
+ decorative
+ orientation="horizontal"
+ className="m-0 grow bg-divider-subtle"
+ />
</div>
- <Separator
- decorative
- orientation="horizontal"
- className="m-0 grow bg-divider-subtle"
- />
- </div>
- <div className="mb-2 body-xs-regular text-text-tertiary">
- {t(($) => $['mcp.server.modal.parametersTip'], { ns: 'tools' })}
- </div>
- <div className="min-w-0 space-y-3">
- {latestParams.map((paramItem) => {
- if (!paramItem.variable) return null
+ <div className="mb-2 body-xs-regular text-text-tertiary">
+ {t(($) => $['mcp.server.modal.parametersTip'], { ns: 'tools' })}
+ </div>
+ <div className="min-w-0 space-y-3">
+ {latestParams.map((paramItem) => {
+ if (!paramItem.variable) return null
- const { variable } = paramItem
+ const { variable } = paramItem
- return (
- <MCPServerParamItem
- key={variable}
- data={paramItem}
- value={params[variable] || ''}
- onChange={(value) => handleParamChange(variable, value)}
- />
- )
- })}
+ return (
+ <MCPServerParamItem
+ key={variable}
+ data={paramItem}
+ value={params[variable] || ''}
+ onChange={(value) => handleParamChange(variable, value)}
+ />
+ )
+ })}
+ </div>
</div>
- </div>
- )}
- </DialogBody>
- <DialogFooter>
- <Button onClick={onHide}>{t(($) => $['mcp.modal.cancel'], { ns: 'tools' })}</Button>
- <Button
- disabled={!description || creating || updating}
- variant="primary"
- onClick={submit}
- >
- {data
- ? t(($) => $['mcp.modal.save'], { ns: 'tools' })
- : t(($) => $['mcp.server.modal.confirm'], { ns: 'tools' })}
- </Button>
- </DialogFooter>
+ )}
+ </DialogBody>
+ <DialogFooter className="max-sm:flex-col max-sm:items-stretch">
+ <Button onClick={onHide}>{t(($) => $['mcp.modal.cancel'], { ns: 'tools' })}</Button>
+ <Button
+ type="submit"
+ disabled={!description}
+ loading={creating || updating}
+ variant="primary"
+ >
+ {data
+ ? t(($) => $['mcp.modal.save'], { ns: 'tools' })
+ : t(($) => $['mcp.server.modal.confirm'], { ns: 'tools' })}
+ </Button>
+ </DialogFooter>
+ </form>
</DialogContent>
</Dialog>
)
diff --git a/web/app/components/tools/mcp/mcp-server-param-item.tsx b/web/app/components/tools/mcp/mcp-server-param-item.tsx
index bc47bcef51f..3aa189b777e 100644
--- a/web/app/components/tools/mcp/mcp-server-param-item.tsx
+++ b/web/app/components/tools/mcp/mcp-server-param-item.tsx
@@ -3,22 +3,34 @@ import { Textarea } from '@langgenius/dify-ui/textarea'
import * as React from 'react'
import { useTranslation } from 'react-i18next'
+export type MCPServerParam = {
+ variable?: string
+ label?: string
+ type?: string
+}
+
type Props = Readonly<{
- data?: any
+ data: MCPServerParam
value: string
onChange: (value: string) => void
}>
const MCPServerParamItem = ({ data, value, onChange }: Props) => {
const { t } = useTranslation(['tools'])
+ const inputId = React.useId()
return (
<div className="min-w-0 space-y-0.5">
<div className="flex min-h-6 min-w-0 flex-wrap items-center gap-2">
- <div className="max-w-full min-w-0 system-xs-medium wrap-break-word text-text-secondary">
- {data.label}
- </div>
- <div className="system-xs-medium text-text-quaternary">·</div>
+ <label
+ htmlFor={inputId}
+ className="max-w-full min-w-0 system-xs-medium wrap-break-word text-text-secondary"
+ >
+ {data.label || data.variable}
+ </label>
+ <span aria-hidden className="system-xs-medium text-text-quaternary">
+ ·
+ </span>
<div className="max-w-full min-w-0 system-xs-medium break-all text-text-secondary">
{data.variable}
</div>
@@ -27,7 +39,7 @@ const MCPServerParamItem = ({ data, value, onChange }: Props) => {
</div>
</div>
<Textarea
- aria-label={data.label}
+ id={inputId}
className="h-8 resize-none"
value={value}
placeholder={t(($) => $['mcp.server.modal.parametersPlaceholder'], { ns: 'tools' })}
diff --git a/web/features/agent-v2/agent-detail/access/components/__tests__/access-surface-cards.spec.tsx b/web/features/agent-v2/agent-detail/access/components/__tests__/access-surface-cards.spec.tsx
index 1954d05ffa6..1af046d14c1 100644
--- a/web/features/agent-v2/agent-detail/access/components/__tests__/access-surface-cards.spec.tsx
+++ b/web/features/agent-v2/agent-detail/access/components/__tests__/access-surface-cards.spec.tsx
@@ -1329,9 +1329,11 @@ describe('Agent access surface cards', () => {
render(<ServiceApiAccessCard agentId="agent-1" />, {
wrapper: createAccessCardWrapper(client),
})
- expect(
- await screen.findByRole('button', { name: 'agentV2.agentDetail.access.copyServiceEndpoint' }),
- ).toBeEnabled()
+ await waitFor(() => {
+ expect(
+ screen.getByRole('button', { name: 'agentV2.agentDetail.access.copyServiceEndpoint' }),
+ ).toBeEnabled()
+ })
expect(
screen.getByRole('link', {
name: 'agentV2.agentDetail.access.serviceApi.actions.apiReference',