/* eslint no-undef: 0 */
import React, { useEffect } from 'react'
import BrowserOnly from '@docusaurus/BrowserOnly'
const parseCLIARGS = `graph TD
STARTWDIO(Execute wdio or wdio run)-->
PARSECLIARGS[Parse CLI args]
PARSECLIARGS-->HELPSWITCH["wdio command --help"]-->
COMMANDINCLUDED{"Command included?"}
COMMANDINCLUDED-->|Yes|PRINTCMDHELP[Print command help text]
COMMANDINCLUDED-->|No|PRINTWDIOHELP[Print wdio help]
PARSECLIARGS-->CONFIGCMD[config]-->
RUNCONFIG[Run config command code]
PARSECLIARGS-->REPL[repl]-->
RUNREPL[Run repl command code]
PARSECLIARGS-->INSTALL[install]-->
RUNINSTALL[Run install code]
PARSECLIARGS-->RUN[run]-->
LAUNCHRUNNER[Launch test runner]
`
const runRepl = `graph TD
CALLRUN("Launch test runner by calling the @wdio/cli:index run()")-->
LAUNCHTESTRUNNER2[Test runner is launched]-->
CALLRUNCMDHANDLER("Call @wdio/cli/commands:run launcher()")-->
INSTANTIATELAUNCHER["Creates @wdio/cli:launcher instance 1) Set log level 2) Worker count equals number of specs * caps array length 3)Create a new runnner instance using @wdio/utils:initializePlugin 4. Create CLI Interface instance. 5. Setup interface job:start, job:end event listeners"]-->
CALLLAUNCHERINSTANCERUN["@wdio/cli:launcher run()"]-->
INITLAUNCHERINSTANCE["Create instance of all services listed in the config services property."] -->
INIT["Call the runner initialize() method"]-->
RUNPRETSTTASKS["Run pre-test tasks for runner plugins"]-->
CONFIGONPREPAREHOOK["wdio.conf.js onPrepare hook"]-->
SERVICESONPREPAREHOOK["Run the services onPrepare hook e.g. start selenium server."]-->
RUNMODE("Call @wdio/cli:launcher runMode()")-->
RUNMODEPROMISERESOLVED{"runMode() promise resolve?"}
RUNMODEPROMISERESOLVED-->|No|SCHEDULE["In @wdio/cli:launcher runMode() create a spec execution schedule."]-->
RUNSPECS["Start test execution by calling @wdio/cli:launcher runSpecs()."]-->
CREATEWORKERS["Create a new test instance (worker process) by calling @wdio/cli:launcher runSpecs().
Call @wdio/cli:launcher startInstance() to create a new worker instance.
See Create Worker Process and Test Execution flowcharts for more information on this process."]-->
ISNUMBERINSTANCESSPECSZERO{"Is number of worker processes less than config maxInstances?"}
ISNUMBERINSTANCESSPECSZERO-->|Yes|CREATEWORKERS
ISNUMBERINSTANCESSPECSZERO-->|No|SCHEDULELOOP["When number of running instances and number of specs is zero, exit runSpecs()."]-->ENDRUNMODE
RUNMODEPROMISERESOLVED-->|Yes|ENDRUNMODE["Pass control back to @wdio/cli:launcher run()."]-->
ONCOMPLETEHOOKS[Run service and config onComplete hooks.]-->
INTERFACEFINALISE["Call @wdio/cli interface.js finalise() method. This method prints the test results and summary using data from the repoter packages."]-->
EXIT(Shutdown runner, end test process.)
`
const installConfig = `graph TD
INSTALLCOMMAND[install]-->
TYPENAMESUPPORTED{Is type and name supported?}
TYPENAMESUPPORTED-->|No|ERROR[Throw error message]
TYPENAMESUPPORTED-->|Yes|INSTALLPACKAGE[Install package]
INSTALLPACKAGE-->ADDSERVICEREPORTER[Add services and reporters to wdio.conf.js]
CONFIGCOMMAND[config]-->
EXECUTEWIZARD[Execute setup wizard]-->
QUESTIONNAIRE[Run questionaire, store answers package variables.]-->
SYNCMODE{executionMode is sync?}
SYNCMODE-->|Yes|INSTALLWDIOSYNC["Install @wdio/sync"]
INSTALLWDIOSYNC-->YARNCHECK["If --yarn, Install packages using yarn, otherwise use npm"]
SYNCMODE-->|No|ASYNCMODE["Do not install @wdio/sync"]
YARNCHECK-->CREATEWDIOCONFIG["Create wdio.conf.js"]
ASYNCMODE-->YARNCHECK
REPLCOMMAND[repl]-->
CREATESESSION[Create a new Webdriver session using webdriverio remote]-->
ADDGLOBALS["Add browser, $, and $$ to global scope"]-->
LOADREPL[Load the REPL by calling the WebdriverIO debug command]-->
EXITREPL[Exit when REPL closed]
`
const startTestInstance = `graph TD
STARTINSTANCE("@wdio/cli:launcher startInstance()")-->
CALLRUNNERRUNMETHOD["Call @wdio/local-runner:index.js run() return @wdio/local-runner:worker instance"]-->
ADDLISTENERS["Add message, error, exit event listeners to worker instance."]-->
CALLPOSTMESSAGE["Call @wdio/local-runner:worker postMessage(). If an instance is not created, call startProcess() and fork a child process."]-->
FORKCHILDPROCESS["@wdio/local-runner:worker startProcess() forks a child process using the child_process fork() method."]-->
CREATERUNNERINSTANCE["The args passed to child_process fork execute the code in the @wdio/local-runner run.js.This action creates a new instance of @wdio/runner index.js. "]-->
ADDHANDLERS["Add message, error and exit listeners to the forked process. These listeners will process commands."]-->
RUNWDIORUNNERINDEXJS["@wdio/local-runner postMessage() instructs the child process to run the code @wdio/runner index.js."]-->
POSTMESSAGE["@wdio/local-runner postMessage() sends child process a message that contains the capability id,'run' command, config file, CLI args, capabilties, config details about automation backend, number of retries. When the child process receives this message, all services, reports and services are setup. The tests are them executed."]-->
CONTROLPASSEDTORUNNERINDEXJS["Control passed to @wdio/runner:index"]-->
TESTINITCOMPLETE("All services, reports and services are setup. The tests are them executed. See Test Execution flow chart for more information.")
`
const setupTest = `graph TD
START("@wdio/runner:index called from child process via a run message.")-->
EXECUTERUN["@wdio/runner:index run()"]-->
SETUPREPORTER["Initialise BaseReporter object which creates a new @wdio/runner reporter instance.All reporters listed in the wdio.conf.js reporters property are initialized."]-->
INITTESTFRAMEWORK["Test framework from the wdio.conf. js property is initialized usingthe @wdio/utils initializePlugin method.
Supported frameworks include @wdio/mocha-framework, @wdio/cucumber-framework and @wdio/jasmine-framework."]-->
INITSERVICES["Initialise services"]-->
RUNEFORESESSIONHOOK[Run wdio.conf.js beforeSession hook.]-->
INITSESSION["Call @wdio/runner:index _initSession. @wdio/runner:utils initializeInstance calls webdriverio:index.js remote()."]-->
ISPROTOCOLWEBDRIVER{"Is protocol webdriver?"}
ISPROTOCOLWEBDRIVER-->|Yes|WEBDRIVER
ISPROTOCOLWEBDRIVER-->|No|DEVTOOLS
WEBDRIVER["Call webdriver:index newSession 1. Start Webdriver session. 2. Get protocol commands. 3. Create webdriver monad with protocol arguments. 4. Return monad session instance to caller."]-->RUNNERRUN
DEVTOOLS["Create puppeteer instance. Return session instance to caller."]-->RUNNERRUN
RUNNERRUN["Store instance in global browser variable."]-->
SETWATCHMODEFLAG["Set watch mode flag"]-->
INITCOMPLETE[Initialisation successful, send runner:start message to reporter.]-->
KICKOFFTESTS["Kick off tests in framework by calling the framework's run method, e.g. @wdio/mocha-framework:index run()."]-->
WAITFORTESTTOFINISH[Wait for test to finish. If watch mode keep session open.]-->
SENDRESULTS[Send results to reporter instance for processing.]-->
INTERFACE["@wdio/cli:interface printSummary() called Test results printed to terminal"]-->
KILLWORKERSESSION[Kill worker session.]
`
const graphData = `
graph LR
START("Start wdio in the CLI @wdio/cli index / run.js")-->
LAUNCHER["@wdio/cli launcher.js"]-->
LOCALRUNNER["@wdio/local-runner"]-->
RUNNER["@wdio/runner"]
LISTOFSERVICES["Any package that ends with -service @wdio/appium-service @wdio/applitools-service @wdio/browserstack-service wdio-lambdatest-service @wdio/lighthouse-service @wdio/firefox-profile-service @wdio/sauce-service @wdio/selenium-standalone-service @wdio/static-server-service @wdio/testingbot-service wdio-chromedriver-service wdio-intercept-service wdio-zafira-listener-service wdio-reportportal-service wdio-docker-service"]-->
LAUNCHER
LISTOFSERVICES-->LOCALRUNNER
LISTOFSERVICES-->RUNNER
REPORTER["Any package that ends with -reporter @wdio/allure-reporter @wdio/concise-reporter @wdio/dot-reporter @wdio/junit-reporter @wdio/reporter @wdio/spec-reporter @wdio/sumologic-reporter @wdio/json-reporter wdio-reportportal-reporter wdio-video-reporter @rpii/wdio-html-reporter wdio-mochawesome-reporter wdio-timeline-reporter wdio-cucumberjs-json-reporter"]-->RUNNER
FRAMEWORK["Any package that ends with -framework @wdio/jasmine-framework @wdio/mocha-framework @wdio/cucumber-framework "]-->
RUNNER
WEBDRIVER["webdriverio webdriver"]-->
RUNNER
GLOBAL["GLOBALS @wdio/sync @wdio/config @wdio/logger @wdio/utils"]
`
export function CreateFlowcharts({ id }) {
useEffect(() => {
// Define the initial _id based on the id prop
let _id = 'graph TD'
// Map id values to their corresponding _id values
const idToIdMapping = {
createlocalworkerprocess: startTestInstance,
testexecution: setupTest,
highleveloverview: graphData,
}
// Update _id based on the id prop if it exists in the mapping
if (idToIdMapping[id]) {
_id = idToIdMapping[id]
}
// Delaying the Flow chart creation to ensure `flowChartGraphDivContainer` element is added to dom.
setTimeout(() => {
createFlowChart(_id)
}, 25)
}, [id])
return (
{() => {
return (