Compare commits
1 Commits
main
...
gru/projec
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3338be6650 |
@ -4,7 +4,8 @@ import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
|
|||||||
import type { ChatItemType } from '@fastgpt/global/core/chat/type';
|
import type { ChatItemType } from '@fastgpt/global/core/chat/type';
|
||||||
import {
|
import {
|
||||||
transformPreviewHistories,
|
transformPreviewHistories,
|
||||||
addStatisticalDataToHistoryItem
|
addStatisticalDataToHistoryItem,
|
||||||
|
getFlatAppResponses
|
||||||
} from '@/global/core/chat/utils';
|
} from '@/global/core/chat/utils';
|
||||||
|
|
||||||
const mockResponseData = {
|
const mockResponseData = {
|
||||||
@ -14,6 +15,70 @@ const mockResponseData = {
|
|||||||
moduleType: FlowNodeTypeEnum.chatNode
|
moduleType: FlowNodeTypeEnum.chatNode
|
||||||
};
|
};
|
||||||
|
|
||||||
|
describe('getFlatAppResponses', () => {
|
||||||
|
it('should return empty array for empty input', () => {
|
||||||
|
expect(getFlatAppResponses([])).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle single level responses', () => {
|
||||||
|
const responses = [
|
||||||
|
{ ...mockResponseData, moduleType: FlowNodeTypeEnum.chatNode },
|
||||||
|
{ ...mockResponseData, moduleType: FlowNodeTypeEnum.tools }
|
||||||
|
];
|
||||||
|
expect(getFlatAppResponses(responses)).toEqual(responses);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle nested pluginDetail', () => {
|
||||||
|
const responses = [
|
||||||
|
{
|
||||||
|
...mockResponseData,
|
||||||
|
pluginDetail: [{ ...mockResponseData, moduleType: FlowNodeTypeEnum.tools }]
|
||||||
|
}
|
||||||
|
];
|
||||||
|
expect(getFlatAppResponses(responses)).toHaveLength(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle nested toolDetail', () => {
|
||||||
|
const responses = [
|
||||||
|
{
|
||||||
|
...mockResponseData,
|
||||||
|
toolDetail: [{ ...mockResponseData, moduleType: FlowNodeTypeEnum.chatNode }]
|
||||||
|
}
|
||||||
|
];
|
||||||
|
expect(getFlatAppResponses(responses)).toHaveLength(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle nested loopDetail', () => {
|
||||||
|
const responses = [
|
||||||
|
{
|
||||||
|
...mockResponseData,
|
||||||
|
loopDetail: [{ ...mockResponseData, moduleType: FlowNodeTypeEnum.datasetSearchNode }]
|
||||||
|
}
|
||||||
|
];
|
||||||
|
expect(getFlatAppResponses(responses)).toHaveLength(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle multiple levels of nesting', () => {
|
||||||
|
const responses = [
|
||||||
|
{
|
||||||
|
...mockResponseData,
|
||||||
|
pluginDetail: [
|
||||||
|
{
|
||||||
|
...mockResponseData,
|
||||||
|
toolDetail: [
|
||||||
|
{
|
||||||
|
...mockResponseData,
|
||||||
|
loopDetail: [{ ...mockResponseData }]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
];
|
||||||
|
expect(getFlatAppResponses(responses)).toHaveLength(4);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('transformPreviewHistories', () => {
|
describe('transformPreviewHistories', () => {
|
||||||
it('should transform histories correctly with responseDetail=true', () => {
|
it('should transform histories correctly with responseDetail=true', () => {
|
||||||
const histories: ChatItemType[] = [
|
const histories: ChatItemType[] = [
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user