Skip to content

Commit 3c88b7d

Browse files
committed
Switch to kebab-case for all IDs
1 parent 4905cc8 commit 3c88b7d

File tree

5 files changed

+34
-52
lines changed

5 files changed

+34
-52
lines changed

public/index.html

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
</div>
2323
</noscript>
2424
<main class="container py-5">
25-
<div class="text-center mb-4">
25+
<div class="text-center mt-4 mb-4">
2626
<img
2727
src="assets/logo.png"
2828
alt="MATLAB logo"
@@ -35,7 +35,7 @@ <h2>Generate a GitHub Actions Workflow for MATLAB</h2>
3535
</p>
3636
</div>
3737
<div class="ps-4 pe-4">
38-
<form id="generateForm" class="needs-validation" novalidate>
38+
<form id="generate-form" class="needs-validation" novalidate>
3939
<div class="form-floating mb-4">
4040
<input
4141
type="text"
@@ -55,7 +55,7 @@ <h2>Generate a GitHub Actions Workflow for MATLAB</h2>
5555
<button
5656
type="submit"
5757
class="btn btn-primary w-100 mb-4"
58-
id="generateButton"
58+
id="generate-button"
5959
aria-label="Generate Workflow">
6060
Generate Workflow
6161
</button>
@@ -64,7 +64,7 @@ <h2>Generate a GitHub Actions Workflow for MATLAB</h2>
6464
class="btn btn-link d-flex align-items-center justify-content-center mx-auto p-0"
6565
type="button"
6666
data-bs-toggle="collapse"
67-
data-bs-target="#advancedOptions">
67+
data-bs-target="#advanced-options">
6868
Advanced Options
6969
<svg
7070
xmlns="http://www.w3.org/2000/svg"
@@ -79,7 +79,7 @@ <h2>Generate a GitHub Actions Workflow for MATLAB</h2>
7979
d="M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708" />
8080
</svg>
8181
</button>
82-
<div class="collapse mt-4" id="advancedOptions">
82+
<div class="collapse mt-4" id="advanced-options">
8383
<div
8484
class="form-check form-switch form-switch-md d-flex justify-content-between align-items-center"
8585
data-bs-toggle="tooltip"
@@ -88,8 +88,8 @@ <h2>Generate a GitHub Actions Workflow for MATLAB</h2>
8888
<input
8989
class="form-check-input"
9090
type="checkbox"
91-
id="useBatchToken" />
92-
<label class="form-check-label ms-2" for="useBatchToken">
91+
id="use-batch-token" />
92+
<label class="form-check-label ms-2" for="use-batch-token">
9393
Use MATLAB batch licensing token
9494
</label>
9595
</div>
@@ -119,8 +119,10 @@ <h2>Generate a GitHub Actions Workflow for MATLAB</h2>
119119
<input
120120
class="form-check-input"
121121
type="checkbox"
122-
id="useVirtualDisplay" />
123-
<label class="form-check-label ms-2" for="useVirtualDisplay">
122+
id="use-virtual-display" />
123+
<label
124+
class="form-check-label ms-2"
125+
for="use-virtual-display">
124126
Use virtual display on Linux runner
125127
</label>
126128
</div>
@@ -150,10 +152,10 @@ <h2>Generate a GitHub Actions Workflow for MATLAB</h2>
150152
<input
151153
class="form-check-input"
152154
type="checkbox"
153-
id="buildAcrossPlatforms" />
155+
id="build-across-platforms" />
154156
<label
155157
class="form-check-label ms-2"
156-
for="buildAcrossPlatforms">
158+
for="build-across-platforms">
157159
Build across multiple platforms
158160
</label>
159161
</div>

public/scripts/main.js

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ window.navigateTo = navigateTo;
88

