diff --git a/apps/remix-ide-e2e/src/tests/script-runner.test.ts b/apps/remix-ide-e2e/src/tests/script-runner.test.ts index 4df6de5dc7..a2ad18977a 100644 --- a/apps/remix-ide-e2e/src/tests/script-runner.test.ts +++ b/apps/remix-ide-e2e/src/tests/script-runner.test.ts @@ -4,98 +4,106 @@ import init from '../helpers/init' const tests = { - before: function (browser: NightwatchBrowser, done: VoidFunction) { - init(browser, done, 'http://127.0.0.1:8080', false) - }, - 'Should activate plugins': function (browser: NightwatchBrowser) { - browser - .waitForElementVisible('*[data-id="remixIdeSidePanel"]') - .waitForElementVisible('*[plugin="pluginManager"]') - .click('*[plugin="pluginManager"]') - .waitForElementVisible('*[data-id="pluginManagerComponentPluginManager"]') - .click('*[data-id="pluginManagerComponentPluginManager"]') - .scrollAndClick('*[data-id="pluginManagerComponentActivateButtonUIScriptRunner"]') - }, - 'Should load default script runner': function (browser: NightwatchBrowser) { - browser - .waitForElementVisible('[data-id="sr-loaded-default"]') - .waitForElementVisible('[data-id="dependency-ethers-^5"]') - .waitForElementVisible('[data-id="sr-toggle-ethers6"]') - }, - 'Should load script runner ethers6': function (browser: NightwatchBrowser) { - browser - .click('[data-id="sr-toggle-ethers6"]') - .waitForElementVisible('[data-id="sr-loaded-ethers6"]') - .waitForElementPresent('[data-id="dependency-ethers-^6"]') - }, - 'Should have config file in .remix/script.config.json': function (browser: NightwatchBrowser) { - browser - .clickLaunchIcon('filePanel') - .waitForElementVisible('[data-path=".remix"]') - .waitForElementVisible('[data-id="treeViewDivDraggableItem.remix/script.config.json"]') - .openFile('.remix/script.config.json') - }, - 'check config file content': function (browser: NightwatchBrowser) { - browser - .getEditorValue((content) => { - console.log(JSON.parse(content)) - const parsed = JSON.parse(content) - browser.assert.ok(parsed.defaultConfig === 'ethers6', 'config file content is correct') - }) - }, - 'execute ethers6 script': function (browser: NightwatchBrowser) { - browser - .click('*[data-id="treeViewUltreeViewMenu"]') // make sure we create the file at the root folder - .addFile('deployWithEthersJs.js', { content: deployWithEthersJs }) - .pause(1000) - .click('[data-id="treeViewDivtreeViewItemcontracts"]') - .openFile('contracts/2_Owner.sol') - .clickLaunchIcon('solidity') - .click('*[data-id="compilerContainerCompileBtn"]') - .executeScriptInTerminal('remix.execute(\'deployWithEthersJs.js\')') - .waitForElementContainsText('*[data-id="terminalJournal"]', '0xd9145CCE52D386f254917e481eB44e9943F39138', 60000) - }, - 'switch workspace it should be default again': function (browser: NightwatchBrowser) { - browser - .clickLaunchIcon('filePanel') - .pause(2000) - .waitForElementVisible('*[data-id="workspacesMenuDropdown"]') - .click('*[data-id="workspacesMenuDropdown"]') - .click('*[data-id="workspacecreate"]') - .waitForElementPresent('*[data-id="create-semaphore"]') - .scrollAndClick('*[data-id="create-semaphore"]') - .modalFooterOKClick('TemplatesSelection') - .waitForElementVisible({ - locateStrategy: 'xpath', - selector: "//li[@data-id='UIScriptRunner' and @role='tab']" - }) - .click({ - locateStrategy: 'xpath', - selector: "//li[@data-id='UIScriptRunner' and @role='tab']" - }) - .waitForElementVisible('[data-id="sr-loaded-default"]') - .waitForElementVisible('[data-id="dependency-ethers-^5"]') - .waitForElementVisible('[data-id="sr-toggle-ethers6"]') - }, - 'switch to default workspace that should be on ethers6': function (browser: NightwatchBrowser) { - browser - .switchWorkspace('default_workspace') - .waitForElementVisible({ - locateStrategy: 'xpath', - selector: "//li[@data-id='UIScriptRunner' and @role='tab']" - }) - .click({ - locateStrategy: 'xpath', - selector: "//li[@data-id='UIScriptRunner' and @role='tab']" - }) - .waitForElementVisible('[data-id="sr-loaded-ethers6"]') - .waitForElementPresent('[data-id="dependency-ethers-^6"]') - } + before: function (browser: NightwatchBrowser, done: VoidFunction) { + init(browser, done, 'http://127.0.0.1:8080', false) + }, + 'Should activate plugins': function (browser: NightwatchBrowser) { + browser + .waitForElementVisible('*[data-id="remixIdeSidePanel"]') + .waitForElementVisible('*[plugin="pluginManager"]') + .click('*[plugin="pluginManager"]') + .waitForElementVisible('*[data-id="pluginManagerComponentPluginManager"]') + .click('*[data-id="pluginManagerComponentPluginManager"]') + .scrollAndClick('*[data-id="pluginManagerComponentActivateButtonUIScriptRunner"]') + }, + 'Should load default script runner': function (browser: NightwatchBrowser) { + browser + .waitForElementVisible('*[data-id="verticalIconsKindfilePanel"]') + .click('*[data-id="verticalIconsKindfilePanel"]') + .waitForElementVisible('*[data-id="treeViewDivtreeViewItemscripts"]') + .click('*[data-id="treeViewDivtreeViewItemscripts"]') + .waitForElementVisible('*[data-id="treeViewDivtreeViewItemscripts/deploy_with_ethers.ts"]') + .click('*[data-id="treeViewDivtreeViewItemscripts/deploy_with_ethers.ts"]') + .waitForElementVisible('button[data-id="script-config"]') + .click('button[data-id="script-config"]') + .waitForElementVisible('[data-id="sr-loaded-default"]') + .waitForElementVisible('[data-id="dependency-ethers-^5"]') + .waitForElementVisible('[data-id="sr-load-ethers6"]') + }, + 'Should load script runner ethers6': function (browser: NightwatchBrowser) { + browser + .click('[data-id="sr-load-ethers6"]') + .waitForElementVisible('[data-id="sr-loaded-ethers6"]') + .waitForElementPresent('[data-id="dependency-ethers-^6"]') + }, + 'Should have config file in .remix/script.config.json': function (browser: NightwatchBrowser) { + browser + .frameParent() + // .clickLaunchIcon('filePanel') + .waitForElementVisible('[data-path=".remix"]') + .waitForElementVisible('[data-id="treeViewDivDraggableItem.remix/script.config.json"]') + .openFile('.remix/script.config.json') + }, + 'check config file content': function (browser: NightwatchBrowser) { + browser + .getEditorValue((content) => { + console.log(JSON.parse(content)) + const parsed = JSON.parse(content) + browser.assert.ok(parsed.defaultConfig === 'ethers6', 'config file content is correct') + }) + }, + 'execute ethers6 script': function (browser: NightwatchBrowser) { + browser + .click('*[data-id="treeViewUltreeViewMenu"]') // make sure we create the file at the root folder + .addFile('deployWithEthersJs.js', { content: deployWithEthersJs }) + .pause(1000) + .click('[data-id="treeViewDivtreeViewItemcontracts"]') + .openFile('contracts/2_Owner.sol') + .clickLaunchIcon('solidity') + .click('*[data-id="compilerContainerCompileBtn"]') + .executeScriptInTerminal('remix.execute(\'deployWithEthersJs.js\')') + .waitForElementContainsText('*[data-id="terminalJournal"]', '0xd9145CCE52D386f254917e481eB44e9943F39138', 60000) + }, + 'switch workspace it should be default again': function (browser: NightwatchBrowser) { + browser + .clickLaunchIcon('filePanel') + .pause(2000) + .waitForElementVisible('*[data-id="workspacesMenuDropdown"]') + .click('*[data-id="workspacesMenuDropdown"]') + .click('*[data-id="workspacecreate"]') + .waitForElementPresent('*[data-id="create-semaphore"]') + .scrollAndClick('*[data-id="create-semaphore"]') + .modalFooterOKClick('TemplatesSelection') + .waitForElementVisible({ + locateStrategy: 'xpath', + selector: "//li[@data-id='UIScriptRunner' and @role='tab']" + }) + .click({ + locateStrategy: 'xpath', + selector: "//li[@data-id='UIScriptRunner' and @role='tab']" + }) + .waitForElementVisible('[data-id="sr-load-default"]') + .waitForElementVisible('[data-id="dependency-ethers-^5"]') + .waitForElementVisible('[data-id="sr-load-zksyncv6"]') + }, + 'switch to default workspace that should be on ethers6': function (browser: NightwatchBrowser) { + browser + .switchWorkspace('default_workspace') + .waitForElementVisible({ + locateStrategy: 'xpath', + selector: "//li[@data-id='UIScriptRunner' and @role='tab']" + }) + .click({ + locateStrategy: 'xpath', + selector: "//li[@data-id='UIScriptRunner' and @role='tab']" + }) + .waitForElementVisible('[data-id="sr-loaded-ethers6"]') + .waitForElementPresent('[data-id="dependency-ethers-^6"]') + } } module.exports = tests - const deployWithEthersJs = ` import { ethers } from 'ethers' @@ -105,7 +113,7 @@ import { ethers } from 'ethers' * @param {Array} args list of constructor' parameters * @param {Number} accountIndex account index from the exposed account * @return {Contract} deployed contract - * + * */ const deploy = async (contractName: string, args: Array, accountIndex?: number): Promise => { @@ -136,4 +144,4 @@ const deploy = async (contractName: string, args: Array, accountIndex?: num } catch (e) { console.log(e.message) } -})()` \ No newline at end of file +})()` diff --git a/apps/remix-ide/src/app/tabs/locales/en/scriptrunnerui.json b/apps/remix-ide/src/app/tabs/locales/en/scriptrunnerui.json new file mode 100644 index 0000000000..441e6a2312 --- /dev/null +++ b/apps/remix-ide/src/app/tabs/locales/en/scriptrunnerui.json @@ -0,0 +1,3 @@ +{ + "scriptrunnerui.defaultSection": "{{configName}}" +} diff --git a/libs/remix-ui/scriptrunner/src/lib/components/config-section.tsx b/libs/remix-ui/scriptrunner/src/lib/components/config-section.tsx new file mode 100644 index 0000000000..ef042893aa --- /dev/null +++ b/libs/remix-ui/scriptrunner/src/lib/components/config-section.tsx @@ -0,0 +1,137 @@ +import React, { useEffect, useRef, useState } from 'react' +import { FormattedMessage } from 'react-intl' +import { ProjectConfiguration } from '../../types'; +import { faCheck, faExclamationCircle, faRedoAlt, faToggleOn, faCaretDown, faCaretUp } from '@fortawesome/free-solid-svg-icons'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { CustomTooltip } from '@remix-ui/helper'; + +export interface ConfigSectionProps { + _paq: any; + activeKey: string + setActiveKey: (key: string) => void + config: ProjectConfiguration + key: number + loadScriptRunner: (config: ProjectConfiguration) => void + activeConfig: ProjectConfiguration +} + +export default function ConfigSection(props: ConfigSectionProps) { + const [isVisible, setIsVisible] = useState(true) + + const handleAnimationEnd = () => { + setIsVisible(false); + } + + const SectionHeader = () => { + + return ( +
+
+ { + props.setActiveKey(props.config.name) + props.loadScriptRunner(props.config) + props._paq.push(['trackEvent', 'scriptRunnerPlugin', 'loadScriptRunnerConfig', props.config.name]) + }} + checked={props.activeKey === props.config.name} + /> + +
+
+ ) + } + + const Dependencies = () => { + const [showAll, setShowAll] = useState(false); + const visibleDeps = showAll ? props.config.dependencies : props.config.dependencies.slice(0, 4); + const hasMore = props.config.dependencies.length > 4; + + return ( + <> + {visibleDeps.map((dep, depIndex) => ( +
  • + {dep.name} (v{dep.version}) +
  • + ))} + {hasMore && ( +
  • + { + e.preventDefault(); + setShowAll(!showAll); + }} + > + {showAll ? 'Show less' : 'Show more'} + + +
  • + )} + + ) + } + + return ( +
    +
    + +
    + {props.config.isLoading &&
    + Loading config +
    } +
    + <> + {!props.config.isLoading && !props.config.errorStatus && !props.config.error && +
    props.loadScriptRunner(props.config)} className="pointer px-2 pb-1"> + { props.activeConfig && props.activeConfig.name === props.config.name && +
    + {isVisible && Config loaded} + +
    + } +
    + } +
    + +
    +
    + {props.config.errorStatus && props.config.error &&
    + + + + +
    } + {!props.config.isLoading && props.config.errorStatus && props.config.error && +
    { + props.loadScriptRunner(props.config) + props._paq.push(['trackEvent', 'scriptRunnerPlugin', 'loadScriptRunnerConfig', props.config.name]) + }} + className="pointer px-2" + > + +
    + } +
    +
    +
    +

    {props.config.description}

    +

    Dependencies

    +
      + +
    +
    +
    + +
    + ) +} diff --git a/libs/remix-ui/scriptrunner/src/lib/script-runner-ui.tsx b/libs/remix-ui/scriptrunner/src/lib/script-runner-ui.tsx index f7a4948f12..cf46fcaae7 100644 --- a/libs/remix-ui/scriptrunner/src/lib/script-runner-ui.tsx +++ b/libs/remix-ui/scriptrunner/src/lib/script-runner-ui.tsx @@ -5,6 +5,7 @@ import { faCaretDown, faCaretRight, faCheck, faExclamationCircle, faRedoAlt, faT import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { CustomScriptRunner } from "./custom-script-runner"; import { CustomTooltip } from "@remix-ui/helper"; +import ConfigSection from "./components/config-section"; const _paq = (window._paq = window._paq || []) // eslint-disable-line export interface ScriptRunnerUIProps { @@ -33,8 +34,25 @@ export const ScriptRunnerUI = (props: ScriptRunnerUIProps) => { } return ( -
    - +
    +
    +
    script configuration
    +
    choose a specific configuration for your script
    +
    +
    + {configurations.filter((config) => config.publish).map((config: ProjectConfiguration, index) => ( + + ))} +
    + {/* {configurations.filter((config) => config.publish).map((config: ProjectConfiguration, index) => (
    @@ -97,7 +115,7 @@ export const ScriptRunnerUI = (props: ScriptRunnerUIProps) => {
    )) } - + */} {enableCustomScriptRunner &&