Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
crowlKats committed Jan 27, 2025
1 parent ac15740 commit 6e76bcb
Show file tree
Hide file tree
Showing 85 changed files with 11,269 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/snapshots/html_test__html_doc_dts-10.snap

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions tests/snapshots/html_test__html_doc_dts-11.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
source: tests/html_test.rs
expression: files.get(file_name).unwrap()
---
function findParent(el, find) {
do {
if (find(el)) {
return el;
}
} while (el = el.parentElement);
}

document.addEventListener("click", (e) => {
const target = findParent(
e.target,
(el) => el instanceof HTMLButtonElement && el.dataset["copy"],
);
if (target) {
navigator?.clipboard?.writeText(target.dataset["copy"]);
target.classList.add("copied");
setTimeout(() => target.classList.remove("copied"), 1000);
}
});

window.addEventListener("load", () => {
const usageSelector = document.getElementById("usageSelector");

document.addEventListener("mouseup", (e) => {
if (
findParent(
e.target,
(el) =>
el.parentElement === usageSelector && el instanceof HTMLDivElement,
)
) {
usageSelector.open = false;
}
});
});
145 changes: 145 additions & 0 deletions tests/snapshots/html_test__html_doc_dts-12.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
---
source: tests/html_test.rs
expression: files.get(file_name).unwrap()
---
const Fuse = window.Fuse;

const searchInput = document.querySelector("#searchbar");
const contentDiv = document.querySelector("#content");
const searchResultsDiv = document.querySelector("#searchResults");
const currentFile =
document.querySelector("meta[name='doc-current-file']").attributes
.getNamedItem("content").value;
const pathToRoot = "../".repeat(
currentFile ? (currentFile.split("/").length + 1) : 0,
);
searchInput.removeAttribute("style");

const SEARCH_INDEX = window.DENO_DOC_SEARCH_INDEX;

const fuse = new Fuse(SEARCH_INDEX.nodes, {
keys: [{
name: "name",
weight: 2,
}],
isCaseSensitive: false,
minMatchCharLength: 2,
threshold: 0.4,
});

const loadedUrl = new URL(window.location.href);
const val = loadedUrl.searchParams.get("q");
if (val) {
searchInput.value = val;
doSearch(val);
}

window.addEventListener("load", function () {
document.addEventListener("keydown", function (event) {
if (event.key.toLowerCase() === "s") {
if (event.target !== searchInput) {
searchInput.focus();
event.preventDefault();
}
}
});

const emptyPlaceholder = "Click or press 'S' to search...";
searchInput.placeholder = emptyPlaceholder;

searchInput.addEventListener("focus", function () {
searchInput.placeholder = "Type your query here...";
});

searchInput.addEventListener("blur", function () {
searchInput.placeholder = emptyPlaceholder;
});
});

function debounce(func, delay) {
let timerId;

return function () {
const context = this;
const args = arguments;

clearTimeout(timerId);

timerId = setTimeout(function () {
func.apply(context, args);
}, delay);
};
}

const debouncedSearch = debounce(doSearch, 250);

searchInput.addEventListener("input", (e) => {
const val = e.target.value;
debouncedSearch(val);
});

function doSearch(val) {
if (!val) {
updateCurrentLocation(val);
showPage();
} else {
const results = searchInIndex(val);
// console.log("results", results);
updateCurrentLocation(val);
renderResults(results);
showSearchResults();
}
}

function updateCurrentLocation(val) {
const url = new URL(window.location.href);
if (val) {
url.searchParams.set("q", val);
} else {
url.searchParams.delete("q");
}
window.history.replaceState({}, "", url.href);
}

function showPage() {
contentDiv.style.display = "flex";
searchResultsDiv.style.display = "none";
}

function showSearchResults() {
contentDiv.style.display = "none";
searchResultsDiv.style.display = "block";
}

function renderResults(results) {
if (results.length === 0) {
searchResultsDiv.innerHTML = `<span>No result</span>`;
return;
}

let html = `<ul>`;
for (const result of results) {
const kind = result.kind.map((kind) => {
return `<div class="text-${kind.kind} bg-${kind.kind}/15" title="${kind.title}">${kind.char}</div>`;
}).join("");
html += `<li class="block">
<a href="${pathToRoot}${result.file}/~/${result.name}.html" class="flex rounded-lg gap-4 items-center justify-between py-2 px-3 hover:bg-stone-100">
<div class="flex items-center gap-2.5">
<div class="docNodeKindIcon">
${kind}
</div>
<span class="text-sm leading-none">${result.name}</span>
</div>
</a>
</li>`;
}
html += `</ul>`;
searchResultsDiv.innerHTML = html;
}