99
function generateWorkflowWithFormInputs() {
1010
return generateWorkflow({
11-
useBatchToken: document.getElementById("useBatchToken").checked,
12-
useVirtualDisplay: document.getElementById("useVirtualDisplay").checked,
13-
buildAcrossPlatforms: document.getElementById("buildAcrossPlatforms")
11+
useBatchToken: document.getElementById("use-batch-token").checked,
12+
useVirtualDisplay: document.getElementById("use-virtual-display").checked,
13+
buildAcrossPlatforms: document.getElementById("build-across-platforms")
1414
.checked,
1515
jsyaml: window.jsyaml,
1616
siteUrl:
@@ -43,26 +43,9 @@ function handleFormSubmit(e) {
4343
window.navigateTo(url);
4444
}
4545

46-
function handleDownloadClick(e) {
47-
e.preventDefault();
48-
49-
const workflow = generateWorkflowWithFormInputs();
50-
51-
const blob = new Blob([workflow], { type: "text/yaml" });
52-
const url = URL.createObjectURL(blob);
53-
const a = document.createElement("a");
54-
a.href = url;
55-
a.download = "matlab.yml";
56-
a.click();
57-
URL.revokeObjectURL(url);
58-
}
59-
6046
document
61-
.getElementById("generateForm")
47+
.getElementById("generate-form")
6248
.addEventListener("submit", handleFormSubmit);
63-
document
64-
.getElementById("downloadButton")
65-
?.addEventListener("click", handleDownloadClick);
6649

6750
document.querySelectorAll('[data-bs-toggle="tooltip"]').forEach((el) => {
6851
new bootstrap.Tooltip(el);

public/scripts/workflow.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ function parseRepositoryURL(repoURL) {
33
repoURL = repoURL.trim().replace(/\.git$/i, "");
44

55
// Normalize all input to HTTP(S) URL for easier parsing
6-
let m = repoURL.match(/^(git@|ssh:\/\/git@|git:\/\/)([^:/]+)[:\/]((?:[^/]+\/)+[^/]+)$/i);
6+
let m = repoURL.match(
7+
/^(git@|ssh:\/\/git@|git:\/\/)([^:/]+)[:/]((?:[^/]+\/)+[^/]+)$/i,
8+
);
79
if (m) {
810
// SSH or git: git@github.com:owner/repo or ssh://[email protected]/owner/repo or git://github.com/owner/repo
911
repoURL = `https://${m[2]}/${m[3]}`;

tests/main.test.js

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ beforeEach(async () => {
1010
global.URL.revokeObjectURL = jest.fn();
1111

1212
document.body.innerHTML = `
13-
<form id="generateForm">
13+
<form id="generate-form">
1414
<input id="repo" />
15-
<input type="checkbox" id="useBatchToken" />
16-
<input type="checkbox" id="useVirtualDisplay" />
17-
<input type="checkbox" id="buildAcrossPlatforms" />
18-
<button type="submit" id="generateButton"></button>
15+
<input type="checkbox" id="use-batch-token" />
16+
<input type="checkbox" id="use-virtual-display" />
17+
<input type="checkbox" id="build-across-platforms" />
18+
<button type="submit" id="generate-button"></button>
1919
</form>
2020
<a id="downloadButton"></a>
2121
`;
@@ -29,7 +29,7 @@ test("form submit with invalid repo shows error", () => {
2929
expect(repoInput.classList.contains("is-invalid")).toBe(false);
3030
repoInput.value = "invalidrepo";
3131
document
32-
.getElementById("generateForm")
32+
.getElementById("generate-form")
3333
.dispatchEvent(new Event("submit", { bubbles: true, cancelable: true }));
3434
expect(repoInput.classList.contains("is-invalid")).toBe(true);
3535
expect(window.navigateTo).not.toHaveBeenCalled();
@@ -39,7 +39,7 @@ test("form submit with valid slug works", () => {
3939
const repoInput = document.getElementById("repo");
4040
repoInput.value = "owner/repo";
4141
document
42-
.getElementById("generateForm")
42+
.getElementById("generate-form")
4343
.dispatchEvent(new Event("submit", { bubbles: true, cancelable: true }));
4444
expect(window.navigateTo).toHaveBeenCalledWith(
4545
expect.stringContaining("https://github.com/owner/repo/new/main?filename="),
@@ -50,7 +50,7 @@ test("form submit with valid URL works", () => {
5050
const repoInput = document.getElementById("repo");
5151
repoInput.value = "https://github.com/octocat/Hello-World";
5252
document
53-
.getElementById("generateForm")
53+
.getElementById("generate-form")
5454
.dispatchEvent(new Event("submit", { bubbles: true, cancelable: true }));
5555
expect(window.navigateTo).toHaveBeenCalledWith(
5656
expect.stringContaining(
@@ -63,7 +63,7 @@ test("form submit with valid cloud-hosted enterprise URL works", () => {
6363
const repoInput = document.getElementById("repo");
6464
repoInput.value = "https://github.com/enterprises/gh/octocat/Hello-World";
6565
document
66-
.getElementById("generateForm")
66+
.getElementById("generate-form")
6767
.dispatchEvent(new Event("submit", { bubbles: true, cancelable: true }));
6868
expect(window.navigateTo).toHaveBeenCalledWith(
6969
expect.stringContaining(
@@ -72,11 +72,6 @@ test("form submit with valid cloud-hosted enterprise URL works", () => {
7272
);
7373
});
7474

75-
test("download button triggers download", () => {
76-
document.getElementById("downloadButton").click();
77-
expect(global.URL.createObjectURL).toHaveBeenCalled();
78-
});
79-
8075
test("advanced options are passed to generateWorkflow", async () => {
8176
// Re-import main.js with a spy on generateWorkflow
8277
jest.resetModules();
@@ -87,13 +82,13 @@ test("advanced options are passed to generateWorkflow", async () => {
8782
}));
8883
window.jsyaml = { dump: () => "yaml-content" };
8984
document.getElementById("repo").value = "o/r";
90-
document.getElementById("useBatchToken").checked = true;
91-
document.getElementById("useVirtualDisplay").checked = false;
92-
document.getElementById("buildAcrossPlatforms").checked = true;
85+
document.getElementById("use-batch-token").checked = true;
86+
document.getElementById("use-virtual-display").checked = false;
87+
document.getElementById("build-across-platforms").checked = true;
9388
await import("../public/scripts/main.js");
9489
window.navigateTo = jest.fn();
9590
document
96-
.getElementById("generateForm")
91+
.getElementById("generate-form")
9792
.dispatchEvent(new Event("submit", { bubbles: true, cancelable: true }));
9893
expect(workflowSpy).toHaveBeenCalledWith({
9994
useBatchToken: true,

tests/smoke-html.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ test("index.html renders the form", () => {
1111
"utf8",
1212
);
1313
document.documentElement.innerHTML = html;
14-
expect(document.getElementById("generateForm")).not.toBeNull();
14+
expect(document.getElementById("generate-form")).not.toBeNull();
1515
});

0 commit comments

Comments
 (0)