mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix(editor): Fix execution running status listener for chat messages (#12951)
This commit is contained in:
parent
7031569a02
commit
4d55a29460
|
@ -215,6 +215,7 @@ describe('CanvasChat', () => {
|
||||||
// Send message
|
// Send message
|
||||||
const input = await findByTestId('chat-input');
|
const input = await findByTestId('chat-input');
|
||||||
await userEvent.type(input, 'Hello AI!');
|
await userEvent.type(input, 'Hello AI!');
|
||||||
|
|
||||||
await userEvent.keyboard('{Enter}');
|
await userEvent.keyboard('{Enter}');
|
||||||
|
|
||||||
// Verify message and response
|
// Verify message and response
|
||||||
|
@ -263,14 +264,18 @@ describe('CanvasChat', () => {
|
||||||
// Send message
|
// Send message
|
||||||
const input = await findByTestId('chat-input');
|
const input = await findByTestId('chat-input');
|
||||||
await userEvent.type(input, 'Test message');
|
await userEvent.type(input, 'Test message');
|
||||||
|
|
||||||
|
workflowsStore.isWorkflowRunning = true;
|
||||||
await userEvent.keyboard('{Enter}');
|
await userEvent.keyboard('{Enter}');
|
||||||
|
|
||||||
await waitFor(() => expect(queryByTestId('chat-message-typing')).toBeInTheDocument());
|
await waitFor(() => expect(queryByTestId('chat-message-typing')).toBeInTheDocument());
|
||||||
|
|
||||||
|
workflowsStore.isWorkflowRunning = false;
|
||||||
workflowsStore.getWorkflowExecution = {
|
workflowsStore.getWorkflowExecution = {
|
||||||
...(mockWorkflowExecution as unknown as IExecutionResponse),
|
...(mockWorkflowExecution as unknown as IExecutionResponse),
|
||||||
status: 'success',
|
status: 'success',
|
||||||
};
|
};
|
||||||
|
|
||||||
await waitFor(() => expect(queryByTestId('chat-message-typing')).not.toBeInTheDocument());
|
await waitFor(() => expect(queryByTestId('chat-message-typing')).not.toBeInTheDocument());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -175,28 +175,18 @@ const closePanel = () => {
|
||||||
// This function creates a promise that resolves when the workflow execution completes
|
// This function creates a promise that resolves when the workflow execution completes
|
||||||
// It's used to handle the loading state while waiting for the workflow to finish
|
// It's used to handle the loading state while waiting for the workflow to finish
|
||||||
async function createExecutionPromise() {
|
async function createExecutionPromise() {
|
||||||
let resolvePromise: () => void;
|
return await new Promise<void>((resolve) => {
|
||||||
const promise = new Promise<void>((resolve) => {
|
const resolveIfFinished = (isRunning: boolean) => {
|
||||||
resolvePromise = resolve;
|
if (!isRunning) {
|
||||||
});
|
unwatch();
|
||||||
|
resolve();
|
||||||
// Watch for changes in the workflow execution status
|
|
||||||
const stopWatch = watch(
|
|
||||||
() => workflowsStore.getWorkflowExecution?.status,
|
|
||||||
(newStatus) => {
|
|
||||||
// If the status is no longer 'running', resolve the promise
|
|
||||||
if (newStatus && newStatus !== 'running') {
|
|
||||||
resolvePromise();
|
|
||||||
// Stop the watcher when the promise is resolved
|
|
||||||
stopWatch();
|
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
{ immediate: true }, // Check the status immediately when the watcher is set up
|
|
||||||
);
|
|
||||||
|
|
||||||
// Return the promise, which will resolve when the workflow execution is complete
|
// Watch for changes in the workflow execution status
|
||||||
// This allows the caller to await the execution and handle the loading state appropriately
|
const unwatch = watch(() => workflowsStore.isWorkflowRunning, resolveIfFinished);
|
||||||
return await promise;
|
resolveIfFinished(workflowsStore.isWorkflowRunning);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onRunChatWorkflow(payload: RunWorkflowChatPayload) {
|
async function onRunChatWorkflow(payload: RunWorkflowChatPayload) {
|
||||||
|
|
Loading…
Reference in a new issue