function searchInIndex(val) {
return fuse.search(val).map((result) => result.item);
}
7 changes: 7 additions & 0 deletions tests/snapshots/html_test__html_doc_dts-13.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
source: tests/html_test.rs
expression: files.get(file_name).unwrap()
---
(function () {
window.DENO_DOC_SEARCH_INDEX = {"kind":"search","nodes":[{"kind":[{"char":"I","kind":"Interface","title":"Interface"}],"name":"ResponseInit","file":".","doc":"","url":"././~/ResponseInit.html","deprecated":false},{"kind":[{"char":"p","kind":"Property","title":"Property"}],"name":"ResponseInit.status","file":".","doc":"","url":"././~/ResponseInit.status.html","deprecated":false},{"kind":[{"char":"p","kind":"Property","title":"Property"}],"name":"ResponseInit.statusText","file":".","doc":"","url":"././~/ResponseInit.statusText.html","deprecated":false},{"kind":[{"char":"I","kind":"Interface","title":"Interface"},{"char":"v","kind":"Variable","title":"Variable"}],"name":"WebSocket","file":".","doc":"","url":"././~/WebSocket.html","deprecated":false},{"kind":[{"char":"p","kind":"Property","title":"Property"}],"name":"WebSocket.bufferedAmount","file":".","doc":"","url":"././~/WebSocket.bufferedAmount.html","deprecated":false},{"kind":[{"char":"p","kind":"Property","title":"Property"}],"name":"WebSocket.prototype","file":".","doc":"","url":"././~/WebSocket.prototype.html","deprecated":false},{"kind":[{"char":"p","kind":"Property","title":"Property"}],"name":"WebSocket.OPEN","file":".","doc":"","url":"././~/WebSocket.OPEN.html","deprecated":false}]};
})()
56 changes: 56 additions & 0 deletions tests/snapshots/html_test__html_doc_dts-2.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
source: tests/html_test.rs
expression: files.get(file_name).unwrap()
---
<!DOCTYPE html>
<html>
<head>
<title>documentation</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="doc-current-file" content="">
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" href="page.css">
<link id="ddocResetStylesheet" rel="stylesheet" href="reset.css"><script src="search_index.js" defer></script>
<script src="script.js" defer></script>
<script src="fuse.js" defer></script>
<script src="search.js" defer></script></head>
<body>
<div class="ddoc">
<div id="categoryPanel">
<ul><li><a href=".&#x2F;uncategorized.html" title="Uncategorized">Uncategorized</a></li><li>
<a class="!flex items-center gap-0.5" href=".&#x2F;all_symbols.html">
<span class="leading-none">view all 2 symbols</span><svg
width="16"
height="16"
viewBox="0 0 16 16"
fill="none"
xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M5.76748 11.8159C5.5378 11.577 5.54525 11.1972 5.78411 10.9675L8.93431 8L5.78411 5.0325C5.54525 4.80282 5.5378 4.423 5.76748 4.18413C5.99715 3.94527 6.37698 3.93782 6.61584 4.1675L10.2158 7.5675C10.3335 7.68062 10.4 7.83679 10.4 8C10.4 8.16321 10.3335 8.31938 10.2158 8.4325L6.61584 11.8325C6.37698 12.0622 5.99715 12.0547 5.76748 11.8159Z" fill="currentColor" />
</svg>
</a>
</li>
</ul>
</div>
<div><nav class="top-0 sticky bg-white z-50 py-3 h-14" id="topnav">
<div class="h-full">
<div><ul class="breadcrumbs"><li>index</li></ul>
</div>

<input
type="text"
id="searchbar"
style="display: none;"
class="py-2 px-2.5 rounded text-sm border border-gray-300 bg-transparent" />
</div>
</nav>
<div id="searchResults"></div><div id="content">
<main><section>
<div class="space-y-2 flex-1"><div class="space-y-7" id="module_doc"></div>
</div>
</section>
</main></div>
</div>
</div>
</body>
</html>
Loading

0 comments on commit 6e76bcb

Please sign in to comment.