Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: DH-18428: e2e tests #213

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ To run using `VS Code` debugger:
npm run test:e2e
```

or with flags

```sh
npm run test:e2e -- -s --spec test
```

4. You should see the tests start and `VS Code` stop at the breakpoint.

## VSCE
Expand Down
93 changes: 93 additions & 0 deletions e2e/specs/__snapshots__/test.e2e.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Snapshot v1

exports[`panels > should open panels > 1: Tab groups - initial load 1`] = `
[
{
"ariaLabel": "simple_ticking3.py",
"isSelected": true,
"text": "simple_ticking3.py",
},
{
"ariaLabel": "t1, Editor Group 2",
"text": "t1",
},
{
"ariaLabel": "t2, Editor Group 2",
"text": "t2",
},
{
"ariaLabel": "t3, Editor Group 2",
"isSelected": true,
"text": "t3",
},
]
`;

exports[`panels > should open panels > 2: Tab groups - after clicking t1 1`] = `
[
{
"ariaLabel": "simple_ticking3.py",
"isSelected": true,
"text": "simple_ticking3.py",
},
{
"ariaLabel": "t1, Editor Group 2",
"isSelected": true,
"text": "t1",
},
{
"ariaLabel": "t2, Editor Group 2",
"text": "t2",
},
{
"ariaLabel": "t3, Editor Group 2",
"text": "t3",
},
]
`;

exports[`panels > should open panels > 3: Tab groups - after closing t1 and t2 1`] = `
[
{
"ariaLabel": "simple_ticking3.py, Editor Group 1",
"isSelected": true,
"text": "simple_ticking3.py",
},
{
"ariaLabel": "t3, Editor Group 2",
"isSelected": true,
"text": "t3",
},
{
"ariaLabel": "t1, Editor Group 2",
"text": "t1",
},
{
"ariaLabel": "t2, Editor Group 2",
"text": "t2",
},
]
`;

exports[`panels > should open panels > 4: Tab groups - after dragging t1 to a new tab group 1`] = `
[
{
"ariaLabel": "simple_ticking3.py, Editor Group 1",
"isSelected": true,
"text": "simple_ticking3.py",
},
{
"ariaLabel": "t3, Editor Group 2",
"isSelected": true,
"text": "t3",
},
{
"ariaLabel": "t1, Editor Group 2",
"text": "t1",
},
{
"ariaLabel": "t2, Editor Group 2",
"text": "t2",
},
]
`;
104 changes: 99 additions & 5 deletions e2e/specs/test.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { browser, expect } from '@wdio/globals';

Check failure on line 1 in e2e/specs/test.e2e.ts

View workflow job for this annotation

GitHub Actions / call-e2e / e2e

Failed Test: should open panels

should open panels: expect(received).toBe(expected) // Object.is equality - Expected - 13 + Received + 0 [ { "ariaLabel": "simple_ticking3.py", "isSelected": true, "text": "simple_ticking3.py", }, - { - "ariaLabel": "t1, Editor Group 2", - "text": "t1", - }, - { - "ariaLabel": "t2, Editor Group 2", - "text": "t2", - }, - { - "ariaLabel": "t3, Editor Group 2", - "isSelected": true, - "text": "t3", - }, ] - Error: expect(received).toBe(expected) // Object.is equality - Expected - 13 + Received + 0 [ { "ariaLabel": "simple_ticking3.py", "isSelected": true, "text": "simple_ticking3.py", }, - { - "ariaLabel": "t1, Editor Group 2", - "text": "t1", - }, - { - "ariaLabel": "t2, Editor Group 2", - "text": "t2", - }, - { - "ariaLabel": "t3, Editor Group 2", - "isSelected": true, - "text": "t3", - }, ] at Context.<anonymous> (/home/runner/work/vscode-deephaven/vscode-deephaven/e2e/specs/test.e2e.ts:74:43)
import {
closeAllEditors,
hasConnectionStatusBarItem,
Expand All @@ -8,6 +8,11 @@
setConfigSectionSettings,
} from '../testUtils';

afterEach(async () => {
await resetConfig();
await closeAllEditors();
});

// There are some tests that can be used for reference in:
// https://github.com/stateful/vscode-marquee/blob/main/test/specs and
// https://github.com/webdriverio-community/wdio-vscode-service/blob/main/test/specs
Expand All @@ -30,11 +35,6 @@
await openEditors(['test.txt', 'test.groovy', 'test.py']);
});

afterEach(async () => {
await resetConfig();
await closeAllEditors();
});

['test.groovy', 'test.py'].forEach(supportedTitle => {
it(`should only be visible when a supported file type is active: ${supportedTitle}`, async () => {
const workbench = await browser.getWorkbench();
Expand All @@ -51,3 +51,97 @@
});
});
});

describe('panels', () => {
beforeEach(async () => {
await setConfigSectionSettings(
'coreServers',
PYTHON_AND_GROOVY_SERVER_CONFIG
);
await openEditors(['simple_ticking3.py']);
});

it.only('should open panels', async () => {
const workbench = await browser.getWorkbench();

await workbench.getEditorView().openEditor('simple_ticking3.py');
await $('.codelens-decoration .codicon-run-all').click();

// We need this to wait until panels load
await workbench.getAllWebviews();

/* Test 1 */
expect(await getTabs().map(parseTab)).toMatchSnapshot(
'1: Tab groups - initial load'
);

/* Test 2 */
await getTab('t1', 2).click();

expect(await getTabs().map(parseTab)).toMatchSnapshot(
'2: Tab groups - after clicking t1'
);

/* Test 3 */
await getTabCloseAction('t1', 2).click();
await getTabCloseAction('t2', 2).click();

await getTab('simple_ticking3.py', 1).click();
await $('.codelens-decoration .codicon-run-all').click();

expect(await getTabs().map(parseTab)).toMatchSnapshot(
'3: Tab groups - re-run after closing t1 and t2'
);
});
});

function getTab(
title: string,
editorGroup: number
): ReturnType<WebdriverIO.Browser['$']> {
const selector =
editorGroup > 1 ? `${title}, Editor Group ${editorGroup}` : title;
return $(`.tab[aria-label="${selector}"`);
}

function getTabCloseAction(
title: string,
editorGroup: number
): ReturnType<WebdriverIO.Browser['$']> {
return getTab(title, editorGroup).$('a.codicon-close');
}

function getTabs(): ReturnType<WebdriverIO.Browser['$$']> {
return $$('.tab');
}

async function parseTab(tab: WebdriverIO.Element): Promise<{
text: string;
ariaLabel: string;
isSelected?: true;
}> {
const text = await tab.getText();
const ariaLabel = await tab.getAttribute('aria-label');
const isSelected = (await tab.getAttribute('aria-selected')) === 'true';

return isSelected ? { text, ariaLabel, isSelected } : { text, ariaLabel };
}

// async function getTabs(): Promise<
// {
// text: string;
// ariaLabel: string;
// isSelected?: true;
// ref: WebdriverIO.Element;
// }[]
// > {
// return $$('.tab').map(parseTab);
// }

// function stripRef<T extends { ref: WebdriverIO.Element }>(
// obj: T
// ): Omit<T, 'ref'> {
// // eslint-disable-next-line no-unused-vars
// const { ref, ...rest } = obj;
// return rest;
// }
7 changes: 7 additions & 0 deletions e2e/test-ws/simple_ticking3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from deephaven import time_table

t1 = time_table("PT2S")

t2 = time_table("PT2S")

t3 = time_table("PT2S")
59 changes: 58 additions & 1 deletion e2e/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as vscode from 'vscode';

// Note that calls to `browser.executeWorkbench` cannot reference any variables
// or functions from the outside scope. They only have access to variables
// passed in as additional parameters.
// passed in as additional parameters. Return values need to be JSON serializable.
// See https://www.npmjs.com/package/wdio-vscode-service#accessing-vscode-apis

// CONFIG_ROOT_KEY and ConfigSectionKey are based on `src/common/constants.ts`.
Expand Down Expand Up @@ -36,6 +36,63 @@ export async function findConnectionStatusBarItem(): Promise<
);
}

type SerializableTabGroup = {
viewColumn: vscode.ViewColumn;
isActive: boolean;
activeTab?: string;
tabs: string[];
};

/** Map of SerializableTabGroups keyed by their respective ViewColumn. */
type SerializableTabGroupMap = Record<vscode.ViewColumn, SerializableTabGroup>;

export async function getDhTabGroups(): Promise<SerializableTabGroupMap> {
// See note about `executeWorkbench` at top of this file.
return browser.executeWorkbench(async (vs: typeof vscode) => {
/*
* Check if the tab is a Deephaven panel tab. Note that `executeWorkbench`
* has no access to functions defined outside of the calback closer, so this
* has to be defined here.
*/
function isDhPanelTab(tab: vscode.Tab): boolean {
const { input } = tab;

return (
input != null &&
typeof input === 'object' &&
'viewType' in input &&
typeof input.viewType === 'string' &&
input.viewType.endsWith('-dhPanel')
);
}

const tabGroups = {} as SerializableTabGroupMap;

for (const group of vs.window.tabGroups.all) {
const tabs: string[] = [];

for (const tab of group.tabs) {
if (isDhPanelTab(tab)) {
tabs.push(tab.label);
}
}

if (tabs.length === 0) {
continue;
}

tabGroups[group.viewColumn] = {
activeTab: group.activeTab?.label,
isActive: group.isActive,
tabs,
viewColumn: group.viewColumn,
};
}

return tabGroups;
});
}

/**
* Check if the connection status bar item is visible.
*/
Expand Down
Loading