From 6ee9aa2cce123a1c3355dcbebe8bbf613a4b7c80 Mon Sep 17 00:00:00 2001 From: Nelson Kopliku Date: Thu, 25 May 2023 14:53:08 +0200 Subject: [PATCH] Fix navigation to a running execution detail (#1457) --- assets/js/state/selectors/lastExecutions.js | 2 +- .../js/state/selectors/lastExecutions.test.js | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/assets/js/state/selectors/lastExecutions.js b/assets/js/state/selectors/lastExecutions.js index 281b73fe56..c4c14df336 100644 --- a/assets/js/state/selectors/lastExecutions.js +++ b/assets/js/state/selectors/lastExecutions.js @@ -21,7 +21,7 @@ const addHostnameToAgentsCheckResults = ( ...executionData, data: { ...data, - check_results: check_results.map((checkResult) => ({ + check_results: check_results?.map((checkResult) => ({ ...checkResult, agents_check_results: checkResult?.agents_check_results.map( (target) => ({ diff --git a/assets/js/state/selectors/lastExecutions.test.js b/assets/js/state/selectors/lastExecutions.test.js index 62c5a94848..303b5194bd 100644 --- a/assets/js/state/selectors/lastExecutions.test.js +++ b/assets/js/state/selectors/lastExecutions.test.js @@ -3,6 +3,7 @@ import { clusterFactory, catalogCheckFactory, checksExecutionCompletedForTargetsFactory, + checksExecutionRunningFactory, } from '@lib/test-utils/factories'; import { getLastExecution, getLastExecutionData } from './lastExecutions'; @@ -100,4 +101,34 @@ describe('lastExecutions selector', () => { lastExecution.data.check_results[0].agents_check_results[1].hostname ).toEqual(hostname2); }); + + it('should properly handle running executions', () => { + const { id: clusterID } = clusterFactory.build(); + const runningExecution = checksExecutionRunningFactory.build({ + group_id: clusterID, + }); + + const state = { + clustersList: { + clusters: [], + }, + hostsList: { + hosts: [], + }, + catalog: {}, + lastExecutions: { + [clusterID]: { + loading: false, + data: runningExecution, + error: null, + }, + }, + }; + + const { lastExecution } = getLastExecutionData(clusterID)(state); + + expect(lastExecution.data.result).toBeNull(); + expect(lastExecution.data.check_results).toBeUndefined(); + expect(lastExecution.data.status).toEqual('running'); + }); });