text: /* eslint-disable no-debugger */
  /* eslint-disable no-unused-vars */
  import {useSelector, useDispatch} from 'react-redux';
  import React, {useState, useEffect} from 'react';
  import ScenarioTestPopup from '@pages/common/ScenarioTestPopup';
  
  import {toast} from 'react-toastify';
  import {EXECUTE_STATE} from '@pages/uitest/utils/UitestCommon';
  import {useTranslation} from 'react-i18next';
  import {
      clearScenarioTestModal,
      executeStepByServer,
      executeStepDataClear,
      setExecuteStepCallBack
  } from '../../store/common';
  import {
      searchRandomAll,
      testRandom,
      testRandomDataClear
  } from '../../store/random';
  import {jsonStrFormatPretty, jsonStrFormatNotPretty} from '../../lib/jsonUtils';
  import {setDetailCaseList} from '../../store/uitest';
  import {saveScenarioHistory} from '../../store/scenario';
  import {getJsonObj} from '../../pages/uitest/utils/UitestCommon';
  
  /*
   * 시나리오 테스트 수행/결과 확인 팝업
   * 시나리오상세, 시나리오테스트이력 확인에서 호출함
   */
  function ScenarioTestPopupContainer() {
      const [t] = useTranslation();
      const dispatch = useDispatch();
  
      const {data: codeData} = useSelector((state) => state.common.searchCode);
  
      const [modalShow, setModalShow] = React.useState(false);
  
      // 수행 데이터
      const [executeList, setExecuteList] = React.useState([]);
  
      // execute List selected 값
      const [selectedNavId, setSelectedNavId] = React.useState(0);
  
      // 테스트 수행중인 경우
      const [isProcessTest, setIsProcessTest] = useState(false);
  
      // Session id 저장
      const [sessionId, setSessionId] = React.useState('');
  
      // 테스트 시작시간 저장
      const [startTime, setStartTime] = React.useState('');
  
      const {isFinish} = useSelector(
          (state) => state.common.setExecuteStepCallBack
      );
  
      // 시라리오 바닥 데이터
      const {data: scenarioData} = useSelector(
          (state) => state.uitest.scenarioInfo
      );
  
      const handleClose = () => {
          setModalShow(false);
      };
      const handleShow = () => {
          setSelectedNavId(0);
          setIsProcessTest(false);
          setModalShow(true);
      };
  
      const {data: serverData} = useSelector(
          (state) => state.common.searchServer
      );
  
      const {loading: searchLoading, data: randData} = useSelector(
          (state) => state.random.searchList
      );
  
      const {
          loading: testLoading,
          data: testResponse,
          error: testError
      } = useSelector((state) => state.random.test);
  
      const {scenarioTestInitData} = useSelector((state) => state.common);
  
      useEffect(() => {
          if (scenarioTestInitData.showModal && !modalShow) {
              const executeListTemp = {...scenarioTestInitData.executeList};
              executeListTemp.xhrCount = 0;
              executeListTemp.queryCount = 0;
  
              // scenarioTestInitData.executeList
              // scenarioTestInitData.executeList.caseList;
              const tempStepList = [];
  
              if (executeListTemp.parentId === 'UitestScenario') {
                  if (scenarioTestInitData.executeList.caseList) {
                      scenarioTestInitData.executeList.caseList.forEach(
                          (caze, cazeIdx) => {
                              const {caseName} = caze;
                              if (caze.stepList) {
                                  caze.stepList.forEach((step, stepIdx) => {
                                      const tempStep = {...step};
  
                                      // 값 비워둬야 됨
                                      tempStep.outputData1 = '수행대기중';
                                      tempStep.outputData2 = '수행대기중';
                                      tempStep.cazeIdx = cazeIdx;
                                      tempStep.stepIdx = stepIdx;
                                      tempStep.caseName = caseName;
  
                                      if (
                                          tempStep.stepCode === 'xhr' ||
                                          tempStep.stepCode === 'login'
                                      ) {
                                          tempStep.stepName = step.stepName;
                                          executeListTemp.xhrCount += 1;
                                      } else {
                                          tempStep.stepName = step.inputData2;
  
                                          if (tempStep.stepCode === 'query') {
                                              executeListTemp.queryCount += 1;
                                          }
                                      }
  
                                      tempStep.seq = tempStepList.length;
                                      tempStep.state = EXECUTE_STATE.WAIT;
                                      tempStepList.push(tempStep);
                                  });
                              }
                          }
                      );
                  }
              }
              if (executeListTemp.parentId === 'ScHistoryTable') {
                  executeListTemp.stepList.forEach((step, stepIdx) => {
                      const tempStep = {...step};
  
                      tempStep.cazeIdx = -1;
                      tempStep.stepIdx = stepIdx;
                      tempStep.caseName = step.caseName;
  
                      if (tempStep.stepCode === 'xhr') {
                          tempStep.stepName = step.stepName;
                          executeListTemp.xhrCount += 1;
                      } else {
                          tempStep.stepName = step.inputData2;
  
                          if (tempStep.stepCode === 'query') {
                              executeListTemp.queryCount += 1;
                          }
                      }
                      tempStep.seq = step.seq;
                      tempStepList.push(tempStep);
                  });
  
                  // executeListTemp.stepList = scenarioTestInitData;
              }
              executeListTemp.stepList = tempStepList;
  
              setExecuteList(executeListTemp);
              dispatch(clearScenarioTestModal());
              handleShow();
          }
      }, [scenarioTestInitData.showModal]);
  
      /** **************************** 여기 아래는 execute service 모듈입니다. */
  
      /*
       * afterTestService  : 테스트 완료 후처리 모듈
       * 1. scenario 화면에서 테스트 한 경우 바닥 데이터 변경(저장할 수 있도록 함)
       * 2. scHistory table에 테스트 이력 데이터 저장함
       * 3. 테스트 결과를 화면에 호출하기 위해 executeList 에도 세팅함
       */
      const afterTestService = (isSuccess) => {
          setIsProcessTest(false);
  
          // 종료시간 체크
          const offset = new Date().getTimezoneOffset() * 60000;
          const today = new Date(Date.now() - offset);
  
          // 1. scenario 화면에서 테스트 한 경우 바닥 데이터 변경(저장할 수 있도록 함)
          if (executeList.parentId === 'UitestScenario') {
              const scenarioDataNew = {...scenarioData};
  
              const caseListNew = scenarioDataNew.data.caseList.map((_caze) => {
                  const caze = _caze;
                  const stepListNew = caze.stepList.map((_step) => {
                      const step = _step;
  
                      const changeStep = executeList.stepList.filter(
                          (obj) => obj.id === step.id
                      );
                      if (changeStep.length > 0) {
                          step.outputData1 = changeStep[0].outputData1;
                          step.outputData2 = changeStep[0].outputData2;
                      }
                      return step;
                  });
                  caze.stepList = stepListNew;
                  return caze;
              });
              dispatch(setDetailCaseList(caseListNew));
          }
  
          // 2. scHistory table에 테스트 이력 데이터 저장함
          // 20211025 변수 리스트 데이터도 저장하도록 함
          // const saveVariableList = executeList
          const saveVariableList = executeList.variableList.map((unit) => {
              const variable = unit;
              // variable.testValue = variable.initialValue;
              // variable.changeValue = '';
              // variable.variableDesc = '';
              return variable;
          });
          const data = {
              scenarioId: executeList.scenarioId,
              wasServerId: executeList.wasServerId,
              dbServerId: executeList.dbServerId,
              executeMethod: true,
              isSuccess,
              sctestCd: 'online', // 고정
              startTime,
              endTime: today.toISOString().slice(0, -1),
              scTestList: executeList.stepList,
              variableList: saveVariableList
          };
  
          dispatch(saveScenarioHistory(data));
  
          // 3. 시나리오 전체 테스트 결과를 화면에 호출하기 위해 executeList 에도 세팅함
          // 시간 + 테스트 결과
          const executeListTemp = {...executeList};
          executeListTemp.startTime = startTime;
          executeListTemp.endTime = today.toISOString().slice(0, -1);
  
          const temp =
              Date.parse(executeListTemp.endTime) -
              Date.parse(executeListTemp.startTime);
          executeListTemp.isSuccess = isSuccess;
          // TODO endTime - startTime
          executeListTemp.executeSecond = temp / 1000;
  
          setExecuteList(executeListTemp);
      };
  
      /*
       * step (xhr ) 서버에서 수행하는 전문
       */
      const onExecuteStep = (serverId, step) => {
          dispatch(
              executeStepByServer(
                  serverId,
                  step.urlPath,
                  step.httpMethod,
                  step.inputData2,
                  jsonStrFormatNotPretty(step.inputData1),
                  step.stepCode,
                  sessionId
              )
          );
      };
      /*
       * step ( query) 서버에서 수행하는 전문
       */
      const onExecuteStepQuery = (serverId, step) => {
          dispatch(
              executeStepByServer(
                  serverId,
                  step.urlPath,
                  step.httpMethod,
                  step.inputData2,
                  step.inputData1,
                  step.stepCode
              )
          );
      };
  
      /*
       * step (login ) 서버에서 수행하는 전문
       */
      const onExecuteLogin = (serverId, step) => {
          dispatch(
              executeStepByServer(
                  serverId,
                  step.urlPath,
                  step.httpMethod,
                  step.inputData2,
                  step.inputData1,
                  step.stepCode,
                  ''
              )
          );
      };
  
      /*
       * getVardata : var 데이터 조회
       */
      const getVardata = (type, value, stepId) => {
          if (type === 'string') {
              return value;
          }
          if (type === 'number') {
              return Number(value);
          }
          if (type === 'step') {
              const selectedFromStep = executeList.stepList.filter(
                  (obj) => obj.id === Number(stepId)
              );
              return getJsonObj(selectedFromStep[0].outputData1, value);
          }
          return '';
      };
  
      /*
       * getVardata : var 데이터 조회
       */
      const getVariableData = (executeListTemp, copyFromVariableId) => {
          const tempVariable = executeListTemp.variableList.filter(
              (obj) => obj.id === Number(copyFromVariableId)
          );
  
          if (tempVariable.variableCodeKey === 'number') {
              return Number(tempVariable[0].changeValue);
          }
          return tempVariable[0].changeValue;
      };
  
      /*
       * checkFomular : 수식 true/false 값 리턴
       */
      const checkFomular = (aData, bData, fomular) => {
          // 유형이 다른경우 무조건 오류건
          if (typeof aData !== typeof bData) {
              return false;
          }
  
          if (fomular === '==') {
              if (aData === bData) {
                  return true;
              }
          } else if (fomular === '!=') {
              if (aData !== bData) {
                  return true;
              }
          } else if (fomular === '<') {
              if (typeof aData !== 'number') {
                  return false;
              }
              if (aData < bData) {
                  return true;
              }
          } else if (fomular === 'isNull') {
              if (aData === '') {
                  return true;
              }
          }
          return false;
      };
  
      /*
       * stateChange : 현재 Step Data 변경
       */
      const stateChange = (step, outputData) => {
          const executeListTemp = {...executeList};
          const aLoop = executeListTemp.stepList.map((unit, index) => {
              // eslint-disable-next-line no-underscore-dangle
              const _step = unit;
              if (_step.idx === step.idx && _step.id === step.id) {
                  _step.state = EXECUTE_STATE.SUCCESS;
                  _step.outputData1 = outputData; // 'Sleep finish';
              }
              return _step;
          });
          executeListTemp.stepList = aLoop;
          setExecuteList(executeListTemp);
      };
  
      /*
       * ifExecuteProcess : execute 후속 프로세스 수행
       */
      const ifExecuteProcess = (step, executeType, type, stepId) => {
          if (type === 'success') {
              stateChange(step, executeType);
              afterTestService(true);
          } else if (type === 'error') {
              stateChange(step, executeType);
              afterTestService(false);
          } else if (type === 'jump') {
              let isSkip = true;
  
              const executeListTemp = {...executeList};
              const aLoop = executeListTemp.stepList.map((unit, index) => {
                  // eslint-disable-next-line no-underscore-dangle
                  const _step = unit;
                  // state = EXECUTE_STATE.WAIT
                  if (_step.idx === step.idx && _step.id === step.id) {
                      _step.state = EXECUTE_STATE.SUCCESS;
                      _step.outputData1 = executeType;
                  }
                  if (Number(stepId) === Number(_step.id)) {
                      isSkip = false;
                  }
                  if (isSkip && _step.state === EXECUTE_STATE.WAIT) {
                      _step.state = EXECUTE_STATE.SKIP;
                      _step.outputData1 = 'Skip Case';
                  }
                  return _step;
              });
              executeListTemp.stepList = aLoop;
              setExecuteList(executeListTemp);
  
              dispatch(setExecuteStepCallBack(true));
          }
          // 거짓인 경우 미설정의 경우 다음 Step으로 이동
          else {
              // test
              stateChange(step, executeType);
              dispatch(setExecuteStepCallBack(true));
          }
      };
  
      const getToJsonObject = (jsonKeys, fromData, jsonObj, idx) => {
          const key = jsonKeys[idx];
  
          // jsonKeys 마지막 값인 경우 처리
          if (jsonKeys.length === idx + 1) {
              // eslint-disable-next-line no-param-reassign
              jsonObj[key] = fromData;
          } else if (
              key.length > 2 &&
              key.substring(0, 1) === '[' &&
              key.substring(key.length - 1, key.length) === ']'
          ) {
              // JSONArray jsonArrayT = (JSONArray) toInputData;
              // key = key.substring(1, key.length()-1);
              // int intKey = Integer.parseInt(key);
              // Object temp = getToJsonObject(jsonKeys, fromData, jsonArrayT.get(intKey), idx+1);
              // jsonArrayT.set(intKey, temp);
              const intKey = Number(
                  key.replace('[', '').replace(']', '').replace(/ /gi, '')
              );
  
              const temp = jsonObj.map((obj, index) => {
                  const tempCol = obj;
                  if (index === intKey) {
                      return getToJsonObject(
                          jsonKeys,
                          fromData,
                          jsonObj[intKey],
                          idx + 1
                      );
                  }
                  return tempCol;
              });
              return temp;
          } else {
              const temp = getToJsonObject(
                  jsonKeys,
                  fromData,
                  jsonObj[key],
                  idx + 1
              );
              // eslint-disable-next-line no-param-reassign
              jsonObj[key] = temp;
          }
          return jsonObj;
      };
  
      const onExecuteStepScriptError = (step) => {
          const executeListTemp = {...executeList};
          const {isSkipError} = step;
          const aLoop = executeListTemp.stepList.map((unit, index) => {
              // eslint-disable-next-line no-underscore-dangle
              const _step = unit;
              // state = EXECUTE_STATE.WAIT
              if (_step.idx === step.idx && _step.id === step.id) {
                  _step.state = EXECUTE_STATE.ERROR;
                  _step.outputData1 = 'Script Error';
              }
  
              return _step;
          });
          executeListTemp.stepList = aLoop;
          setExecuteList(executeListTemp);
  
          if (isSkipError) {
              dispatch(setExecuteStepCallBack(true));
          } else {
              afterTestService(false);
          }
      };
  
      /*
       * step ( Script 수행
       */
      const onExecuteStepScript = (step) => {
          const jsonInput = JSON.parse(step.inputData1);
          const executeListTemp = {...executeList};
          let fromData = '';
          // 유형 Sleep
          if (jsonInput.type === 'sleep') {
              // sleepMs ms 대기 후 step 완료 다음 step 호출
              setTimeout(() => {
                  // 현재 step 완료
                  stateChange(step, 'Sleep finish');
                  // 다음 step 호출
                  dispatch(setExecuteStepCallBack(true));
              }, Number(jsonInput.sleepMs));
          }
          // 유형 Copy
          else if (jsonInput.type === 'copy') {
              // FROM data 계산하기 random, variable, step, string, number
              if (jsonInput.copyFromType === 'random') {
                  if (!testLoading && testResponse) {
                      fromData = testResponse.data.testData;
                      dispatch(testRandomDataClear());
                  } else {
                      dispatch(
                          testRandom({
                              randomId: Number(jsonInput.copyRandKey)
                          })
                      );
                      return;
                  }
              } else if (jsonInput.copyFromType === 'variable') {
                  fromData = getVariableData(
                      executeListTemp,
                      jsonInput.copyFromVariableId
                  );
              } else {
                  // fromData 조회
                  fromData = getVardata(
                      jsonInput.copyFromType,
                      jsonInput.copyFromValue,
                      jsonInput.copyFromStepId
                  );
              }
              if (jsonInput.copyToType === 'variable') {
                  const variableLoop = executeListTemp.variableList.map(
                      (unit) => {
                          const variable = unit;
  
                          if (unit.id === Number(jsonInput.copyToVariableId)) {
                              variable.changeValue = fromData;
                          }
                          return variable;
                      }
                  );
                  executeListTemp.variableList = variableLoop;
  
                  const aLoop = executeListTemp.stepList.map((unit, index) => {
                      // eslint-disable-next-line no-underscore-dangle
                      const _step = unit;
                      // if (_step.state === EXECUTE_STATE.PROCESS) {
                      if (_step.idx === step.idx && _step.id === step.id) {
                          _step.state = EXECUTE_STATE.SUCCESS;
                          _step.outputData1 = 'Copy finish';
                      }
  
                      return _step;
                  });
                  executeListTemp.stepList = aLoop;
              } else {
                  const aLoop = executeListTemp.stepList.map((unit, index) => {
                      // eslint-disable-next-line no-underscore-dangle
                      const _step = unit;
  
                      // if (_step.state === EXECUTE_STATE.PROCESS) {
                      if (_step.idx === step.idx && _step.id === step.id) {
                          _step.state = EXECUTE_STATE.SUCCESS;
                          _step.outputData1 = 'Copy finish';
                      }
                      if (_step.id === Number(jsonInput.copyToStepId)) {
                          if (_step.stepCode === 'query') {
                              _step.inputData1 = _step.inputData1.replace(
                                  jsonInput.copyToValue,
                                  `'${fromData}'`
                              );
                          } else if (_step.stepCode === 'xhr') {
                              const jsonToObj = JSON.parse(_step.inputData1);
                              const gubunList = jsonInput.copyToValue.split('.');
  
                              const temp = getToJsonObject(
                                  gubunList,
                                  fromData,
                                  jsonToObj,
                                  0
                              );
                              _step.inputData1 = JSON.stringify(temp);
                          }
                      }
                      return _step;
                  });
                  executeListTemp.stepList = aLoop;
              }
  
              setExecuteList(executeListTemp);
              dispatch(setExecuteStepCallBack(true));
          }
          // 유형 IF
          else if (jsonInput.type === 'if') {
              let aData = '';
              let bData = '';
  
              if (jsonInput.ifCondAType === 'variable') {
                  aData = getVariableData(
                      executeListTemp,
                      jsonInput.ifCondAVariableId
                  );
              } else {
                  aData = getVardata(
                      jsonInput.ifCondAType,
                      jsonInput.ifCondAValue,
                      jsonInput.ifCondAStepId
                  );
              }
  
              // bData 조회
              if (jsonInput.ifFomular !== 'isNull') {
                  if (jsonInput.ifCondBType === 'variable') {
                      bData = getVariableData(
                          executeListTemp,
                          jsonInput.ifCondBVariableId
                      );
                  } else {
                      bData = getVardata(
                          jsonInput.ifCondBType,
                          jsonInput.ifCondBValue,
                          jsonInput.ifCondBStepId
                      );
                  }
              }
  
              const isTrue = checkFomular(aData, bData, jsonInput.ifFomular);
  
              if (isTrue) {
                  ifExecuteProcess(
                      step,
                      'executeTrue',
                      jsonInput.ifExecuteType,
                      jsonInput.ifExecuteJumpStepId
                  );
              } else if (!isTrue) {
                  ifExecuteProcess(
                      step,
                      'executeFalse',
                      jsonInput.ifExecuteTypeF,
                      jsonInput.ifExecuteJumpStepIdF
                  );
              }
              //
          }
      };
  
      /*
       * processStep -> 프로세스 순차적으로 수행
       */
      const processStep = () => {
          const executeListTemp = {...executeList};
  
          // 순차적으로 대기상태인 스탭을 찾음
          let seq = -1;
          const aLoop = executeListTemp.stepList.map((unit, index) => {
              // eslint-disable-next-line no-underscore-dangle
              const _step = unit;
              // state = EXECUTE_STATE.WAIT
              if (
                  (_step.state === EXECUTE_STATE.WAIT ||
                      _step.state === EXECUTE_STATE.PROCESS) &&
                  seq === -1
              ) {
                  _step.state = EXECUTE_STATE.PROCESS;
                  seq = index;
              }
              return _step;
          });
  
          // 최종으로 종료함
          if (seq === -1) {
              // testSuccess();
              afterTestService(true);
              return;
          }
          executeListTemp.stepList = aLoop;
          // const
  
          setExecuteList(executeListTemp);
          const step = aLoop[seq];
          if (step.stepCode === 'xhr') {
              onExecuteStep(executeList.wasServerId, step);
          } else if (step.stepCode === 'query') {
              onExecuteStepQuery(executeList.dbServerId, step);
          } else if (step.stepCode === 'script') {
              try {
                  onExecuteStepScript(step);
              } catch (e) {
                  // 현재 STEP을 애러처리 하고 후속 수행을 진행함
                  onExecuteStepScriptError(step);
              }
          } else if (step.stepCode === 'login') {
              onExecuteLogin(executeList.wasServerId, step);
          }
      };
  
      /*
       * playExecuteTrigger -> 테스트 수행 트리거
       */
      const playExecuteTrigger = () => {
          dispatch(testRandomDataClear());
  
          // 테스트 시작 시간
          const offset = new Date().getTimezoneOffset() * 60000;
          const today = new Date(Date.now() - offset);
          setStartTime(today.toISOString().slice(0, -1));
          setIsProcessTest(true);
  
          // 20211022 변수 데이터 세팅 필요
          const executeListTemp = {...executeList};
          const variableLoop = executeListTemp.variableList.map((unit) => {
              const variable = unit;
              variable.testValue =
                  variable.changeValue && variable.changeValue !== ''
                      ? variable.changeValue
                      : variable.initialValue;
              variable.changeValue = variable.testValue;
              return variable;
          });
          executeListTemp.variableList = variableLoop;
          setExecuteList(executeListTemp);
  
          processStep();
      };
  
      // execute test (xhr, query)
      const {
          loading: executeLoading,
          error: executeError,
          data: executeResponse
      } = useSelector((state) => state.common.executeStepByServer);
  
      useEffect(() => {
          // execute step success
          if (!executeLoading && executeResponse) {
              if (
                  executeResponse.data.sessionId &&
                  executeResponse.data.sessionId !== null &&
                  executeResponse.data.sessionId !== ''
              ) {
                  setSessionId(executeResponse.data.sessionId);
              }
              const executeListTemp = {...executeList};
              const aLoop = executeListTemp.stepList.map((unit, index) => {
                  // eslint-disable-next-line no-underscore-dangle
                  const _step = unit;
                  if (_step.state === EXECUTE_STATE.PROCESS) {
                      if (executeResponse.data.isSuccess) {
                          _step.state = EXECUTE_STATE.SUCCESS;
                          _step.outputData1 = jsonStrFormatPretty(
                              executeResponse.data.responseBody
                          );
                      } else {
                          _step.state = EXECUTE_STATE.ERROR;
                          _step.outputData1 = executeResponse.data.errorMessage;
  
                          if (executeResponse.data.responseBody) {
                              _step.outputData1 = jsonStrFormatPretty(
                                  executeResponse.data.responseBody
                              );
                          }
  
                          // fail 인 경우 처리 로직
  
                          executeResponse.data.isSuccess = _step.isSkipError;
                      }
                      _step.historyId = executeResponse.data.historyId;
                      _step.result = executeResponse.data.httpResponseCode;
                  }
                  return _step;
              });
              executeListTemp.stepList = aLoop;
              setExecuteList(executeListTemp);
              dispatch(executeStepDataClear());
  
              if (executeResponse.data.isSuccess) {
                  dispatch(setExecuteStepCallBack(true));
              } else {
                  afterTestService(false);
              }
          }
  
          // fail
          if (!executeLoading && executeError) {
              const executeListTemp = {...executeList};
              let isSkipError = false;
              const aLoop = executeListTemp.stepList.map((unit, index) => {
                  // eslint-disable-next-line no-underscore-dangle
                  const _step = unit;
  
                  if (_step.state === EXECUTE_STATE.PROCESS) {
                      _step.state = EXECUTE_STATE.ERROR;
  
                      // _step.outputData1 = executeError.data.errorMessage;
  
                      // // fail 인 경우 처리 로직
                      // executeResponse.data.isSuccess = _step.isSkipError;
                      isSkipError = _step.isSkipError;
  
                      // // _step.historyId = executeResponse.data.historyId;
                      _step.result = 'Error';
                  }
                  return _step;
              });
              executeListTemp.stepList = aLoop;
              setExecuteList(executeListTemp);
              dispatch(executeStepDataClear());
  
              if (isSkipError) {
                  dispatch(setExecuteStepCallBack(true));
              } else {
                  afterTestService(false);
              }
          }
      }, [executeResponse, executeError]);
  
      /*
       *
       */
      useEffect(() => {
          if (!testLoading && testResponse) {
              if (modalShow) {
                  processStep();
              }
              // testResponse.data.testData
              // dispatch(testRandomDataClear());
              // toast.success('Save success');
              // dispatch(setExecuteStepCallBack(true));
          }
      }, [testResponse]);
  
      /*
       * 다음 Step 호출
       */
      // useEffect(() => {
  
      // }, [isFinish]);
      if (isFinish) {
          dispatch(setExecuteStepCallBack(false));
          processStep();
      }
      /*
       * onClickInit -> 초기화 버튼 선택시
       */
      const onClickInit = (e) => {
          e.preventDefault();
  
          setSessionId('');
          setStartTime('');
          setIsProcessTest(false);
  
          const executeListTemp = {...executeList};
  
          // 순차적으로 대기상태인 스탭을 찾음
          const aLoop = executeListTemp.stepList.map((unit, index) => {
              // eslint-disable-next-line no-underscore-dangle
              const _step = unit;
              _step.state = EXECUTE_STATE.WAIT;
              _step.outputData1 = '수행대기중';
              _step.outputData2 = '수행대기중';
              return _step;
          });
  
          executeListTemp.stepList = aLoop;
          executeListTemp.isSuccess = '';
          executeListTemp.startTime = '';
          executeListTemp.executeSecond = '';
  
          // 20211025 변수도 초기화 작업 진행
          const variableList = executeListTemp.variableList.map((entity) => {
              const variable = entity;
              variable.changeValue = '';
              variable.testValue = '';
              return variable;
          });
          executeListTemp.variableList = variableList;
  
          // const
          setExecuteList(executeListTemp);
      };
  
      useEffect(() => {
          dispatch(searchRandomAll());
      }, []);
  
      return (
          <ScenarioTestPopup
              modalShow={modalShow}
              handleClose={handleClose}
              serverData={serverData}
              codeData={codeData}
              randData={randData}
              executeList={executeList}
              setExecuteList={setExecuteList}
              selectedNavId={selectedNavId}
              setSelectedNavId={setSelectedNavId}
              playExecuteTrigger={playExecuteTrigger}
              isProcessTest={isProcessTest}
              onClickInit={onClickInit}
          />
      );
  }
  
  export default ScenarioTestPopupContainer;
  