mirror of
https://github.com/langgenius/dify.git
synced 2026-03-27 17:19:55 +08:00
refactor(tests): reorganize test files and enhance test coverage for utility functions
- Moved test files for completion parameters, clipboard, app redirection, and emoji utilities to the appropriate directory structure. - Added comprehensive tests for clipboard functionality, including modern and legacy methods. - Implemented tests for app redirection logic based on user permissions and app modes. - Enhanced tests for completion parameters validation and error handling. - Introduced tests for emoji search functionality with various scenarios. - Updated icon utility tests to cover edge cases and security concerns. - Improved formatting tests for numbers, file sizes, and time representation.
This commit is contained in:
@ -6573,7 +6573,7 @@
|
||||
"count": 1
|
||||
}
|
||||
},
|
||||
"utils/completion-params.spec.ts": {
|
||||
"utils/__tests__/completion-params.spec.ts": {
|
||||
"ts/no-explicit-any": {
|
||||
"count": 3
|
||||
}
|
||||
@ -6596,7 +6596,7 @@
|
||||
"count": 1
|
||||
}
|
||||
},
|
||||
"utils/get-icon.spec.ts": {
|
||||
"utils/__tests__/get-icon.spec.ts": {
|
||||
"ts/no-explicit-any": {
|
||||
"count": 2
|
||||
}
|
||||
@ -6606,7 +6606,7 @@
|
||||
"count": 2
|
||||
}
|
||||
},
|
||||
"utils/index.spec.ts": {
|
||||
"utils/__tests__/index.spec.ts": {
|
||||
"test/no-identical-title": {
|
||||
"count": 2
|
||||
},
|
||||
@ -6624,7 +6624,7 @@
|
||||
"count": 1
|
||||
}
|
||||
},
|
||||
"utils/model-config.spec.ts": {
|
||||
"utils/__tests__/model-config.spec.ts": {
|
||||
"ts/no-explicit-any": {
|
||||
"count": 13
|
||||
}
|
||||
@ -6634,12 +6634,12 @@
|
||||
"count": 6
|
||||
}
|
||||
},
|
||||
"utils/navigation.spec.ts": {
|
||||
"utils/__tests__/navigation.spec.ts": {
|
||||
"ts/no-explicit-any": {
|
||||
"count": 4
|
||||
}
|
||||
},
|
||||
"utils/tool-call.spec.ts": {
|
||||
"utils/__tests__/tool-call.spec.ts": {
|
||||
"ts/no-explicit-any": {
|
||||
"count": 1
|
||||
}
|
||||
@ -6649,4 +6649,4 @@
|
||||
"count": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
851
web/pnpm-lock.yaml
generated
851
web/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -3,7 +3,7 @@
|
||||
* Tests navigation path generation based on user permissions and app modes
|
||||
*/
|
||||
import { AppModeEnum } from '@/types/app'
|
||||
import { getRedirection, getRedirectionPath } from './app-redirection'
|
||||
import { getRedirection, getRedirectionPath } from '../app-redirection'
|
||||
|
||||
describe('app-redirection', () => {
|
||||
/**
|
||||
@ -10,7 +10,7 @@
|
||||
*/
|
||||
import { afterEach, beforeAll, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { writeTextToClipboard } from './clipboard'
|
||||
import { writeTextToClipboard } from '../clipboard'
|
||||
|
||||
describe('Clipboard Utilities', () => {
|
||||
describe('writeTextToClipboard', () => {
|
||||
@ -1,5 +1,5 @@
|
||||
import type { FormValue, ModelParameterRule } from '@/app/components/header/account-setting/model-provider-page/declarations'
|
||||
import { mergeValidCompletionParams } from './completion-params'
|
||||
import { mergeValidCompletionParams } from '../completion-params'
|
||||
|
||||
describe('completion-params', () => {
|
||||
describe('mergeValidCompletionParams', () => {
|
||||
@ -10,7 +10,7 @@ import { renderHook } from '@testing-library/react'
|
||||
* - createSelectorCtx: Context with selector support using use-context-selector library
|
||||
*/
|
||||
import * as React from 'react'
|
||||
import { createCtx, createSelectorCtx } from './context'
|
||||
import { createCtx, createSelectorCtx } from '../context'
|
||||
|
||||
describe('Context Utilities', () => {
|
||||
describe('createCtx', () => {
|
||||
@ -1,4 +1,4 @@
|
||||
import { downloadBlob, downloadUrl } from './download'
|
||||
import { downloadBlob, downloadUrl } from '../download'
|
||||
|
||||
describe('downloadUrl', () => {
|
||||
let mockAnchor: HTMLAnchorElement
|
||||
@ -1,6 +1,6 @@
|
||||
import type { Mock } from 'vitest'
|
||||
import { SearchIndex } from 'emoji-mart'
|
||||
import { searchEmoji } from './emoji'
|
||||
import { searchEmoji } from '../emoji'
|
||||
|
||||
vi.mock('emoji-mart', () => ({
|
||||
SearchIndex: {
|
||||
@ -1,4 +1,4 @@
|
||||
import { formatFileSize, formatNumber, formatNumberAbbreviated, formatTime } from './format'
|
||||
import { formatFileSize, formatNumber, formatNumberAbbreviated, formatTime } from '../format'
|
||||
|
||||
describe('formatNumber', () => {
|
||||
it('should correctly format integers', () => {
|
||||
@ -3,7 +3,7 @@ import { MARKETPLACE_API_PREFIX } from '@/config'
|
||||
* Test suite for icon utility functions
|
||||
* Tests the generation of marketplace plugin icon URLs
|
||||
*/
|
||||
import { getIconFromMarketPlace } from './get-icon'
|
||||
import { getIconFromMarketPlace } from '../get-icon'
|
||||
|
||||
describe('get-icon', () => {
|
||||
describe('getIconFromMarketPlace', () => {
|
||||
@ -8,7 +8,7 @@ import {
|
||||
getTextWidthWithCanvas,
|
||||
randomString,
|
||||
sleep,
|
||||
} from './index'
|
||||
} from '../index'
|
||||
|
||||
describe('sleep', () => {
|
||||
it('should wait for the specified time', async () => {
|
||||
@ -2,7 +2,7 @@
|
||||
* Test suite for MCP (Model Context Protocol) utility functions
|
||||
* Tests icon detection logic for MCP-related features
|
||||
*/
|
||||
import { shouldUseMcpIcon, shouldUseMcpIconForAppIcon } from './mcp'
|
||||
import { shouldUseMcpIcon, shouldUseMcpIconForAppIcon } from '../mcp'
|
||||
|
||||
describe('mcp', () => {
|
||||
/**
|
||||
@ -16,7 +16,7 @@ import {
|
||||
formatBooleanInputs,
|
||||
promptVariablesToUserInputsForm,
|
||||
userInputsFormToPromptVariables,
|
||||
} from './model-config'
|
||||
} from '../model-config'
|
||||
|
||||
describe('Model Config Utilities', () => {
|
||||
describe('userInputsFormToPromptVariables', () => {
|
||||
@ -10,7 +10,7 @@ import {
|
||||
datasetNavigation,
|
||||
extractQueryParams,
|
||||
mergeQueryParams,
|
||||
} from './navigation'
|
||||
} from '../navigation'
|
||||
|
||||
describe('navigation', () => {
|
||||
const originalWindow = globalThis.window
|
||||
@ -3,7 +3,7 @@ import { DatasetPermission } from '@/models/datasets'
|
||||
* Test suite for permission utility functions
|
||||
* Tests dataset edit permission logic based on user roles and dataset settings
|
||||
*/
|
||||
import { hasEditPermissionForDataset } from './permission'
|
||||
import { hasEditPermissionForDataset } from '../permission'
|
||||
|
||||
describe('permission', () => {
|
||||
/**
|
||||
@ -1,4 +1,4 @@
|
||||
import { isSupportMCP } from './plugin-version-feature'
|
||||
import { isSupportMCP } from '../plugin-version-feature'
|
||||
|
||||
describe('plugin-version-feature', () => {
|
||||
beforeEach(() => {
|
||||
@ -1,4 +1,4 @@
|
||||
import { compareVersion, getLatestVersion, isEarlierThanVersion, isEqualOrLaterThanVersion } from './semver'
|
||||
import { compareVersion, getLatestVersion, isEarlierThanVersion, isEqualOrLaterThanVersion } from '../semver'
|
||||
|
||||
describe('semver utilities', () => {
|
||||
describe('getLatestVersion', () => {
|
||||
@ -2,7 +2,7 @@ import type { SetupStatusResponse } from '@/models/common'
|
||||
|
||||
import { fetchSetupStatus } from '@/service/common'
|
||||
|
||||
import { fetchSetupStatusWithCache } from './setup-status'
|
||||
import { fetchSetupStatusWithCache } from '../setup-status'
|
||||
|
||||
vi.mock('@/service/common', () => ({
|
||||
fetchSetupStatus: vi.fn(),
|
||||
@ -1,4 +1,4 @@
|
||||
import { storage } from './storage'
|
||||
import { storage } from '../storage'
|
||||
|
||||
describe('storage', () => {
|
||||
beforeEach(() => {
|
||||
@ -2,7 +2,7 @@
|
||||
* Test suite for time utility functions
|
||||
* Tests date comparison and formatting using dayjs
|
||||
*/
|
||||
import { formatTime, isAfter } from './time'
|
||||
import { formatTime, isAfter } from '../time'
|
||||
|
||||
describe('time', () => {
|
||||
/**
|
||||
@ -3,7 +3,7 @@ import { ModelFeatureEnum } from '@/app/components/header/account-setting/model-
|
||||
* Test suite for tool call utility functions
|
||||
* Tests detection of function/tool call support in AI models
|
||||
*/
|
||||
import { supportFunctionCall } from './tool-call'
|
||||
import { supportFunctionCall } from '../tool-call'
|
||||
|
||||
describe('tool-call', () => {
|
||||
/**
|
||||
@ -1,4 +1,4 @@
|
||||
import { validateRedirectUrl } from './urlValidation'
|
||||
import { validateRedirectUrl } from '../urlValidation'
|
||||
|
||||
describe('URL Validation', () => {
|
||||
describe('validateRedirectUrl', () => {
|
||||
@ -1,4 +1,4 @@
|
||||
import { draft07Validator, forbidBooleanProperties } from './validators'
|
||||
import { draft07Validator, forbidBooleanProperties } from '../validators'
|
||||
|
||||
describe('Validators', () => {
|
||||
describe('draft07Validator', () => {
|
||||
@ -8,7 +8,7 @@ import {
|
||||
getVars,
|
||||
hasDuplicateStr,
|
||||
replaceSpaceWithUnderscoreInVarNameInput,
|
||||
} from './var'
|
||||
} from '../var'
|
||||
|
||||
describe('Variable Utilities', () => {
|
||||
describe('checkKey', () => {
|
||||
Reference in New Issue
Block a user