Skip to content

Commit dae5c35

Browse files
authored
Merge pull request #6198 from ethereum/fix_deps_unfolding
Fix deps unfolding
2 parents d553f90 + c05b591 commit dae5c35

File tree

9 files changed

+159
-13
lines changed

9 files changed

+159
-13
lines changed

apps/remix-ide-e2e/src/commands/createContract.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ function createContract (browser: NightwatchBrowser, inputParams: string, callba
1818
browser.setValue('.udapp_contractActionsContainerSingle > input', inputParams, function () {
1919
browser
2020
.pause(1000) // wait to get the button enabled
21-
.waitForElementVisible('.udapp_contractActionsContainerSingle > div')
22-
.click('.udapp_contractActionsContainerSingle > div').pause(500).perform(function () { callback() })
21+
.waitForElementVisible('.udapp_contractActionsContainerSingle button')
22+
.click('.udapp_contractActionsContainerSingle button').pause(500).perform(function () { callback() })
2323
})
2424
} else {
2525
browser
26-
.click('.udapp_contractActionsContainerSingle > div')
26+
.waitForElementVisible('.udapp_contractActionsContainerSingle button')
27+
.click('.udapp_contractActionsContainerSingle button')
2728
.pause(500)
2829
.perform(function () { callback() })
2930
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { NightwatchBrowser } from 'nightwatch'
2+
import EventEmitter from 'events'
3+
4+
class ExpandAllFolders extends EventEmitter {
5+
command (this: NightwatchBrowser, targetDirectory?: string) {
6+
this.api.perform((done) => {
7+
expandAllFolders(this.api, targetDirectory, () => {
8+
done()
9+
this.emit('complete')
10+
})
11+
})
12+
return this
13+
}
14+
}
15+
16+
function expandAllFolders (browser: NightwatchBrowser, targetDirectory?: string, done?: VoidFunction) {
17+
// Ensure file panel is open
18+
browser.perform((bdone: VoidFunction) => {
19+
browser.isVisible('[data-id="remixIdeSidePanel"]', (result) => {
20+
if (result.value) {
21+
browser.element('css selector', '[data-id="verticalIconsKindfilePanel"] img[data-id="selected"]', (result) => {
22+
if (result.status === 0) {
23+
bdone()
24+
} else browser.clickLaunchIcon('filePanel').perform(() => {
25+
bdone()
26+
})
27+
})
28+
} else {
29+
browser.clickLaunchIcon('filePanel').perform(() => {
30+
bdone()
31+
})
32+
}
33+
})
34+
})
35+
.perform(() => {
36+
let attempts = 0
37+
const maxAttempts = 200
38+
39+
const expandNextClosedFolder = () => {
40+
if (attempts >= maxAttempts) {
41+
if (done) done()
42+
return
43+
}
44+
attempts++
45+
46+
const closedFolderSelector = targetDirectory
47+
? `li[data-id*="treeViewLitreeViewItem${targetDirectory}"] .fa-folder:not(.fa-folder-open)`
48+
: 'li[data-id*="treeViewLitreeViewItem"] .fa-folder:not(.fa-folder-open)'
49+
50+
browser.element('css selector', closedFolderSelector, (result) => {
51+
if (result.status === 0 && result.value) {
52+
// Found a closed folder icon, now find its parent li element and click it
53+
browser.elementIdElement((result.value as any)['element-6066-11e4-a52e-4f735466cecf'], 'xpath', './..', (parentResult) => {
54+
if (parentResult.status === 0) {
55+
browser.elementIdClick((parentResult.value as any)['element-6066-11e4-a52e-4f735466cecf'])
56+
.pause(100) // Wait for folder to expand and DOM to update
57+
.perform(() => expandNextClosedFolder()) // Look for next closed folder
58+
} else {
59+
// Failed to find parent, try alternative approach
60+
browser.click(closedFolderSelector)
61+
.pause(100)
62+
.perform(() => expandNextClosedFolder()) // recursive call
63+
}
64+
})
65+
} else {
66+
if (done) done()
67+
}
68+
})
69+
}
70+
71+
expandNextClosedFolder()
72+
})
73+
}
74+
75+
module.exports = ExpandAllFolders

apps/remix-ide-e2e/src/tests/ai_panel.test.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const sources = [
88
{ 'Untitled.sol': { content: examples.ballot.content } }
99
]
1010

11-
module.exports = {
11+
const tests = {
1212
'@disabled': true,
1313
before: function (browser: NightwatchBrowser, done: VoidFunction) {
1414
init(browser, done)
@@ -271,3 +271,18 @@ module.exports = {
271271
.waitForElementNotVisible('*[data-id="remix-ai-assistant"]', 5000)
272272
},
273273
}
274+
275+
const branch = process.env.CIRCLE_BRANCH
276+
const runTestsConditions = branch && (branch === 'master' || branch === 'remix_live' || branch.includes('remix_beta') || branch.includes('metamask'))
277+
278+
const checkBrowserIsChrome = function (browser: NightwatchBrowser) {
279+
return browser.browserName.indexOf('chrome') > -1
280+
}
281+
282+
if (!checkBrowserIsChrome(browser)) {
283+
module.exports = {}
284+
} else {
285+
module.exports = {
286+
...(branch ? (runTestsConditions ? tests : {}) : tests)
287+
};
288+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'use strict'
2+
import { NightwatchBrowser } from 'nightwatch'
3+
import init from '../helpers/init'
4+
5+
module.exports = {
6+
'@disabled': true,
7+
before: function (browser: NightwatchBrowser, done: VoidFunction) {
8+
init(browser, done)
9+
},
10+
11+
'Should expand all folders in the file explorer': function (browser: NightwatchBrowser) {
12+
browser
13+
.clickLaunchIcon('filePanel')
14+
.waitForElementVisible('*[data-id="treeViewLitreeViewItemcontracts"]')
15+
.waitForElementVisible('*[data-id="treeViewLitreeViewItemscripts"]')
16+
.expandAllFolders()
17+
.pause(2000)
18+
.isVisible({
19+
selector: '*[data-id="treeViewLitreeViewItemcontracts"] .fa-folder-open',
20+
timeout: 5000,
21+
suppressNotFoundErrors: true
22+
})
23+
.isVisible({
24+
selector: '*[data-id="treeViewLitreeViewItemscripts"] .fa-folder-open',
25+
timeout: 5000,
26+
suppressNotFoundErrors: true
27+
})
28+
},
29+
30+
'Should expand all folders within a specific directory': function (browser: NightwatchBrowser) {
31+
browser
32+
.clickLaunchIcon('filePanel')
33+
.addFile('package.json', sources[0]['package.json'])
34+
.addFile('Untitled10.sol', sources[0]['Untitled10.sol'])
35+
.waitForElementVisible('*[data-id="treeViewLitreeViewItem.deps"]')
36+
.expandAllFolders()
37+
.pause(5000)
38+
}
39+
}
40+
const sources = [
41+
{
42+
'Untitled10.sol': { content: 'pragma solidity ^0.8.0; import "@module_remapping/token/ERC20/ERC20.sol"; contract test15 {}' },
43+
'package.json': { content: `{
44+
"dependencies": {
45+
"@module_remapping": "npm:@openzeppelin/contracts@^4.9.0"
46+
}
47+
}` }
48+
}
49+
]

apps/remix-ide-e2e/src/tests/solidityImport.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ module.exports = {
100100
.click('li[data-id="treeViewLitreeViewItemREADME.txt"')
101101
.addFile('Untitled9.sol', sources[8]['Untitled9.sol'])
102102
// avoid invalid source issues
103+
.expandAllFolders()
103104
.isVisible({
104105
selector: '*[data-id="treeViewLitreeViewItem.deps/npm/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"]',
105106
timeout: 120000,
@@ -108,6 +109,7 @@ module.exports = {
108109
.clickLaunchIcon('solidity')
109110
.click('[data-id="compilerContainerCompileBtn"]')
110111
.clickLaunchIcon('filePanel')
112+
.expandAllFolders()
111113
.isVisible({
112114
selector: '*[data-id="treeViewLitreeViewItem.deps/npm/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"]',
113115
timeout: 120000,
@@ -126,7 +128,8 @@ module.exports = {
126128
.clickLaunchIcon('filePanel')
127129
.click('li[data-id="treeViewLitreeViewItemREADME.txt"')
128130
.addFile('package.json', sources[9]['package.json'])
129-
.addFile('Untitled10.sol', sources[9]['Untitled10.sol'])
131+
.addFile('Untitled10.sol', sources[9]['Untitled10.sol'])
132+
.expandAllFolders()
130133
// avoid invalid source issues
131134
.isVisible({
132135
selector: '*[data-id="treeViewLitreeViewItem.deps/npm/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"]',
@@ -136,6 +139,7 @@ module.exports = {
136139
.clickLaunchIcon('solidity')
137140
.click('[data-id="compilerContainerCompileBtn"]')
138141
.clickLaunchIcon('filePanel')
142+
.expandAllFolders()
139143
.isVisible({
140144
selector: '*[data-id="treeViewLitreeViewItem.deps/npm/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"]',
141145
timeout: 120000,

apps/remix-ide-e2e/src/tests/solidityUnittests.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ module.exports = {
192192
.modalFooterOKClick('TemplatesSelection')
193193
.pause(3000)
194194
.currentWorkspaceIs('workspace_new')
195+
.expandAllFolders()
195196
.waitForElementVisible('li[data-id="treeViewLitreeViewItem.deps/remix-tests/remix_tests.sol"]')
196197
.waitForElementVisible('li[data-id="treeViewLitreeViewItem.deps/remix-tests/remix_accounts.sol"]')
197198
.openFile('.deps/remix-tests/remix_tests.sol')

apps/remix-ide-e2e/src/types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ declare module 'nightwatch' {
8484
addFileSnekmate: (name: string, content: NightwatchContractContent) => NightwatchBrowser
8585
selectFiles: (selelectedElements: any[]) => NightwatchBrowser
8686
waitForCompilerLoaded: () => NightwatchBrowser
87+
expandAllFolders: (targetDirectory?: string) => NightwatchBrowser
8788
}
8889

8990
export interface NightwatchBrowser {

libs/remix-ui/workspace/src/lib/reducers/workspace.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,8 @@ export const browserReducer = (state = browserInitialState, action: Actions) =>
337337

338338
const check = checkCurrentParentPathInView(payload, state.mode === 'browser' ? state.browser.expandPath : state.localhost.expandPath)
339339
const fd = fileAdded(state, payload)
340-
const browserExpandPath = state.mode === 'browser' && !isElectron() && check.inView ? [...new Set([...state.browser.expandPath, payload])] : state.browser.expandPath
341-
const localhostExpandPath = state.mode === 'localhost' && check.inView ? [...new Set([...state.localhost.expandPath, payload])] : state.localhost.expandPath
340+
const browserExpandPath = state.mode === 'browser' && !isElectron() && check.inView && !payload.includes('.deps') ? [...new Set([...state.browser.expandPath, payload])] : state.browser.expandPath
341+
const localhostExpandPath = state.mode === 'localhost' && check.inView && !payload.includes('.deps') ? [...new Set([...state.localhost.expandPath, payload])] : state.localhost.expandPath
342342
const flatTree = flattenTree(fd, state.mode === 'browser'? browserExpandPath : localhostExpandPath)
343343
return {
344344
...state,
@@ -373,8 +373,8 @@ export const browserReducer = (state = browserInitialState, action: Actions) =>
373373
const inView = check.inView || check.rootViewToAdd
374374
payload.folderPath = check.inView ? payload.folderPath : check.rootViewToAdd ? check.rootFolder : ''
375375

376-
const browserExpandPath = state.mode === 'browser' && !isElectron() && inView ? [...new Set([...state.browser.expandPath, payload.folderPath])] : state.browser.expandPath
377-
const localhostExpandPath = state.mode === 'localhost' && inView ? [...new Set([...state.localhost.expandPath, payload.folderPath])] : state.localhost.expandPath
376+
const browserExpandPath = state.mode === 'browser' && !isElectron() && inView && !payload.folderPath.includes('.deps') ? [...new Set([...state.browser.expandPath, payload.folderPath])] : state.browser.expandPath
377+
const localhostExpandPath = state.mode === 'localhost' && inView && !payload.folderPath.includes('.deps') ? [...new Set([...state.localhost.expandPath, payload.folderPath])] : state.localhost.expandPath
378378
const flatTree = flattenTree(fd, state.mode === 'browser'? browserExpandPath : localhostExpandPath)
379379
return {
380380
...state,

libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -659,15 +659,15 @@ export function Workspace() {
659659

660660
const uploadFile = (target) => {
661661
const parentFolder = getFocusedFolder()
662-
const expandPath = [...new Set([...global.fs.browser.expandPath, parentFolder])]
662+
const expandPath = [...new Set([...global.fs.browser.expandPath, parentFolder].filter(path => !path.includes('.deps')))]
663663

664664
global.dispatchHandleExpandPath(expandPath)
665665
global.dispatchUploadFile(target, parentFolder)
666666
}
667667

668668
const uploadFolder = (target) => {
669669
const parentFolder = getFocusedFolder()
670-
const expandPath = [...new Set([...global.fs.browser.expandPath, parentFolder])]
670+
const expandPath = [...new Set([...global.fs.browser.expandPath, parentFolder].filter(path => !path.includes('.deps')))]
671671

672672
global.dispatchHandleExpandPath(expandPath)
673673
global.dispatchUploadFolder(target, parentFolder)
@@ -810,7 +810,7 @@ export function Workspace() {
810810

811811
const handleNewFileInput = async (parentFolder?: string) => {
812812
if (!parentFolder) parentFolder = getFocusedFolder()
813-
const expandPath = [...new Set([...global.fs.browser.expandPath, parentFolder])]
813+
const expandPath = [...new Set([...global.fs.browser.expandPath, parentFolder].filter(path => !path.includes('.deps')))]
814814

815815
await global.dispatchAddInputField(parentFolder, 'file')
816816
global.dispatchHandleExpandPath(expandPath)
@@ -820,7 +820,7 @@ export function Workspace() {
820820
const handleNewFolderInput = async (parentFolder?: string) => {
821821
if (!parentFolder) parentFolder = getFocusedFolder()
822822
else if (parentFolder.indexOf('.sol') !== -1 || parentFolder.indexOf('.js') !== -1) parentFolder = extractParentFromKey(parentFolder)
823-
const expandPath = [...new Set([...global.fs.browser.expandPath, parentFolder])]
823+
const expandPath = [...new Set([...global.fs.browser.expandPath, parentFolder].filter(path => !path.includes('.deps')))]
824824

825825
await global.dispatchAddInputField(parentFolder, 'folder')
826826
global.dispatchHandleExpandPath(expandPath)

0 commit comments

Comments
 (0)