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
Merged
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
7 changes: 2 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ jobs:
test:
strategy:
matrix:
# TODO: return windows-latest
os: [ubuntu-latest, macos-latest]
# TODO: return windows-latest, ubuntu-latest
os: [macos-latest]
node-version: [20.x]
include:
- os: ubuntu-latest
node-version: 18.x
vscodeVersion:
- stable

Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ vscode.d.ts
samples/**/.*
.wdio*
.tmp
tests/e2e/screens-on-fail
tests/e2e/**/screens-on-fail
51 changes: 51 additions & 0 deletions media/settings-view/main.css
Original file line number Diff line number Diff line change
@@ -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

margin: 0;
padding: 0;
}

.section__header {
font-size: 11px;
margin: 10px 0 3px 8px;
font-weight: 700;
color: var(--vscode-editor-inlineValuesForeground);
text-transform: uppercase;
}

.section__list {
display: flex;
flex-direction: column;
}

.section__list-item {
height: 22px;
line-height: 22px;
padding-right: 2px;
padding-left: 8px;
display: flex;
align-items: center;
box-sizing: border-box;
width: 100%;
white-space: nowrap;
flex: 0;
cursor: pointer;
}

.section__list-item:hover {
background-color: #e8e8e8;
}

body[data-vscode-theme-kind="vscode-dark"] .section__list-item:hover {
background-color: #2a2d2e;
}

label {
display: flex;
align-items: center;
cursor: inherit;
flex: auto;
}

input[type="checkbox"] {
margin-right: 4px;
cursor: pointer;
}
44 changes: 44 additions & 0 deletions media/settings-view/main.js
Original file line number Diff line number Diff line change
@@ -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

const { method, params } = event.data;

if (method === "updateSettings") {
for (const [key, value] of Object.entries(params.settings)) {
// eslint-disable-next-line no-undef
const input = document.querySelector(".section_type_settings input[settingName=" + key + "]");

if (!input) {
continue;
}

if (typeof value === "boolean") {
input.checked = value;
} else {
input.value = value;
}
}
}
});

function listenSettingsCheckbox() {
// 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

method: "toggleSettingsCheckbox",
params: {
settingName: event.target.getAttribute("settingName"),
value: this.checked,
},
});
});
}
}
})();
13 changes: 12 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
"key": "ctrl+shift+8",
"mac": "cmd+shift+8",
"when": "editorTextFocus && editorLangId =~ /(javascript|typescript)/"
},
"views": {
"test": [
{
"type": "webview",
"id": "tpn.settingsView",
"name": "Testplane"
}
]
}
},
"repository": {
Expand All @@ -41,7 +50,9 @@
"build": "tsup --minify --clean",
"watch": "tsup --watch --sourcemap",
"test": "npm run lint && npm run test-e2e",
"test-e2e": "wdio run ./tests/e2e/wdio.conf.ts",
"test-e2e": "npm run test-e2e:basic && npm run test-e2e:settings-view",
"test-e2e:basic": "wdio run ./tests/e2e/basic/wdio.conf.ts",
"test-e2e:settings-view": "wdio run ./tests/e2e/settings-view/wdio.conf.ts",
"eslint": "eslint src --ext ts --cache",
"lint": "eslint --cache . && prettier --check .",
"reformat": "eslint --fix . && prettier --write .",
Expand Down
4 changes: 4 additions & 0 deletions samples/basic/testplane.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export default {
httpTimeout: 60000,
testTimeout: 90000,
resetCursor: false,
takeScreenshotOnFails: {
testFail: false,
assertViewFail: false,
Copy link
Member Author

Choose a reason for hiding this comment

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

There is no need to wasting time on it

},
sets: {
desktop: {
files: ["tests/**/*.testplane.ts"],
Expand Down
Loading
Loading