mirror of
https://github.com/langgenius/dify.git
synced 2026-04-30 23:48:04 +08:00
refactor(components): reorder class names for consistency in various plugin components and add unit tests for CardMoreInfo and other components
This commit is contained in:
@ -1,14 +1,14 @@
|
||||
import type { Dependency, GitHubItemAndMarketPlaceDependency, InstallStatus, PackageDependency, Plugin, PluginDeclaration, VersionProps } from '../../types'
|
||||
import type { Dependency, GitHubItemAndMarketPlaceDependency, InstallStatus, PackageDependency, Plugin, PluginDeclaration, VersionProps } from '../../../types'
|
||||
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { InstallStep, PluginCategoryEnum } from '../../types'
|
||||
import InstallBundle, { InstallType } from './index'
|
||||
import GithubItem from './item/github-item'
|
||||
import LoadedItem from './item/loaded-item'
|
||||
import MarketplaceItem from './item/marketplace-item'
|
||||
import PackageItem from './item/package-item'
|
||||
import ReadyToInstall from './ready-to-install'
|
||||
import Installed from './steps/installed'
|
||||
import { InstallStep, PluginCategoryEnum } from '../../../types'
|
||||
import InstallBundle, { InstallType } from '../index'
|
||||
import GithubItem from '../item/github-item'
|
||||
import LoadedItem from '../item/loaded-item'
|
||||
import MarketplaceItem from '../item/marketplace-item'
|
||||
import PackageItem from '../item/package-item'
|
||||
import ReadyToInstall from '../ready-to-install'
|
||||
import Installed from '../steps/installed'
|
||||
|
||||
// Factory functions for test data
|
||||
const createMockPlugin = (overrides: Partial<Plugin> = {}): Plugin => ({
|
||||
@ -143,19 +143,19 @@ let mockHideLogicState = {
|
||||
setIsInstalling: vi.fn(),
|
||||
handleStartToInstall: vi.fn(),
|
||||
}
|
||||
vi.mock('../hooks/use-hide-logic', () => ({
|
||||
vi.mock('../../hooks/use-hide-logic', () => ({
|
||||
default: () => mockHideLogicState,
|
||||
}))
|
||||
|
||||
// Mock useGetIcon hook
|
||||
vi.mock('../base/use-get-icon', () => ({
|
||||
vi.mock('../../base/use-get-icon', () => ({
|
||||
default: () => ({
|
||||
getIconUrl: (icon: string) => icon || 'default-icon.png',
|
||||
}),
|
||||
}))
|
||||
|
||||
// Mock usePluginInstallLimit hook
|
||||
vi.mock('../hooks/use-install-plugin-limit', () => ({
|
||||
vi.mock('../../hooks/use-install-plugin-limit', () => ({
|
||||
default: () => ({ canInstall: true }),
|
||||
pluginInstallLimit: () => ({ canInstall: true }),
|
||||
}))
|
||||
@ -190,22 +190,22 @@ vi.mock('@/app/components/plugins/plugin-page/use-reference-setting', () => ({
|
||||
}))
|
||||
|
||||
// Mock checkTaskStatus
|
||||
vi.mock('../base/check-task-status', () => ({
|
||||
vi.mock('../../base/check-task-status', () => ({
|
||||
default: () => ({ check: vi.fn(), stop: vi.fn() }),
|
||||
}))
|
||||
|
||||
// Mock useRefreshPluginList
|
||||
vi.mock('../hooks/use-refresh-plugin-list', () => ({
|
||||
vi.mock('../../hooks/use-refresh-plugin-list', () => ({
|
||||
default: () => ({ refreshPluginList: vi.fn() }),
|
||||
}))
|
||||
|
||||
// Mock useCheckInstalled
|
||||
vi.mock('../hooks/use-check-installed', () => ({
|
||||
vi.mock('../../hooks/use-check-installed', () => ({
|
||||
default: () => ({ installedInfo: {} }),
|
||||
}))
|
||||
|
||||
// Mock ReadyToInstall child component to test InstallBundle in isolation
|
||||
vi.mock('./ready-to-install', () => ({
|
||||
vi.mock('../ready-to-install', () => ({
|
||||
default: ({
|
||||
step,
|
||||
onStepChange,
|
||||
@ -1,9 +1,9 @@
|
||||
import type { Dependency, GitHubItemAndMarketPlaceDependency, PackageDependency, Plugin, VersionInfo } from '../../../types'
|
||||
import type { Dependency, GitHubItemAndMarketPlaceDependency, PackageDependency, Plugin, VersionInfo } from '../../../../types'
|
||||
import { act, fireEvent, render, screen, waitFor } from '@testing-library/react'
|
||||
import * as React from 'react'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { PluginCategoryEnum } from '../../../types'
|
||||
import InstallMulti from './install-multi'
|
||||
import { PluginCategoryEnum } from '../../../../types'
|
||||
import InstallMulti from '../install-multi'
|
||||
|
||||
// ==================== Mock Setup ====================
|
||||
|
||||
@ -62,12 +62,12 @@ vi.mock('@/context/global-public-context', () => ({
|
||||
}))
|
||||
|
||||
// Mock pluginInstallLimit
|
||||
vi.mock('../../hooks/use-install-plugin-limit', () => ({
|
||||
vi.mock('../../../hooks/use-install-plugin-limit', () => ({
|
||||
pluginInstallLimit: () => ({ canInstall: true }),
|
||||
}))
|
||||
|
||||
// Mock child components
|
||||
vi.mock('../item/github-item', () => ({
|
||||
vi.mock('../../item/github-item', () => ({
|
||||
default: vi.fn().mockImplementation(({
|
||||
checked,
|
||||
onCheckedChange,
|
||||
@ -120,7 +120,7 @@ vi.mock('../item/github-item', () => ({
|
||||
}),
|
||||
}))
|
||||
|
||||
vi.mock('../item/marketplace-item', () => ({
|
||||
vi.mock('../../item/marketplace-item', () => ({
|
||||
default: vi.fn().mockImplementation(({
|
||||
checked,
|
||||
onCheckedChange,
|
||||
@ -142,7 +142,7 @@ vi.mock('../item/marketplace-item', () => ({
|
||||
)),
|
||||
}))
|
||||
|
||||
vi.mock('../item/package-item', () => ({
|
||||
vi.mock('../../item/package-item', () => ({
|
||||
default: vi.fn().mockImplementation(({
|
||||
checked,
|
||||
onCheckedChange,
|
||||
@ -163,7 +163,7 @@ vi.mock('../item/package-item', () => ({
|
||||
)),
|
||||
}))
|
||||
|
||||
vi.mock('../../base/loading-error', () => ({
|
||||
vi.mock('../../../base/loading-error', () => ({
|
||||
default: () => <div data-testid="loading-error">Loading Error</div>,
|
||||
}))
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
import type { Dependency, InstallStatusResponse, PackageDependency } from '../../../types'
|
||||
import type { Dependency, InstallStatusResponse, PackageDependency } from '../../../../types'
|
||||
import { act, fireEvent, render, screen, waitFor } from '@testing-library/react'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { PluginCategoryEnum, TaskStatus } from '../../../types'
|
||||
import Install from './install'
|
||||
import { PluginCategoryEnum, TaskStatus } from '../../../../types'
|
||||
import Install from '../install'
|
||||
|
||||
// ==================== Mock Setup ====================
|
||||
|
||||
@ -42,7 +42,7 @@ vi.mock('@/service/use-plugins', () => ({
|
||||
// Mock checkTaskStatus
|
||||
const mockCheck = vi.fn()
|
||||
const mockStop = vi.fn()
|
||||
vi.mock('../../base/check-task-status', () => ({
|
||||
vi.mock('../../../base/check-task-status', () => ({
|
||||
default: () => ({
|
||||
check: mockCheck,
|
||||
stop: mockStop,
|
||||
@ -51,7 +51,7 @@ vi.mock('../../base/check-task-status', () => ({
|
||||
|
||||
// Mock useRefreshPluginList
|
||||
const mockRefreshPluginList = vi.fn()
|
||||
vi.mock('../../hooks/use-refresh-plugin-list', () => ({
|
||||
vi.mock('../../../hooks/use-refresh-plugin-list', () => ({
|
||||
default: () => ({
|
||||
refreshPluginList: mockRefreshPluginList,
|
||||
}),
|
||||
@ -69,7 +69,7 @@ vi.mock('@/app/components/plugins/plugin-page/use-reference-setting', () => ({
|
||||
}))
|
||||
|
||||
// Mock InstallMulti component with forwardRef support
|
||||
vi.mock('./install-multi', async () => {
|
||||
vi.mock('../install-multi', async () => {
|
||||
const React = await import('react')
|
||||
|
||||
const createPlugin = (index: number) => ({
|
||||
@ -838,7 +838,7 @@ describe('Install Component', () => {
|
||||
// ==================== Memoization Test ====================
|
||||
describe('Memoization', () => {
|
||||
it('should be memoized', async () => {
|
||||
const InstallModule = await import('./install')
|
||||
const InstallModule = await import('../install')
|
||||
// memo returns an object with $$typeof
|
||||
expect(typeof InstallModule.default).toBe('object')
|
||||
})
|
||||
Reference in New Issue
Block a user