+
+
{cardContent}
)
}
return (
-
+
{cardContent}
)
diff --git a/web/app/components/explore/learn-dify/__tests__/item.spec.tsx b/web/app/components/explore/learn-dify/__tests__/item.spec.tsx
index fc2f328110a..c3d2f6287e4 100644
--- a/web/app/components/explore/learn-dify/__tests__/item.spec.tsx
+++ b/web/app/components/explore/learn-dify/__tests__/item.spec.tsx
@@ -1,7 +1,8 @@
import type { DeploymentEdition } from '@dify/contracts/api/console/system-features/types.gen'
import type { ReactElement } from 'react'
import type { App } from '@/models/explore'
-import { fireEvent, screen } from '@testing-library/react'
+import { screen } from '@testing-library/react'
+import userEvent from '@testing-library/user-event'
import { trackEvent } from '@/app/components/base/amplitude'
import { renderWithConsoleQuery } from '@/test/console/query-data'
import { AppModeEnum } from '@/types/app'
@@ -57,14 +58,15 @@ describe('LearnDifyItem', () => {
expect(screen.queryByText('explore.appCard.try')).not.toBeInTheDocument()
})
- it('should create app when card is clicked outside cloud edition', () => {
+ it('should create app when card is clicked outside cloud edition', async () => {
deploymentEdition = 'COMMUNITY'
const app = createApp()
const onCreate = vi.fn()
+ const user = userEvent.setup()
render(
)
- fireEvent.click(screen.getByRole('button', { name: 'Learn Dify App' }))
+ await user.click(screen.getByRole('button', { name: 'Learn Dify App' }))
expect(onCreate).toHaveBeenCalledWith(app)
expect(mockTrackEvent).not.toHaveBeenCalled()
@@ -78,13 +80,14 @@ describe('LearnDifyItem', () => {
expect(screen.queryByRole('button', { name: 'Learn Dify App' })).not.toBeInTheDocument()
})
- it('should open detail when card is clicked in cloud edition', () => {
+ it('should open detail when card is clicked in cloud edition', async () => {
const onTry = vi.fn()
const app = createApp()
+ const user = userEvent.setup()
render(
)
- fireEvent.click(screen.getByRole('button', { name: 'Learn Dify App' }))
+ await user.click(screen.getByRole('button', { name: 'Learn Dify App' }))
expect(onTry).toHaveBeenCalledWith({ appId: app.app_id, app })
expect(mockTrackEvent).toHaveBeenCalledWith('preview_template', {
@@ -96,13 +99,19 @@ describe('LearnDifyItem', () => {
})
})
- it('should run the card action when Enter is pressed', () => {
+ it('should run the card action when Enter is pressed', async () => {
const onTry = vi.fn()
const app = createApp()
+ const user = userEvent.setup()
render(
)
- fireEvent.keyDown(screen.getByRole('button', { name: 'Learn Dify App' }), { key: 'Enter' })
+ const card = screen.getByRole('button', { name: 'Learn Dify App' })
+ expect(card).toHaveAttribute('type', 'button')
+ expect(card).toHaveAccessibleDescription('Learn Dify description')
+
+ card.focus()
+ await user.keyboard('{Enter}')
expect(onTry).toHaveBeenCalledWith({ appId: app.app_id, app })
})
diff --git a/web/app/components/explore/learn-dify/index.tsx b/web/app/components/explore/learn-dify/index.tsx
index 5ab9e98fb01..ce920be506f 100644
--- a/web/app/components/explore/learn-dify/index.tsx
+++ b/web/app/components/explore/learn-dify/index.tsx
@@ -119,7 +119,7 @@ const LearnDifyContent = ({
{onHide && (