Skip to content

Commit 96de14d

Browse files
committed
Enclose the whole interaction with the EditorAction menu in the
conditional wait to avoid having some stale reference when trying to click on them after we found them. Signed-off-by: Aurélien Pupier <[email protected]>
1 parent 29964d8 commit 96de14d

File tree

3 files changed

+62
-31
lines changed

3 files changed

+62
-31
lines changed

src/ui-test/tests/deploy.kubernetes.run.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
} from 'vscode-extension-tester';
2525
import { killTerminal, waitUntilTerminalHasText } from '../utils';
2626
import { CAMEL_ROUTE_YAML_WITH_SPACE } from '../variables';
27-
import { actionAvailable } from './helper/Awaiters';
27+
import { actionAvailable as clickOnEditorAction } from './helper/Awaiters';
2828

2929
/**
3030
* Note: OC login needs to be done before executing this test for deployment into OpenShift
@@ -52,10 +52,8 @@ describe('Camel standalone file deployment using Camel JBang Kubernetes Run', fu
5252

5353
it('Deploy integration to OpenShift or Kubernetes (Minikube)', async function () {
5454
await VSBrowser.instance.driver.sleep(500);
55-
await actionAvailable(editorView, 'Deploy Integration with Apache Camel Kubernetes Run');
56-
const action = (await editorView.getAction('Deploy Integration with Apache Camel Kubernetes Run')) as EditorAction;
57-
await action.click();
58-
await waitUntilTerminalHasText(action.getDriver(), ['Hello Camel from'], 10_000, 900_000);
55+
await clickOnEditorAction(editorView, 'Deploy Integration with Apache Camel Kubernetes Run');
56+
await waitUntilTerminalHasText(VSBrowser.instance.driver, ['Hello Camel from'], 10_000, 900_000);
5957
});
6058

6159
});

src/ui-test/tests/editor.actions.test.ts

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {
3434
isCamelVersionProductized,
3535
} from '../utils';
3636
import { CAMEL_RUN_DEBUG_FOLDER_ACTION_LABEL, CAMEL_RUN_DEBUG_WORKSPACE_ACTION_LABEL, CAMEL_RUN_FOLDER_ACTION_LABEL, CAMEL_RUN_WORKSPACE_ACTION_LABEL, TOP_ROUTE_1 } from '../variables';
37-
import { actionAvailable } from './helper/Awaiters';
37+
import { openDropDownMenuEditorAction, selectDropDownMenuEditorAction } from './helper/Awaiters';
3838

3939
describe('Camel file editor test', function () {
4040

@@ -68,26 +68,22 @@ describe('Camel file editor test', function () {
6868
if (process.platform === "darwin"){
6969
this.skip();
7070
}
71-
await actionAvailable(editorView, "Run or Debug...");
72-
const action = (await editorView.getAction("Run or Debug...")) as EditorActionDropdown;
73-
const menu = await action.open();
74-
expect(await menu.hasItem(CAMEL_RUN_ACTION_LABEL)).true;
75-
expect(await menu.hasItem(CAMEL_RUN_WORKSPACE_ACTION_LABEL)).true;
76-
expect(await menu.hasItem(CAMEL_RUN_FOLDER_ACTION_LABEL)).true;
77-
await menu.close();
71+
const menu = await openDropDownMenuEditorAction(editorView, "Run or Debug...");
72+
expect(await menu?.hasItem(CAMEL_RUN_ACTION_LABEL)).true;
73+
expect(await menu?.hasItem(CAMEL_RUN_WORKSPACE_ACTION_LABEL)).true;
74+
expect(await menu?.hasItem(CAMEL_RUN_FOLDER_ACTION_LABEL)).true;
75+
await menu?.close();
7876
});
7977

8078
it('Debug and Run actions are available', async function () {
8179
if (process.platform === "darwin"){
8280
this.skip();
8381
}
84-
await actionAvailable(editorView, "Run or Debug...");
85-
const action = (await editorView.getAction("Run or Debug...")) as EditorActionDropdown;
86-
const menu = await action.open();
87-
expect(await menu.hasItem(CAMEL_RUN_DEBUG_ACTION_LABEL)).true;
88-
expect(await menu.hasItem(CAMEL_RUN_DEBUG_WORKSPACE_ACTION_LABEL)).true;
89-
expect(await menu.hasItem(CAMEL_RUN_DEBUG_FOLDER_ACTION_LABEL)).true;
90-
await menu.close();
82+
const menu = await openDropDownMenuEditorAction(editorView, "Run or Debug...");
83+
expect(await menu?.hasItem(CAMEL_RUN_DEBUG_ACTION_LABEL)).true;
84+
expect(await menu?.hasItem(CAMEL_RUN_DEBUG_WORKSPACE_ACTION_LABEL)).true;
85+
expect(await menu?.hasItem(CAMEL_RUN_DEBUG_FOLDER_ACTION_LABEL)).true;
86+
await menu?.close();
9187
});
9288

9389
const runActionLabels = [
@@ -101,10 +97,7 @@ describe('Camel file editor test', function () {
10197
if (process.platform === "darwin") {
10298
this.skip();
10399
}
104-
await actionAvailable(editorView, "Run or Debug...");
105-
const action = (await editorView.getAction("Run or Debug...")) as EditorActionDropdown;
106-
const menu = await action.open();
107-
await menu.select(runActionLabels.label);
100+
await selectDropDownMenuEditorAction(editorView, "Run or Debug...", runActionLabels.label);
108101
await waitUntilTerminalHasText(driver, runActionLabels.terminalText, 2000, 120000);
109102
await killTerminal();
110103
});
@@ -124,10 +117,7 @@ describe('Camel file editor test', function () {
124117
if (process.platform === "darwin"){
125118
this.skip();
126119
}
127-
await actionAvailable(editorView, "Run or Debug...");
128-
const action = (await editorView.getAction("Run or Debug...")) as EditorActionDropdown;
129-
const menu = await action.open();
130-
await menu.select(debugActionLabels.label);
120+
await selectDropDownMenuEditorAction(editorView, "Run or Debug...", debugActionLabels.label);
131121

132122
await waitUntilTerminalHasText(driver, debugActionLabels.terminalText, 2000, 120000);
133123

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,56 @@
11
import waitUntil from 'async-wait-until';
2-
import { EditorView } from 'vscode-extension-tester';
2+
import { ContextMenu, EditorView } from 'vscode-extension-tester';
33

44

5-
export async function actionAvailable(editorView: EditorView, actionLabel: string) {
5+
export async function clickOnEditorAction(editorView: EditorView, actionLabel: string) {
66
await waitUntil(async () => {
77
try {
8-
return await editorView.getAction(actionLabel) !== undefined;
8+
const action = await editorView.getAction(actionLabel);
9+
if (action !== undefined) {
10+
await action.click();
11+
return true;
12+
} else {
13+
return false;
14+
}
915
} catch {
1016
return false;
1117
}
1218
});
1319
}
20+
21+
export async function openDropDownMenuEditorAction(editorView: EditorView, actionLabel: string) :Promise<ContextMenu | undefined>{
22+
let contextMenu : ContextMenu | undefined = undefined;
23+
await waitUntil(async () => {
24+
try {
25+
const action = await editorView.getAction(actionLabel);
26+
if (action !== undefined) {
27+
contextMenu = await action.open();
28+
return true;
29+
} else {
30+
return false;
31+
}
32+
} catch {
33+
return false;
34+
}
35+
});
36+
return contextMenu;
37+
}
38+
39+
export async function selectDropDownMenuEditorAction(editorView: EditorView, actionLabel: string, subActionLabel: string) :Promise<ContextMenu | undefined>{
40+
let contextMenu : ContextMenu | undefined = undefined;
41+
await waitUntil(async () => {
42+
try {
43+
const action = await editorView.getAction(actionLabel);
44+
if (action !== undefined) {
45+
contextMenu = await action.open();
46+
await contextMenu.select(subActionLabel);
47+
return true;
48+
} else {
49+
return false;
50+
}
51+
} catch {
52+
return false;
53+
}
54+
});
55+
return contextMenu;
56+
}

0 commit comments

Comments
 (0)