Files
pages/internal/server/testdata/search-results.js
T
Anya Tokugawa d5d21b7841
Build and publish container images / images (push) Successful in 9m34s
Release container images / release (push) Successful in 36s
Refactor architecture into eight components and consolidate reliability work
Extract Grammaratur, Dregarnuhr, Geduldh, Mestionora, Ordoschnellic, Schutzaria, Kunstzeal and Seheweit behind compatible application contracts.

Include accumulated editor resilience, navigation and theme UX, remote CLI, storage/schema and DR groundwork, tests and design/operations documentation.

Verified: uncached full Go suite; go vet ./...; race tests for all eight components; 11 targeted Chromium tests; Node suites; 19 Python CLI tests; reproducible editor build. No push, release tag or deployment in this checkpoint.
2026-11-01 15:23:31 +09:00

72 lines
5.3 KiB
JavaScript

window.addEventListener('load', async () => {
try {
const assert = (condition, message) => { if (!condition) throw new Error(message); };
const results = document.querySelector('[data-search-view]');
assert(results, 'Search results missing');
const form = document.querySelector('#search-form');
assert(form, 'Shared search form missing');
const initial = new FormData(form);
assert(initial.get('q')?.includes('nebula'), 'Search query not preserved');
for (const name of ['q', 'scope', 'file_type', 'ext', 'date_field', 'from', 'to']) {
assert(initial.getAll(name).length === 1, 'Search parameter missing or duplicated: ' + name);
}
const options = document.querySelector('.search-options');
assert(options?.querySelector('summary'), 'Accessible search options disclosure missing');
const saved = {};
for (const [name, value] of Object.entries({file_type:'pdf', ext:'pdf', date_field:'created', from:'2026-01-01', to:'2026-01-31'})) {
const control = form.elements.namedItem(name);
assert(control?.form === form, 'Filter does not belong to the search form: ' + name);
saved[name] = control.value;
control.value = value;
}
const filtered = new FormData(form);
assert(filtered.get('file_type') === 'pdf' && filtered.get('ext') === 'pdf', 'File filter was not submitted');
assert(filtered.get('date_field') === 'created' && filtered.get('from') === '2026-01-01' && filtered.get('to') === '2026-01-31', 'Date filter was not submitted');
assert(filtered.get('q') === initial.get('q') && filtered.get('scope') === initial.get('scope'), 'Filters lost the query or folder scope');
for (const [name, value] of Object.entries(saved)) form.elements.namedItem(name).value = value;
const city = document.querySelector('[data-city-search-results]');
if (city) {
assert(city.compareDocumentPosition(results) & Node.DOCUMENT_POSITION_FOLLOWING, 'City results must precede pages');
assert(!city.querySelector('.children-entry,[data-child-path]'), 'City result is exposed to file operations');
assert(city.querySelector('[data-city-search-kind] .search-result-name mark'), 'City name highlight missing');
assert(city.querySelector('.search-result-path')?.getAttribute('href')?.startsWith('/'), 'City boundary Path link missing');
for (const hit of city.querySelectorAll('[data-city-search-kind]')) {
const href = hit.querySelector('.search-result-name')?.getAttribute('href');
assert(href?.startsWith('/') && !href.startsWith('/v/city/'), 'Search links to City settings');
assert(href === hit.querySelector('.search-result-path')?.getAttribute('href'), 'City title and Path destinations differ');
}
assert(!city.querySelector('script,[onload],[onerror]'), 'City source HTML became executable markup');
}
for (const mode of ['list', 'detail', 'icon']) {
const button = document.querySelector(`[data-children-view="${mode}"]`);
button.click();
assert(results.dataset.searchView === mode, 'View switch failed: ' + mode);
const panel = results.querySelector('.search-view-' + mode);
assert(getComputedStyle(panel).display !== 'none', 'Selected mode is hidden: ' + mode);
assert(panel.querySelector('.search-result-name')?.textContent.includes('nebula'), 'Page name missing');
assert(panel.querySelector('.search-result-path')?.textContent.includes('/docs/nebula guide?#%'), 'Full Path missing');
assert([...panel.querySelectorAll('.search-result-excerpt mark')].some(mark => mark.textContent.toLowerCase() === 'nebula'), 'Context highlight missing');
assert(panel.querySelector('[data-match-source="body"]'), 'Match source missing');
assert(panel.querySelector('.search-result-name').closest('a').getAttribute('href').includes('%3F%23%25'), 'Path URL was not encoded');
if (city) assert(getComputedStyle(city).display !== 'none', 'View switching hid City results: ' + mode);
}
assert(!results.querySelector('script,[onload],[onerror]'), 'Source HTML became executable markup');
assert(!results.textContent.includes('SECRET_EXCERPT'), 'Unreadable snippet leaked');
document.querySelector('[data-children-view="list"]').click();
const row = results.querySelector('.search-view-list .children-entry');
row.dispatchEvent(new MouseEvent('click', {bubbles:true, cancelable:true, ctrlKey:true}));
assert(row.classList.contains('children-selected'), 'Ctrl selection stopped working');
if (city) {
const cityRow = city.querySelector('[data-city-search-kind]');
cityRow.dispatchEvent(new MouseEvent('click', {bubbles:true, cancelable:true, ctrlKey:true}));
assert(!cityRow.classList.contains('children-selected'), 'City result became a selectable file');
}
options.open = true;
assert(document.documentElement.scrollWidth <= innerWidth, 'Search introduces horizontal page scrolling: ' + [...document.querySelectorAll('body *')].filter(el => el.getBoundingClientRect().right > innerWidth + 1).slice(0,8).map(el => el.tagName + '.' + el.className + ':' + Math.round(el.getBoundingClientRect().right)).join(', '));
document.body.dataset.vimReady = '1';
console.log('Vim initialized');
} catch (error) {
const box = document.createElement('div'); box.id = 'error'; box.textContent = error.stack || error.message; document.body.append(box);
}
});