Skip to content

Commit 03e7292

Browse files
ci-botAniket-Engg
authored andcommitted
fix e2es for workspaces and workspaces.git
1 parent 5d5d101 commit 03e7292

File tree

3 files changed

+85
-66
lines changed

3 files changed

+85
-66
lines changed

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

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ module.exports = {
3232
.pause(100)
3333
.waitForElementVisible('*[data-id="treeViewLitreeViewItemcontracts"]')
3434
.waitForElementNotPresent('*[data-id="treeViewLitreeViewItem.git"]')
35-
.waitForElementNotVisible('[data-id="workspaceGitPanel"]')
35+
.waitForElementVisible('[data-id="treeViewDivtreeViewItemREADME.txt"]')
3636
},
3737
'Should add credentials #group1 #group2 #group3': function (browser: NightwatchBrowser) {
3838
browser
39-
.clickLaunchIcon('settings')
39+
.waitForElementVisible('*[data-id="topbar-settingsIcon"]')
40+
.click('*[data-id="topbar-settingsIcon"]')
4041
.setValue('[data-id="settingsTabGithubUsername"]', 'circleci')
4142
.setValue('[data-id="settingsTabGithubEmail"]', '[email protected]')
4243
.click('[data-id="settingsTabSaveGistToken"]')
@@ -45,7 +46,7 @@ module.exports = {
4546
'Should create and initialize a GIT repository #group1': function (browser: NightwatchBrowser) {
4647
browser
4748
.clickLaunchIcon('filePanel')
48-
.waitForElementNotVisible('[data-id="workspaceGitPanel"]')
49+
// .waitForElementNotVisible('[data-id="workspaceGitPanel"]')
4950
.click('*[data-id="workspacesSelect"]')
5051
.click('*[data-id="workspacecreate"]')
5152
.waitForElementPresent('*[data-id="create-blank"]')
@@ -81,15 +82,15 @@ module.exports = {
8182
'Should clone a repository #group2': function (browser: NightwatchBrowser) {
8283
browser
8384
.clickLaunchIcon('filePanel')
84-
.waitForElementVisible('[data-id="workspacesSelect"]')
85-
.click('[data-id="workspacesSelect"]')
86-
.waitForElementVisible('[data-id="workspaceclone"]')
87-
.click('[data-id="workspaceclone"]')
88-
.waitForElementVisible('[data-id="fileSystemModalDialogModalBody-react"]')
89-
.click('[data-id="fileSystemModalDialogModalBody-react"]')
85+
.waitForElementVisible('*[data-id="github-dropdown-toggle"]')
86+
.click('*[data-id="github-dropdown-toggle"]')
87+
.waitForElementVisible('*[data-id="github-dropdown-item-clone"]')
88+
.click('*[data-id="github-dropdown-item-clone"]')
89+
.waitForElementVisible('[data-id="topbarModalModalDialogModalBody-react"]')
90+
.click('[data-id="topbarModalModalDialogModalBody-react"]')
9091
.waitForElementVisible('[data-id="modalDialogCustomPromptTextClone"]')
9192
.setValue('[data-id="modalDialogCustomPromptTextClone"]', 'https://github.com/ethereum/awesome-remix')
92-
.click('[data-id="fileSystem-modal-footer-ok-react"]')
93+
.click('[data-id="topbarModal-modal-footer-ok-react"]')
9394
.waitForElementPresent('.fa-spinner')
9495
.pause(5000)
9596
.waitForElementNotPresent('.fa-spinner')
@@ -107,33 +108,37 @@ module.exports = {
107108

108109
'Should display non-clashing names for duplicate clone #group2': '' + function (browser: NightwatchBrowser) {
109110
browser
110-
.click('[data-id="workspacesSelect"]')
111-
.waitForElementVisible('[data-id="workspaceclone"]')
112-
.click('[data-id="workspaceclone"]')
113-
.waitForElementVisible('[data-id="fileSystemModalDialogModalBody-react"]')
114-
.click('[data-id="fileSystemModalDialogModalBody-react"]')
111+
.waitForElementVisible('*[data-id="github-dropdown-toggle"]')
112+
.click('*[data-id="github-dropdown-toggle"]')
113+
.waitForElementVisible('*[data-id="github-dropdown-item-clone"]')
114+
.click('*[data-id="github-dropdown-item-clone"]')
115+
.waitForElementVisible('[data-id="topbarModalModalDialogModalBody-react"]')
116+
.click('[data-id="topbarModalModalDialogModalBody-react"]')
115117
.waitForElementVisible('[data-id="modalDialogCustomPromptTextClone"]')
116118
.setValue('[data-id="modalDialogCustomPromptTextClone"]', 'https://github.com/ethereum/awesome-remix')
117-
.click('[data-id="fileSystem-modal-footer-ok-react"]')
119+
.click('[data-id="topbarModal-modal-footer-ok-react"]')
118120
.pause(5000)
119121
.waitForElementContainsText('[data-id="workspacesSelect"]', 'awesome-remix1')
120-
.click('[data-id="workspacesSelect"]')
121-
.waitForElementVisible('[data-id="workspaceclone"]')
122-
.click('[data-id="workspaceclone"]')
123-
.waitForElementVisible('[data-id="fileSystemModalDialogModalBody-react"]')
124-
.click('[data-id="fileSystemModalDialogModalBody-react"]')
122+
.waitForElementVisible('*[data-id="github-dropdown-toggle"]')
123+
.click('*[data-id="github-dropdown-toggle"]')
124+
.waitForElementVisible('*[data-id="github-dropdown-item-clone"]')
125+
.click('*[data-id="github-dropdown-item-clone"]')
126+
.waitForElementVisible('[data-id="topbarModalModalDialogModalBody-react"]')
127+
.click('[data-id="topbarModalModalDialogModalBody-react"]')
125128
.waitForElementVisible('[data-id="modalDialogCustomPromptTextClone"]')
126129
.setValue('[data-id="modalDialogCustomPromptTextClone"]', 'https://github.com/ethereum/awesome-remix')
127-
.click('[data-id="fileSystem-modal-footer-ok-react"]')
130+
.click('[data-id="topbarModal-modal-footer-ok-react"]')
128131
.pause(5000)
129132
.waitForElementContainsText('[data-id="workspacesSelect"]', 'awesome-remix2')
130-
.click('[data-id="workspacesSelect"]')
131-
.waitForElementVisible('[data-id="workspaceDropdownMenuIcon]"')
132-
.waitForElementVisible('[data-id="fileSystemModalDialogModalBody-react"]')
133-
.click('[data-id="fileSystemModalDialogModalBody-react"]')
133+
.waitForElementVisible('*[data-id="github-dropdown-toggle"]')
134+
.click('*[data-id="github-dropdown-toggle"]')
135+
.waitForElementVisible('*[data-id="github-dropdown-item-clone"]')
136+
.click('*[data-id="github-dropdown-item-clone"]')
137+
.waitForElementVisible('[data-id="topbarModalModalDialogModalBody-react"]')
138+
.click('[data-id="topbarModalModalDialogModalBody-react"]')
134139
.waitForElementVisible('[data-id="modalDialogCustomPromptTextClone"]')
135140
.setValue('[data-id="modalDialogCustomPromptTextClone"]', 'https://github.com/ethereum/awesome-remix')
136-
.click('[data-id="fileSystem-modal-footer-ok-react"]')
141+
.click('[data-id="topbarModal-modal-footer-ok-react"]')
137142
.pause(5000)
138143
.waitForElementContainsText('[data-id="workspacesSelect"]', 'awesome-remix3')
139144
.switchWorkspace('awesome-remix')
@@ -144,15 +149,15 @@ module.exports = {
144149

145150
'Should display error message in modal for failed clone #group2': function (browser: NightwatchBrowser) {
146151
browser
147-
.waitForElementVisible('[data-id="workspacesSelect"]')
148-
.click('[data-id="workspacesSelect"]')
149-
.waitForElementVisible('[data-id="workspaceclone"]')
150-
.click('[data-id="workspaceclone"]')
151-
.waitForElementVisible('[data-id="fileSystemModalDialogModalBody-react"]')
152-
.click('[data-id="fileSystemModalDialogModalBody-react"]')
152+
.waitForElementVisible('*[data-id="github-dropdown-toggle"]')
153+
.click('*[data-id="github-dropdown-toggle"]')
154+
.waitForElementVisible('*[data-id="github-dropdown-item-clone"]')
155+
.click('*[data-id="github-dropdown-item-clone"]')
156+
.waitForElementVisible('[data-id="topbarModalModalDialogModalBody-react"]')
157+
.click('[data-id="topbarModalModalDialogModalBody-react"]')
153158
.waitForElementVisible('[data-id="modalDialogCustomPromptTextClone"]')
154159
.setValue('[data-id="modalDialogCustomPromptTextClone"]', 'https://github.com/ethereum/non-existent-repo')
155-
.click('[data-id="fileSystem-modal-footer-ok-react"]')
160+
.click('[data-id="topbarModal-modal-footer-ok-react"]')
156161
.pause(5000)
157162
.waitForElementVisible('[data-id="cloneGitRepositoryModalDialogModalBody-react"]')
158163
.waitForElementContainsText('[data-id="cloneGitRepositoryModalDialogModalBody-react"]', 'An error occurred: Please check that you have the correct URL for the repo. If the repo is private, you need to add your github credentials (with the valid token permissions) in the Git plugin')
@@ -165,15 +170,16 @@ module.exports = {
165170
'Should show all cloned repo branches #group3': function (browser: NightwatchBrowser) {
166171
browser
167172
.clickLaunchIcon('filePanel')
168-
.waitForElementNotVisible('[data-id="workspaceGitPanel"]')
169-
.click('[data-id="workspacesSelect"]')
170-
.waitForElementVisible('[data-id="workspaceclone"]')
171-
.click('[data-id="workspaceclone"]')
172-
.waitForElementVisible('[data-id="fileSystemModalDialogModalBody-react"]')
173-
.click('[data-id="fileSystemModalDialogModalBody-react"]')
173+
// .waitForElementNotVisible('[data-id="workspaceGitPanel"]')
174+
.waitForElementVisible('*[data-id="github-dropdown-toggle"]')
175+
.click('*[data-id="github-dropdown-toggle"]')
176+
.waitForElementVisible('*[data-id="github-dropdown-item-clone"]')
177+
.click('*[data-id="github-dropdown-item-clone"]')
178+
.waitForElementVisible('[data-id="topbarModalModalDialogModalBody-react"]')
179+
.click('[data-id="topbarModalModalDialogModalBody-react"]')
174180
.waitForElementVisible('[data-id="modalDialogCustomPromptTextClone"]')
175181
.setValue('[data-id="modalDialogCustomPromptTextClone"]', 'https://github.com/ioedeveloper/test-branch-change')
176-
.click('[data-id="fileSystem-modal-footer-ok-react"]')
182+
.click('[data-id="topbarModal-modal-footer-ok-react"]')
177183
.waitForElementPresent('.fa-spinner')
178184
.pause(7000)
179185
.waitForElementNotPresent('.fa-spinner')

libs/remix-ui/top-bar/src/components/WorkspaceDropdown.tsx

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Dropdown, Overlay } from 'react-bootstrap'
55
import { remote } from '@remix-api'
66
import { TopbarContext } from '../context/topbarContext'
77
import { getWorkspaces } from 'libs/remix-ui/workspace/src/lib/actions'
8+
import { WorkspaceMetadata } from 'libs/remix-ui/workspace/src/lib/types'
89

910
interface Branch {
1011
name: string
@@ -31,7 +32,6 @@ interface WorkspacesDropdownProps {
3132
menuItems: MenuItem[]
3233
toggleDropdown: any
3334
showDropdown: boolean
34-
selectedWorkspace: any
3535
currentWorkspace: any
3636
NO_WORKSPACE: string
3737
switchWorkspace: any
@@ -63,11 +63,11 @@ function useClickOutside(refs: React.RefObject<HTMLElement>[], handler: () => vo
6363
}, [refs, handler])
6464
}
6565

66-
export const WorkspacesDropdown: React.FC<WorkspacesDropdownProps> = ({ menuItems, selectedWorkspace, NO_WORKSPACE, switchWorkspace, CustomToggle, createWorkspace, downloadCurrentWorkspace, restoreBackup, deleteAllWorkspaces, setCurrentMenuItemName, setMenuItems, renameCurrentWorkspace, deleteCurrentWorkspace }) => {
66+
export const WorkspacesDropdown: React.FC<WorkspacesDropdownProps> = ({ menuItems, NO_WORKSPACE, switchWorkspace, CustomToggle, createWorkspace, downloadCurrentWorkspace, restoreBackup, deleteAllWorkspaces, setCurrentMenuItemName, setMenuItems, renameCurrentWorkspace, deleteCurrentWorkspace }) => {
6767
const [showMain, setShowMain] = useState(false)
6868
const [openSub, setOpenSub] = useState<number | null>(null)
6969
const global = useContext(TopbarContext)
70-
70+
const [selectedWorkspace, setSelectedWorkspace] = useState<WorkspaceMetadata>(null)
7171
const mainRef = useRef<HTMLDivElement>(null)
7272
const subRefs = useMemo( // useMemo or else rules of hooks is broken.
7373
() => menuItems.map(() => React.createRef<HTMLDivElement>()),
@@ -85,31 +85,44 @@ export const WorkspacesDropdown: React.FC<WorkspacesDropdownProps> = ({ menuItem
8585
}, [])
8686

8787
useEffect(() => {
88-
global.plugin.on('filePanel', 'setWorkspace', (workspace) => {
88+
global.plugin.on('filePanel', 'setWorkspace', async(workspace) => {
8989
setTogglerText(workspace.name)
90+
let workspaces = []
91+
const fromLocalStore = localStorage.getItem('currentWorkspace')
92+
workspaces = await getWorkspaces()
93+
const current = workspaces.find((workspace) => workspace.name === fromLocalStore)
94+
setSelectedWorkspace(current)
9095
})
96+
97+
return () => {
98+
global.plugin.off('filePanel', 'setWorkspace')
99+
}
91100
}, [global.plugin.filePanel.currentWorkspaceMetadata])
92101

93102
useEffect(() => {
94-
const run = async () => {
95-
let workspaces = []
96-
workspaces = await getWorkspaces()
97-
const updated = workspaces.map((workspace) => {
98-
(workspace as any).submenu = subItems
99-
return workspace as any
100-
})
101-
setMenuItems(updated)
103+
let workspaces: any[] = []
104+
105+
try {
106+
setTimeout(async () => {
107+
workspaces = await getWorkspaces()
108+
const updated = workspaces.map((workspace) => {
109+
(workspace as any).submenu = subItems
110+
return workspace as any
111+
})
112+
setMenuItems(updated)
113+
}, 150)
114+
} catch (error) {
115+
console.info('Error fetching workspaces:', error)
102116
}
103-
run()
104117
}, [showMain])
105118

106119
useClickOutside([mainRef, ...subRefs], () => {
107120
setShowMain(false)
108-
setOpenSub(null);
121+
setOpenSub(null)
109122
})
110123

111124
const toggleSub = (idx: number) =>
112-
setOpenSub(prev => (prev === idx ? null : idx));
125+
setOpenSub(prev => (prev === idx ? null : idx))
113126

114127
return (
115128
<div ref={mainRef} >
@@ -124,10 +137,15 @@ export const WorkspacesDropdown: React.FC<WorkspacesDropdownProps> = ({ menuItem
124137
data-id="workspacesMenuDropdown"
125138
as={CustomToggle}
126139
id="dropdown-custom-components"
127-
className="btn btn-light btn-block w-100 d-inline-block border border-dark form-control"
128-
icon={selectedWorkspace && selectedWorkspace.isGitRepo ? 'far fa-code-branch' : null}
140+
className="btn btn-light btn-sm btn-block w-100 d-inline-block border border-dark form-control"
141+
icon={selectedWorkspace && selectedWorkspace.isGitRepo ? 'fas fa-code-branch' : null}
129142
>
130-
{togglerText}
143+
<div
144+
data-id="workspacesSelect-togglerText"
145+
className="text-truncate d-flex flex-row align-items-center justify-content-between"
146+
>
147+
{togglerText}
148+
</div>
131149
</Dropdown.Toggle>
132150

133151
<Dropdown.Menu

libs/remix-ui/top-bar/src/lib/remix-ui-topbar.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function RemixUiTopbar () {
2929
const LOCALHOST = ' - connect to localhost - '
3030
const NO_WORKSPACE = ' - none - '
3131
const ROOT_PATH = '/'
32-
const [selectedWorkspace, setSelectedWorkspace] = useState<WorkspaceMetadata>(null)
32+
3333
const [currentWorkspace, setCurrentWorkspace] = useState<string>(NO_WORKSPACE)
3434
const [currentMenuItemName, setCurrentMenuItemName] = useState<string>(null)
3535
const [currentTheme, setCurrentTheme] = useState<any>(null)
@@ -53,12 +53,10 @@ export function RemixUiTopbar () {
5353
const handleLoginSuccess = (user: GitHubUser, token: string) => {
5454
setUser(user);
5555
setError(null);
56-
console.log('Login successful:', user);
5756
};
5857

5958
const handleLoginError = (error: string) => {
6059
setError(error);
61-
console.error('Login failed:', error);
6260
};
6361

6462
const handleLogout = () => {
@@ -75,10 +73,8 @@ export function RemixUiTopbar () {
7573

7674
useEffect(() => {
7775
const current = localStorage.getItem('currentWorkspace')
78-
const workspace = plugin.workspaces.find((workspace) => workspace.name === current)
79-
setSelectedWorkspace(workspace)
8076
setCurrentWorkspace(current)
81-
}, [plugin.workspaces])
77+
}, [plugin.filePanel.workspaces])
8278

8379
useEffect(() => {
8480
const run = async () => {
@@ -467,7 +463,6 @@ export function RemixUiTopbar () {
467463
menuItems={menuItems}
468464
toggleDropdown={toggleDropdown}
469465
showDropdown={showDropdown}
470-
selectedWorkspace={selectedWorkspace}
471466
currentWorkspace={currentWorkspace}
472467
NO_WORKSPACE={NO_WORKSPACE}
473468
switchWorkspace={switchWorkspace}

0 commit comments

Comments
 (0)