Compare commits

..
1 Commits
Author SHA1 Message Date
super 77dfb83cbf fix(keys): 完整显示 API 密钥分组描述 2026-12-01 22:03:17 +08:00
2 changed files with 71 additions and 13 deletions

No files matched your search

@@ -19,6 +19,8 @@ For commercial licensing, please contact support@quantumnous.com
import { fireEvent, render, screen, within } from '@testing-library/react'
import { describe, expect, test } from 'vitest'
import type { ApiKeyGroupOption } from '../api-key-group-combobox'
let shouldReduceMotion = false
const reducedMotionMediaQuery = window.matchMedia('(prefers-reduced-motion)')
Object.defineProperty(reducedMotionMediaQuery, 'matches', {
@@ -67,13 +69,16 @@ const options = [
{ value: 'vip', label: 'vip', desc: 'Priority group', ratio: 3 },
]
function Harness(props: { initialValue: string }) {
function Harness(props: {
initialValue: string
options?: ApiKeyGroupOption[]
}) {
const [value, setValue] = useState(props.initialValue)
return (
<I18nextProvider i18n={i18n}>
<ApiKeyGroupCombobox
options={options}
options={props.options ?? options}
value={value}
onValueChange={setValue}
/>
@@ -96,6 +101,57 @@ function getCommandItem(label: string): HTMLElement {
return item
}
describe('API key group description readability', () => {
test.each([
{
kind: 'a long multiline description',
description:
'特殊渠道,适合指定客户端调用。完整说明需要显示全部内容,不能省略使用限制。\n请确认客户端支持后再选择此分组。',
},
{
kind: 'an unbroken identifier',
description:
'supported-client-identifier-without-spaces-that-must-wrap-inside-a-narrow-group-selector',
},
])('shows $kind in full before and after selection', ({ description }) => {
render(
<Harness
initialValue=''
options={[
{
value: 'detailed',
label: 'Detailed group',
desc: description,
ratio: 0.083,
},
]}
/>
)
fireEvent.click(getTrigger())
const option = screen.getByRole('option', { name: /Detailed group/ })
const optionDescription = within(option).getByText(description, {
normalizer: (text) => text,
})
expect(optionDescription).toHaveClass(
'whitespace-pre-wrap',
'[overflow-wrap:anywhere]'
)
expect(optionDescription).not.toHaveClass('truncate')
fireEvent.click(option)
const selectedDescription = within(getTrigger()).getByText(description, {
normalizer: (text) => text,
})
expect(selectedDescription).toHaveClass(
'whitespace-pre-wrap',
'[overflow-wrap:anywhere]'
)
expect(selectedDescription).not.toHaveClass('truncate')
expect(getTrigger()).toHaveAttribute('aria-expanded', 'false')
expect(screen.getByTestId('selected-group')).toHaveTextContent('detailed')
})
})
describe('API key group combobox Auto effect', () => {
test('uses the compact table capsules in the selected group and dropdown options', () => {
setReducedMotion(false)
@@ -119,17 +119,17 @@ export function ApiKeyGroupCombobox({
<AutoGroupFlowBorder shouldReduceMotion={shouldReduceMotion} />
)}
<span className='flex min-w-0 flex-1 items-center justify-between gap-2 sm:gap-3'>
<span className='min-w-0'>
<span className='min-w-0 flex-1'>
<span className='block truncate font-medium'>
{selectedOption?.label || placeholder || t('Select a group')}
</span>
{selectedOption?.desc && (
<span className='text-muted-foreground block truncate text-[11px] sm:text-xs'>
<span className='text-muted-foreground block text-[11px] leading-relaxed [overflow-wrap:anywhere] whitespace-pre-wrap sm:text-xs'>
{selectedOption.desc}
</span>
)}
</span>
<span className='hidden sm:block'>
<span className='hidden shrink-0 sm:block'>
<GroupRatioBadge
ratio={selectedOption?.ratio}
isAuto={isAutoSelected}
@@ -188,20 +188,22 @@ export function ApiKeyGroupCombobox({
)}
/>
<span className='min-w-0 flex-1'>
<span className='block truncate font-medium'>
{option.label}
<span className='flex min-w-0 items-center justify-between gap-2'>
<span className='min-w-0 truncate font-medium'>
{option.label}
</span>
<GroupRatioBadge
ratio={option.ratio}
isAuto={isAutoOption}
shouldReduceMotion={shouldReduceMotion}
/>
</span>
{option.desc && (
<span className='text-muted-foreground block truncate text-xs'>
<span className='text-muted-foreground mt-0.5 block text-xs leading-relaxed [overflow-wrap:anywhere] whitespace-pre-wrap'>
{option.desc}
</span>
)}
</span>
<GroupRatioBadge
ratio={option.ratio}
isAuto={isAutoOption}
shouldReduceMotion={shouldReduceMotion}
/>
</CommandItem>
)
})}