mirror of
https://github.com/langgenius/dify.git
synced 2026-04-24 12:55:49 +08:00
* test: adding some web tests (#27792) * feat: add validation to prevent saving empty opening statement in conversation opener modal (#27843) * fix(web): improve the consistency of the inputs-form UI (#27837) * fix(web): increase z-index of PortalToFollowElemContent (#27823) * fix: installation_id is missing when in tools page (#27849) * fix: avoid passing empty uniqueIdentifier to InstallFromMarketplace (#27802) Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * test: create new test scripts and update some existing test scripts o… (#27850) * feat: change feedback to forum (#27862) * chore: translate i18n files and update type definitions (#27868) Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com> * Fix/template transformer line number (#27867) Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com> * bump vite to 6.4.1 (#27877) * Add WEAVIATE_GRPC_ENDPOINT as designed in weaviate migration guide (#27861) Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> * Fix: correct DraftWorkflowApi.post response model (#27289) Signed-off-by: Yongtao Huang <yongtaoh2022@gmail.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> * fix Version 2.0.0-beta.2: Chat annotations Api Error #25506 (#27206) Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Asuka Minato <i@asukaminato.eu.org> * fix jina reader creadential migration command (#27883) * fix agent putout the output of workflow-tool twice (#26835) (#27087) * fix jina reader transform (#27922) * fix: prevent fetch version info in enterprise edition (#27923) * fix(api): fix `VariablePool.get` adding unexpected keys to variable_dictionary (#26767) Co-authored-by: -LAN- <laipz8200@outlook.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * refactor: implement tenant self queue for rag tasks (#27559) Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: -LAN- <laipz8200@outlook.com> * fix: bump brotli to 1.2.0 resloved CVE-2025-6176 (#27950) Signed-off-by: kenwoodjw <blackxin55+@gmail.com> --------- Signed-off-by: Yongtao Huang <yongtaoh2022@gmail.com> Signed-off-by: kenwoodjw <blackxin55+@gmail.com> Co-authored-by: aka James4u <smart.jamesjin@gmail.com> Co-authored-by: Novice <novice12185727@gmail.com> Co-authored-by: yangzheli <43645580+yangzheli@users.noreply.github.com> Co-authored-by: Elliott <105957288+Elliott-byte@users.noreply.github.com> Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com> Co-authored-by: johnny0120 <johnny0120@users.noreply.github.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Gritty_dev <101377478+codomposer@users.noreply.github.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: wangjifeng <163279492+kk-wangjifeng@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Boris Polonsky <BorisPolonsky@users.noreply.github.com> Co-authored-by: Yongtao Huang <yongtaoh2022@gmail.com> Co-authored-by: Cursx <33718736+Cursx@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Asuka Minato <i@asukaminato.eu.org> Co-authored-by: Jyong <76649700+JohnJyong@users.noreply.github.com> Co-authored-by: red_sun <56100962+redSun64@users.noreply.github.com> Co-authored-by: NFish <douxc512@gmail.com> Co-authored-by: QuantumGhost <obelisk.reg+git@gmail.com> Co-authored-by: -LAN- <laipz8200@outlook.com> Co-authored-by: hj24 <huangjian@dify.ai> Co-authored-by: kenwoodjw <blackxin55+@gmail.com>
158 lines
5.1 KiB
TypeScript
158 lines
5.1 KiB
TypeScript
/**
|
|
* Test suite for the classnames utility function
|
|
* This utility combines the classnames library with tailwind-merge
|
|
* to handle conditional CSS classes and merge conflicting Tailwind classes
|
|
*/
|
|
import cn from './classnames'
|
|
|
|
describe('classnames', () => {
|
|
/**
|
|
* Tests basic classnames library features:
|
|
* - String concatenation
|
|
* - Array handling
|
|
* - Falsy value filtering
|
|
* - Object-based conditional classes
|
|
*/
|
|
test('classnames libs feature', () => {
|
|
expect(cn('foo')).toBe('foo')
|
|
expect(cn('foo', 'bar')).toBe('foo bar')
|
|
expect(cn(['foo', 'bar'])).toBe('foo bar')
|
|
|
|
expect(cn(undefined)).toBe('')
|
|
expect(cn(null)).toBe('')
|
|
expect(cn(false)).toBe('')
|
|
|
|
expect(cn({
|
|
foo: true,
|
|
bar: false,
|
|
baz: true,
|
|
})).toBe('foo baz')
|
|
})
|
|
|
|
/**
|
|
* Tests tailwind-merge functionality:
|
|
* - Conflicting class resolution (last one wins)
|
|
* - Modifier handling (hover, focus, etc.)
|
|
* - Important prefix (!)
|
|
* - Custom color classes
|
|
* - Arbitrary values
|
|
*/
|
|
test('tailwind-merge', () => {
|
|
/* eslint-disable tailwindcss/classnames-order */
|
|
expect(cn('p-0')).toBe('p-0')
|
|
expect(cn('text-right text-center text-left')).toBe('text-left')
|
|
expect(cn('pl-4 p-8')).toBe('p-8')
|
|
expect(cn('m-[2px] m-[4px]')).toBe('m-[4px]')
|
|
expect(cn('m-1 m-[4px]')).toBe('m-[4px]')
|
|
expect(cn('overflow-x-auto hover:overflow-x-hidden overflow-x-scroll')).toBe(
|
|
'hover:overflow-x-hidden overflow-x-scroll',
|
|
)
|
|
expect(cn('h-10 h-min')).toBe('h-min')
|
|
expect(cn('bg-grey-5 bg-hotpink')).toBe('bg-hotpink')
|
|
|
|
expect(cn('hover:block hover:inline')).toBe('hover:inline')
|
|
|
|
expect(cn('font-medium !font-bold')).toBe('font-medium !font-bold')
|
|
expect(cn('!font-medium !font-bold')).toBe('!font-bold')
|
|
|
|
expect(cn('text-gray-100 text-primary-200')).toBe('text-primary-200')
|
|
expect(cn('text-some-unknown-color text-components-input-bg-disabled text-primary-200')).toBe('text-primary-200')
|
|
expect(cn('bg-some-unknown-color bg-components-input-bg-disabled bg-primary-200')).toBe('bg-primary-200')
|
|
|
|
expect(cn('border-t border-white/10')).toBe('border-t border-white/10')
|
|
expect(cn('border-t border-white')).toBe('border-t border-white')
|
|
expect(cn('text-3.5xl text-black')).toBe('text-3.5xl text-black')
|
|
})
|
|
|
|
/**
|
|
* Tests the integration of classnames and tailwind-merge:
|
|
* - Object-based conditional classes with Tailwind conflict resolution
|
|
*/
|
|
test('classnames combined with tailwind-merge', () => {
|
|
expect(cn('text-right', {
|
|
'text-center': true,
|
|
})).toBe('text-center')
|
|
|
|
expect(cn('text-right', {
|
|
'text-center': false,
|
|
})).toBe('text-right')
|
|
})
|
|
|
|
/**
|
|
* Tests handling of multiple mixed argument types:
|
|
* - Strings, arrays, and objects in a single call
|
|
* - Tailwind merge working across different argument types
|
|
*/
|
|
test('multiple mixed argument types', () => {
|
|
expect(cn('foo', ['bar', 'baz'], { qux: true, quux: false })).toBe('foo bar baz qux')
|
|
expect(cn('p-4', ['p-2', 'm-4'], { 'text-left': true, 'text-right': true })).toBe('p-2 m-4 text-right')
|
|
})
|
|
|
|
/**
|
|
* Tests nested array handling:
|
|
* - Deep array flattening
|
|
* - Tailwind merge with nested structures
|
|
*/
|
|
test('nested arrays', () => {
|
|
expect(cn(['foo', ['bar', 'baz']])).toBe('foo bar baz')
|
|
expect(cn(['p-4', ['p-2', 'text-center']])).toBe('p-2 text-center')
|
|
})
|
|
|
|
/**
|
|
* Tests empty input handling:
|
|
* - Empty strings, arrays, and objects
|
|
* - Mixed empty and non-empty values
|
|
*/
|
|
test('empty inputs', () => {
|
|
expect(cn('')).toBe('')
|
|
expect(cn([])).toBe('')
|
|
expect(cn({})).toBe('')
|
|
expect(cn('', [], {})).toBe('')
|
|
expect(cn('foo', '', 'bar')).toBe('foo bar')
|
|
})
|
|
|
|
/**
|
|
* Tests number input handling:
|
|
* - Truthy numbers converted to strings
|
|
* - Zero treated as falsy
|
|
*/
|
|
test('numbers as inputs', () => {
|
|
expect(cn(1)).toBe('1')
|
|
expect(cn(0)).toBe('')
|
|
expect(cn('foo', 1, 'bar')).toBe('foo 1 bar')
|
|
})
|
|
|
|
/**
|
|
* Tests multiple object arguments:
|
|
* - Object merging
|
|
* - Tailwind conflict resolution across objects
|
|
*/
|
|
test('multiple objects', () => {
|
|
expect(cn({ foo: true }, { bar: true })).toBe('foo bar')
|
|
expect(cn({ foo: true, bar: false }, { bar: true, baz: true })).toBe('foo bar baz')
|
|
expect(cn({ 'p-4': true }, { 'p-2': true })).toBe('p-2')
|
|
})
|
|
|
|
/**
|
|
* Tests complex edge cases:
|
|
* - Mixed falsy values
|
|
* - Nested arrays with falsy values
|
|
* - Multiple conflicting Tailwind classes
|
|
*/
|
|
test('complex edge cases', () => {
|
|
expect(cn('foo', null, undefined, false, 'bar', 0, 1, '')).toBe('foo bar 1')
|
|
expect(cn(['foo', null, ['bar', undefined, 'baz']])).toBe('foo bar baz')
|
|
expect(cn('text-sm', { 'text-lg': false, 'text-xl': true }, 'text-2xl')).toBe('text-2xl')
|
|
})
|
|
|
|
/**
|
|
* Tests important (!) modifier behavior:
|
|
* - Important modifiers in objects
|
|
* - Conflict resolution with important prefix
|
|
*/
|
|
test('important modifier with objects', () => {
|
|
expect(cn({ '!font-medium': true }, { '!font-bold': true })).toBe('!font-bold')
|
|
expect(cn('font-normal', { '!font-bold': true })).toBe('font-normal !font-bold')
|
|
})
|
|
})
|