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,8 +104,9 @@ const renderConfigVar = (props: Partial<IConfigVarProps> = {}, debugOverrides: P
) )
} }
// Rendering behavior for empty and populated states. describe('ConfigVar', () => {
describe('ConfigVar Rendering', () => { // Rendering behavior for empty and populated states.
describe('ConfigVar Rendering', () => {
beforeEach(() => { beforeEach(() => {
vi.clearAllMocks() vi.clearAllMocks()
latestSortableProps = null latestSortableProps = null
@ -139,10 +143,10 @@ describe('ConfigVar Rendering', () => {
expect(onPromptVariablesChange).toHaveBeenCalledWith([secondVar, firstVar]) expect(onPromptVariablesChange).toHaveBeenCalledWith([secondVar, firstVar])
}) })
}) })
// Variable creation flows using the add menu. // Variable creation flows using the add menu.
describe('ConfigVar Add Variable', () => { describe('ConfigVar Add Variable', () => {
beforeEach(() => { beforeEach(() => {
vi.clearAllMocks() vi.clearAllMocks()
latestSortableProps = null latestSortableProps = null
@ -183,10 +187,10 @@ describe('ConfigVar Add Variable', () => {
expect(onPromptVariablesChange).toHaveBeenLastCalledWith([]) expect(onPromptVariablesChange).toHaveBeenLastCalledWith([])
}) })
}) })
// Editing flows for variables through the modal. // Editing flows for variables through the modal.
describe('ConfigVar Edit Variable', () => { describe('ConfigVar Edit Variable', () => {
beforeEach(() => { beforeEach(() => {
vi.clearAllMocks() vi.clearAllMocks()
latestSortableProps = null latestSortableProps = null
@ -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])
@ -262,10 +272,10 @@ describe('ConfigVar Edit Variable', () => {
expect(Toast.notify).toHaveBeenCalled() expect(Toast.notify).toHaveBeenCalled()
expect(onPromptVariablesChange).not.toHaveBeenCalled() expect(onPromptVariablesChange).not.toHaveBeenCalled()
}) })
}) })
// Removal behavior including confirm modal branch. // Removal behavior including confirm modal branch.
describe('ConfigVar Remove Variable', () => { describe('ConfigVar Remove Variable', () => {
beforeEach(() => { beforeEach(() => {
vi.clearAllMocks() vi.clearAllMocks()
latestSortableProps = null latestSortableProps = null
@ -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,21 +318,17 @@ 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([])
}) })
}) })
// Event subscription support for external data tools. // Event subscription support for external data tools.
describe('ConfigVar External Data Tool Events', () => { describe('ConfigVar External Data Tool Events', () => {
beforeEach(() => { beforeEach(() => {
vi.clearAllMocks() vi.clearAllMocks()
latestSortableProps = null latestSortableProps = null
@ -364,4 +368,5 @@ 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)}