chore: fix faild tests

This commit is contained in:
Joel 2025-12-29 16:25:53 +08:00
parent d9659e470a
commit 576eb663c3
2 changed files with 242 additions and 236 deletions

View File

@ -63,6 +63,9 @@ type DebugConfigurationState = any
const defaultDebugConfigValue: DebugConfigurationState = { const defaultDebugConfigValue: DebugConfigurationState = {
mode: AppModeEnum.CHAT, mode: AppModeEnum.CHAT,
dataSets: [], dataSets: [],
modelConfig: {
model_id: 'test-model',
},
} }
const createDebugConfigValue = (overrides: Partial<DebugConfigurationState> = {}): DebugConfigurationState => ({ const createDebugConfigValue = (overrides: Partial<DebugConfigurationState> = {}): DebugConfigurationState => ({
@ -101,6 +104,7 @@ const renderConfigVar = (props: Partial<IConfigVarProps> = {}, debugOverrides: P
) )
} }
describe('ConfigVar', () => {
// Rendering behavior for empty and populated states. // Rendering behavior for empty and populated states.
describe('ConfigVar Rendering', () => { describe('ConfigVar Rendering', () => {
beforeEach(() => { beforeEach(() => {
@ -205,7 +209,9 @@ describe('ConfigVar Edit Variable', () => {
}) })
const item = screen.getByTitle('name · Name') const item = screen.getByTitle('name · Name')
const actionButtons = item.querySelectorAll('div.h-6.w-6') const itemContainer = item.closest('div.group')
expect(itemContainer).not.toBeNull()
const actionButtons = itemContainer!.querySelectorAll('div.h-6.w-6')
expect(actionButtons).toHaveLength(2) expect(actionButtons).toHaveLength(2)
fireEvent.click(actionButtons[0]) fireEvent.click(actionButtons[0])
@ -226,7 +232,9 @@ describe('ConfigVar Edit Variable', () => {
}) })
const item = screen.getByTitle('first · First') const item = screen.getByTitle('first · First')
const actionButtons = item.querySelectorAll('div.h-6.w-6') const itemContainer = item.closest('div.group')
expect(itemContainer).not.toBeNull()
const actionButtons = itemContainer!.querySelectorAll('div.h-6.w-6')
expect(actionButtons).toHaveLength(2) expect(actionButtons).toHaveLength(2)
fireEvent.click(actionButtons[0]) fireEvent.click(actionButtons[0])
@ -250,7 +258,9 @@ describe('ConfigVar Edit Variable', () => {
}) })
const item = screen.getByTitle('first · First') const item = screen.getByTitle('first · First')
const actionButtons = item.querySelectorAll('div.h-6.w-6') const itemContainer = item.closest('div.group')
expect(itemContainer).not.toBeNull()
const actionButtons = itemContainer!.querySelectorAll('div.h-6.w-6')
expect(actionButtons).toHaveLength(2) expect(actionButtons).toHaveLength(2)
fireEvent.click(actionButtons[0]) fireEvent.click(actionButtons[0])
@ -283,10 +293,8 @@ describe('ConfigVar Remove Variable', () => {
onPromptVariablesChange, onPromptVariablesChange,
}) })
const item = screen.getByTitle('name · Name') const removeBtn = screen.getByTestId('var-item-delete-btn')
const actionButtons = item.querySelectorAll('div.h-6.w-6') fireEvent.click(removeBtn)
expect(actionButtons).toHaveLength(2)
fireEvent.click(actionButtons[1])
expect(onPromptVariablesChange).toHaveBeenCalledWith([]) expect(onPromptVariablesChange).toHaveBeenCalledWith([])
}) })
@ -310,13 +318,9 @@ describe('ConfigVar Remove Variable', () => {
}, },
) )
const item = screen.getByTitle('context · Context') const deleteBtn = screen.getByTestId('var-item-delete-btn')
const actionButtons = item.querySelectorAll('div.h-6.w-6') fireEvent.click(deleteBtn)
expect(actionButtons).toHaveLength(2) // confirmation modal should show up
fireEvent.click(actionButtons[1])
expect(screen.getByText('appDebug.feature.dataSet.queryVariable.deleteContextVarTitle')).toBeInTheDocument()
fireEvent.click(screen.getByRole('button', { name: 'common.operation.confirm' })) fireEvent.click(screen.getByRole('button', { name: 'common.operation.confirm' }))
expect(onPromptVariablesChange).toHaveBeenCalledWith([]) expect(onPromptVariablesChange).toHaveBeenCalledWith([])
@ -365,3 +369,4 @@ describe('ConfigVar External Data Tool Events', () => {
]) ])
}) })
}) })
})

View File

@ -65,6 +65,7 @@ const VarItem: FC<ItemProps> = ({
<RiEditLine className="h-4 w-4 text-text-tertiary" /> <RiEditLine className="h-4 w-4 text-text-tertiary" />
</div> </div>
<div <div
data-testid="var-item-delete-btn"
className="flex h-6 w-6 cursor-pointer items-center justify-center text-text-tertiary hover:text-text-destructive" className="flex h-6 w-6 cursor-pointer items-center justify-center text-text-tertiary hover:text-text-destructive"
onClick={onRemove} onClick={onRemove}
onMouseOver={() => setIsDeleting(true)} onMouseOver={() => setIsDeleting(true)}