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

feat: add webview with ability to change settings in runtime #9

Merged
merged 1 commit into from
Sep 27, 2024

Conversation

DudaGod
Copy link
Member

@DudaGod DudaGod commented Sep 20, 2024

What is done

Add webview to sidebar in order to change some settings (support repl and devtools right now) in runtime. Options are displayed as checkboxes and by default they are disabled. If user click on checkbox then the result is stored in a special workspace storage. For another workspace it will be clear.

These settings take precedence over the values in the config. Moreover checkboxes do not respond to a change in the config. For example if user set devtools: true for chrome and devtools: false for firefox then this will not affect the value of the checkboxes. It is possible to support this, but then I need to display checkboxes for each browser and with a large number of browsers, it will turn into a mess.

How it looks like:

webview_settings

@DudaGod DudaGod force-pushed the TESTPLANE-242.settings_side_bar branch 2 times, most recently from 96e1157 to 896b544 Compare September 20, 2024 13:50
@@ -0,0 +1,51 @@
body {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is css file for new webview in sidebar

@@ -0,0 +1,44 @@
// This script will be run within the webview itself
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is js file for new webview in sidebar (in which render setting elements: devtools and repl)

// It cannot access the main VS Code APIs directly.
(function () {
// eslint-disable-next-line no-undef
const vscode = acquireVsCodeApi();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

listenSettingsCheckbox();

// eslint-disable-next-line no-undef
window.addEventListener("message", event => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From vscode extension I send event to webview. Here I listen this event and modify checkboxes

// eslint-disable-next-line no-undef
for (const checkbox of document.querySelectorAll(".section_type_settings input[type=checkbox]")) {
checkbox.addEventListener("change", function (event) {
vscode.postMessage({
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When checkbox is clicked I send event to vscode in order to use it when run tests

@@ -30,10 +30,19 @@ export class TestingSideBar {
}

async runAllTests(): Promise<void> {
// in order to show test explorer actions
await this._sidebarView.elem.moveTo();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In some cases button Run tests can be hidden. So I move mouse to sidebar.


describe("Settings view", () => {
describe("devtools", () => {
it("should fail if option is not enabled", async () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In samples/settings-view option devtools is not specified. So this test should fail because grid is not run.

const outputText = await outputView.getText();

expect(outputText).toEqual(
expect.arrayContaining([expect.stringContaining("ECONNREFUSED 127.0.0.1:4444")]),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check that in logs exists log with this message (grid url is not available)

await sidebar.waitTestsRead();

const webview = await vscodePO.getWebviewByTitle("Testplane");
await webview.open();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should switch execution context to webview in order to be able to click on devtools checkbox

const webview = await vscodePO.getWebviewByTitle("Testplane");
await webview.open();
await browser.$("[settingname=devtools]").click();
await webview.close();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch execution context back

@DudaGod DudaGod force-pushed the TESTPLANE-242.settings_side_bar branch 15 times, most recently from 4f659b7 to 0eb024c Compare September 24, 2024 11:43
@DudaGod DudaGod force-pushed the TESTPLANE-242.settings_side_bar branch from 0eb024c to 6e07ae8 Compare September 27, 2024 10:44
@DudaGod DudaGod merged commit 8029237 into master Sep 27, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant