fix git clone e2e for hometab clean commented code.

pull/4930/head
Joseph Izang 5 months ago committed by Aniket
parent b1fa3733b8
commit 4da5e3a0b7
  1. 4
      apps/remix-ide-e2e/src/tests/homeTab.test.ts
  2. 48
      apps/remix-ide-e2e/src/tests/importFromGithub.test.ts
  3. 116
      libs/remix-ui/home-tab/src/lib/components/homeTabFile.tsx

@ -28,8 +28,8 @@ module.exports = {
'Should start with ERC20 workspace #group1': function (browser: NightwatchBrowser) { 'Should start with ERC20 workspace #group1': function (browser: NightwatchBrowser) {
browser browser
.click('*[data-path="home"') .click('*[data-path="home"')
.waitForElementVisible('*[data-id="homeTabGetStartedERC20"]') .waitForElementVisible('*[data-id="homeTabGetStartedozerc20"]')
.click('*[data-id="homeTabGetStartederc20"') .click('*[data-id="homeTabGetStartedozerc20"')
.waitForElementVisible('*[data-id="treeViewLitreeViewItemcontracts/MyToken.sol"]') .waitForElementVisible('*[data-id="treeViewLitreeViewItemcontracts/MyToken.sol"]')
.waitForElementVisible('*[data-id="treeViewDivtreeViewItemtests/MyToken_test.sol"]') .waitForElementVisible('*[data-id="treeViewDivtreeViewItemtests/MyToken_test.sol"]')
.click('*[data-id="treeViewDivtreeViewItemtests/MyToken_test.sol"]') .click('*[data-id="treeViewDivtreeViewItemtests/MyToken_test.sol"]')

@ -3,9 +3,9 @@ import { NightwatchBrowser } from 'nightwatch'
import init from '../helpers/init' import init from '../helpers/init'
const testData = { const testData = {
validURL: 'https://github.com/OpenZeppelin/openzeppelin-solidity/blob/67bca857eedf99bf44a4b6a0fc5b5ed553135316/contracts/access/Roles.sol', validURL: 'https://github.com/remix-project-org/git-hometab-test.git',
invalidURL: 'https://github.com/Oppelin/Roles.sol', invalidURL: 'https://github.com/Oppelin/Roles.sol',
JSON: 'https://github.com/ethereum/remix-project/blob/master/package.json' JSON: 'https://github.com/remix-project-org/git-hometab-test.git'
} }
module.exports = { module.exports = {
@ -23,62 +23,52 @@ module.exports = {
.pause(1000) .pause(1000)
.click('button[data-id="landingPageImportFromGitHubButton"]') .click('button[data-id="landingPageImportFromGitHubButton"]')
.waitForElementVisible('*[data-id="fileSystemModalDialogModalTitle-react"]') .waitForElementVisible('*[data-id="fileSystemModalDialogModalTitle-react"]')
.assert.containsText('*[data-id="homeTabModalDialogModalTitle-react"]', 'Import from GitHub') .assert.containsText('*[data-id="fileSystemModalDialogModalTitle-react"]', 'Clone Git Repository')
.waitForElementVisible('*[data-id="fileSystemModalDialogModalBody-react"]') .waitForElementVisible('*[data-id="fileSystemModalDialogModalBody-react"]')
.assert.containsText('*[data-id="fileSystemModalDialogModalBody-react"]', 'Enter the github URL you would like to load.')
.waitForElementVisible('input[data-id="modalDialogCustomPromptTextClone"]') .waitForElementVisible('input[data-id="modalDialogCustomPromptTextClone"]')
}, },
'Display Error Message For Invalid GitHub URL Modal #group1': function (browser: NightwatchBrowser) { 'Display Error Message For Invalid GitHub URL Modal #group1': function (browser: NightwatchBrowser) {
browser browser
.execute(() => { .execute(() => {
(document.querySelector('input[data-id="homeTabModalDialogCustomPromptText"]') as any).focus() (document.querySelector('input[data-id="modalDialogCustomPromptTextClone"]') as any).focus()
}, [], () => { }) }, [], () => { })
.setValue('input[data-id="homeTabModalDialogCustomPromptText"]', testData.invalidURL) .setValue('input[data-id="modalDialogCustomPromptTextClone"]', testData.invalidURL)
.waitForElementVisible('*[data-id="cloneGitRepositoryModalDialogModalFooter-react"]') .waitForElementVisible('*[data-id="fileSystemModalDialogModalFooter-react"]')
.click('[data-id="cloneGitRepository-modal-footer-ok-react"]') // submitted .click('[data-id="fileSystem-modal-footer-ok-react"]') // submitted
//.waitForElementVisible('*[data-shared="tooltipPopup"]') //.waitForElementVisible('*[data-shared="tooltipPopup"]')
//.waitForElementContainsText('*[data-shared="tooltipPopup"] span', 'not found ' + testData.invalidURL) //.waitForElementContainsText('*[data-shared="tooltipPopup"] span', 'not found ' + testData.invalidURL)
}, },
'Import From GitHub For Valid URL #group2': function (browser: NightwatchBrowser) { 'Clone From GitHub with Valid URL #group2': function (browser: NightwatchBrowser) {
browser browser
.waitForElementVisible('*[data-id="remixIdeIconPanel"]', 10000) .waitForElementVisible('*[data-id="remixIdeIconPanel"]', 10000)
.clickLaunchIcon('filePanel') .clickLaunchIcon('filePanel')
.click('div[data-id="verticalIconsHomeIcon"]') .click('div[data-id="verticalIconsHomeIcon"]')
.waitForElementVisible('button[data-id="landingPageImportFromGitHubButton"]').pause(1000) .waitForElementVisible('button[data-id="landingPageImportFromGitHubButton"]').pause(1000)
.click('button[data-id="landingPageImportFromGitHubButton"]') .click('button[data-id="landingPageImportFromGitHubButton"]')
.waitForElementVisible('input[data-id="homeTabModalDialogCustomPromptText"]') .waitForElementVisible('input[data-id="modalDialogCustomPromptTextClone"]')
.execute(() => { .execute(() => {
(document.querySelector('input[data-id="homeTabModalDialogCustomPromptText"]') as any).focus() (document.querySelector('input[data-id="modalDialogCustomPromptTextClone"]') as any).focus()
}, [], () => { }) }, [], () => { })
.clearValue('input[data-id="homeTabModalDialogCustomPromptText"]').pause(1000) .clearValue('input[data-id="modalDialogCustomPromptTextClone"]').pause(1000)
.setValue('input[data-id="homeTabModalDialogCustomPromptText"]', testData.validURL) .setValue('input[data-id="modalDialogCustomPromptTextClone"]', testData.validURL)
.waitForElementVisible('*[data-id="homeTab-modal-footer-ok-react"]') .waitForElementVisible('*[data-id="fileSystem-modal-footer-ok-react"]')
.click('[data-id="homeTab-modal-footer-ok-react"]') .click('[data-id="fileSystem-modal-footer-ok-react"]')
.openFile('github/OpenZeppelin/openzeppelin-solidity/contracts/access/Roles.sol') .openFile('Roles.sol')
.waitForElementVisible({ .waitForElementVisible({
selector: `//*[@data-id='tab-active' and @data-path="default_workspace/github/OpenZeppelin/openzeppelin-solidity/contracts/access/Roles.sol"]`, selector: `//*[@data-id='tab-active' and @data-path="git-hometab-test.git/Roles.sol"]`,
locateStrategy: 'xpath' locateStrategy: 'xpath'
}) })
.getEditorValue((content) => { .getEditorValue((content) => {
browser.assert.ok(content.indexOf('library Roles {') !== -1, 'content does contain "library Roles {"') browser.assert.ok(content.indexOf('library Roles {') !== -1, 'content does contain "library Roles {"')
}) })
}, },
'Import JSON From GitHub For Valid URL #group2': function (browser: NightwatchBrowser) { 'Confirm JSON After Cloning From GitHub For Valid URL #group2': function (browser: NightwatchBrowser) {
browser browser
.click('div[data-id="verticalIconsHomeIcon"]') .click('div[data-id="verticalIconsHomeIcon"]')
.click('button[data-id="landingPageImportFromGitHubButton"]') .openFile('package.json')
.waitForElementVisible('input[data-id="homeTabModalDialogCustomPromptText"]').pause(1000) .waitForElementVisible("*[data-path='git-hometab-test.git/package.json'")
.execute(() => {
(document.querySelector('input[data-id="homeTabModalDialogCustomPromptText"]') as any).focus()
}, [], () => { })
.clearValue('input[data-id="homeTabModalDialogCustomPromptText"]').pause(1000)
.setValue('input[data-id="homeTabModalDialogCustomPromptText"]', testData.JSON)
.waitForElementVisible('*[data-id="homeTab-modal-footer-ok-react"]')
.click('[data-id="homeTab-modal-footer-ok-react"]')
.openFile('github/ethereum/remix-project/package.json')
.waitForElementVisible("div[data-path='default_workspace/github/ethereum/remix-project/package.json'")
.getEditorValue((content) => { .getEditorValue((content) => {
browser.assert.ok(content.indexOf('"name": "remix-project",') !== -1, 'content does contain "name": "remix-project"') browser.assert.ok(content.indexOf('"name": "remix-project",') !== -1, 'content does contain "name": "remix-project"')
}) })

@ -11,21 +11,6 @@ interface HomeTabFileProps {
plugin: any plugin: any
} }
const loadingInitialState = {
tooltip: '',
showModalDialog: false,
importSource: '',
}
const loadingReducer = (state = loadingInitialState, action) => {
return {
...state,
tooltip: action.tooltip,
showModalDialog: false,
importSource: '',
}
}
function HomeTabFile({ plugin }: HomeTabFileProps) { function HomeTabFile({ plugin }: HomeTabFileProps) {
const [state, setState] = useState<{ const [state, setState] = useState<{
searchInput: string searchInput: string
@ -48,10 +33,6 @@ function HomeTabFile({ plugin }: HomeTabFileProps) {
recentWorkspaces: [], recentWorkspaces: [],
}) })
const [, dispatch] = useReducer(loadingReducer, loadingInitialState)
const inputValue = useRef(null)
useEffect(() => { useEffect(() => {
plugin.on('filePanel', 'setWorkspace', async () => { plugin.on('filePanel', 'setWorkspace', async () => {
let recents = JSON.parse(localStorage.getItem('recentWorkspaces')) let recents = JSON.parse(localStorage.getItem('recentWorkspaces'))
@ -91,41 +72,6 @@ function HomeTabFile({ plugin }: HomeTabFileProps) {
} }
}, [plugin]) }, [plugin])
const processLoading = (type: string) => {
_paq.push(['trackEvent', 'hometab', 'filesSection', 'importFrom' + type])
const contentImport = plugin.contentImport
const workspace = plugin.fileManager.getProvider('workspace')
const startsWith = state.importSource.substring(0, 4)
if ((type === 'ipfs' || type === 'IPFS') && startsWith !== 'ipfs' && startsWith !== 'IPFS') {
setState((prevState) => {
return { ...prevState, importSource: startsWith + state.importSource }
})
}
contentImport.import(
state.modalInfo.prefix + state.importSource,
(loadingMsg) => dispatch({ tooltip: loadingMsg }),
async (error, content, cleanUrl, type, url) => {
if (error) {
toast(error.message || error)
} else {
try {
if (await workspace.exists(type + '/' + cleanUrl)) toast('File already exists in workspace')
else {
workspace.addExternal(type + '/' + cleanUrl, content, url)
plugin.call('menuicons', 'select', 'filePanel')
}
} catch (e) {
toast(e.message)
}
}
}
)
setState((prevState) => {
return { ...prevState, showModalDialog: false, importSource: '' }
})
}
const toast = (message: string) => { const toast = (message: string) => {
setState((prevState) => { setState((prevState) => {
return { ...prevState, toasterMsg: message } return { ...prevState, toasterMsg: message }
@ -180,74 +126,16 @@ function HomeTabFile({ plugin }: HomeTabFileProps) {
plugin.verticalIcons.select('filePanel') plugin.verticalIcons.select('filePanel')
} }
const showFullMessage = (title: string, loadItem: string, examples: Array<string>, prefix = '') => {
setState((prevState) => {
return {
...prevState,
showModalDialog: true,
modalInfo: {
title: title,
loadItem: loadItem,
examples: examples,
prefix,
},
}
})
}
const hideFullMessage = () => {
//eslint-disable-line
setState((prevState) => {
return { ...prevState, showModalDialog: false, importSource: '' }
})
}
const handleSwichToRecentWorkspace = async (e, workspaceName) => { const handleSwichToRecentWorkspace = async (e, workspaceName) => {
e.preventDefault() e.preventDefault()
_paq.push(['trackEvent', 'hometab', 'filesSection', 'loadRecentWorkspace']) _paq.push(['trackEvent', 'hometab', 'filesSection', 'loadRecentWorkspace'])
await plugin.call('filePanel', 'switchToWorkspace', { name: workspaceName, isLocalhost: false }) await plugin.call('filePanel', 'switchToWorkspace', { name: workspaceName, isLocalhost: false })
} }
const examples = state.modalInfo.examples.map((urlEl, key) => (
<div key={key} className="p-1 user-select-auto">
<a>{urlEl}</a>
</div>
))
return ( return (
<> <>
<ModalDialog id="homeTab" title={'Import from ' + state.modalInfo.title}
okLabel="Import" hide={!state.showModalDialog} handleHide={() => hideFullMessage()}
okFn={() => processLoading(state.modalInfo.title)}>
<div className="p-2 user-select-auto">
{state.modalInfo.loadItem !== '' && <span>Enter the {state.modalInfo.loadItem} you would like to load.</span>}
{state.modalInfo.examples.length !== 0 && (
<>
<div>e.g</div>
<div>{examples}</div>
</>
)}
<div className="d-flex flex-row">
{state.modalInfo.prefix && <span className="text-nowrap align-self-center mr-2">ipfs://</span>}
<input
ref={inputValue}
type="text"
name="prompt_text"
id="inputPrompt_text"
className="w-100 mt-1 form-control"
data-id="homeTabModalDialogCustomPromptText"
value={state.importSource}
onInput={(e) => {
setState((prevState) => {
return { ...prevState, importSource: inputValue.current.value }
})
}}
/>
</div>
</div>
</ModalDialog>
<Toaster message={state.toasterMsg} /> <Toaster message={state.toasterMsg} />
<div className="justify-content-start mt-1 p-2 d-flex flex-column" id="hTFileSection"> <div className="justify-content-start p-2 d-flex flex-column" id="hTFileSection">
<div className="mb-1"> <div className="mb-1">
{(state.recentWorkspaces[0] || state.recentWorkspaces[1] || state.recentWorkspaces[2]) && ( {(state.recentWorkspaces[0] || state.recentWorkspaces[1] || state.recentWorkspaces[2]) && (
<div className="d-flex flex-column mb-5 remixui_recentworkspace"> <div className="d-flex flex-column mb-5 remixui_recentworkspace">
@ -272,7 +160,7 @@ function HomeTabFile({ plugin }: HomeTabFileProps) {
</div> </div>
)} )}
</div> </div>
<div className="d-flex flex-column flex-nowrap"> <div className="d-flex flex-column flex-nowrap mt-4">
<label style={{ fontSize: '1.2rem' }}> <label style={{ fontSize: '1.2rem' }}>
<FormattedMessage id="home.files" /> <FormattedMessage id="home.files" />
</label> </label>

Loading…
Cancel
Save