Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

test(ui-tests): real assertions for library collection-card + doc-search (dead-field audit PR 3) (#4617)

LearningCircuit2ee1595cb214
diff --git a/tests/ui_tests/test_lib/fixtures.js b/tests/ui_tests/test_lib/fixtures.js
new file mode 100644
index 0000000000..c6e5cd74c3
--- /dev/null
+++ b/tests/ui_tests/test_lib/fixtures.js
@@ -0,0 +1,55 @@
+/**
+ * Shared per-test fixture helpers for library / collection UI tests.
+ *
+ * Seed and clean up a collection via the synchronous library API so tests don't
+ * depend on pre-existing DB state. These mirror the helpers proven in
+ * test_crud_operations_ci.js (#4174/#4180/#4187); they live here now that a
+ * second test file needs them. Each cleanup wraps page.evaluate
+ * in a Node-side try/catch so a torn-down page during teardown can never throw
+ * and mask a test result.
+ *
+ * All helpers read the CSRF token from the current page's meta tag, so the page
+ * must already be on a same-origin app page before calling them.
+ */
+
+async function seedCollection(page) {
+ const r = await page.evaluate(async () => {
+ const csrf = document.querySelector('meta[name="csrf-token"]')?.content;
+ // Best-effort uniqueness (not guaranteed): timestamp + random suffix.
+ const name = `ldr-ui-test-collection-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
+ const res = await fetch('/library/api/collections', {
+ method: 'POST',
+ credentials: 'same-origin',
+ headers: { 'Content-Type': 'application/json', 'X-CSRFToken': csrf || '' },
+ body: JSON.stringify({ name, description: 'UI test fixture', type: 'user_uploads' }),
+ });
+ const body = await res.json().catch(() => ({}));
+ return { ok: res.ok, name, success: body?.success === true, id: body?.collection?.id };
+ });
+ return r.ok && r.success && r.id ? { id: r.id, name: r.name } : null;
+}
+
+async function deleteCollection(page, collectionId) {
+ if (!collectionId) return;
+ try {
+ await page.evaluate(async (id) => {
+ const csrf = document.querySelector('meta[name="csrf-token"]')?.content;
+ try {
+ await fetch(`/library/api/collections/${id}`, {
+ method: 'DELETE',
+ credentials: 'same-origin',
+ headers: { 'X-CSRFToken': csrf || '' },
+ });
+ } catch { /* swallow fetch errors */ }
+ }, collectionId);
+ } catch { /* swallow page.evaluate errors so cleanup never masks the test result */ }
+}
+
+// NOTE: a document-upload helper lives in test_crud_operations_ci.js. It is
+// intentionally NOT exported here yet: the only consumer (documentCardActions)
+// is deferred until it can clean up the uploaded doc (collection delete doesn't
+// cascade to docs — see test_library_documents_ci.js). When that lands, add
+// uploadFixtureDocument here returning the document id(s) so callers can delete
+// the doc, not just the collection.
+
+module.exports = { seedCollection, deleteCollection };
diff --git a/tests/ui_tests/test_library_collections_ci.js b/tests/ui_tests/test_library_collections_ci.js
index db0264abd2..a143880417 100644
--- a/tests/ui_tests/test_library_collections_ci.js
+++ b/tests/ui_tests/test_library_collections_ci.js
@@ -7,6 +7,7 @@
* Run: node test_library_collections_ci.js
*/
const { setupTest, teardownTest, TestResults, log, delay, navigateTo, withTimeout } = require('./test_lib');
+const { seedCollection, deleteCollection } = require('./test_lib/fixtures');
// ============================================================================
// Library Page Tests
@@ -197,33 +198,43 @@ const CollectionsPageTests = {
},
async collectionCardStructure(page, baseUrl) {
+ // Collections render client-side (collections_manager.js) into
+ // #collections-container as <a class="ldr-collection-card" data-id="<id>">
+ // with .ldr-collection-header h3 (name) + .ldr-collection-stats +
+ // .ldr-collection-view-link. The old test scanned for `.collection-card`
+ // (no such class exists) and SKIPped on an empty DB. Seed a collection
+ // and assert the real card markup, then clean up.
await navigateTo(page, `${baseUrl}/library/collections`);
+ const seeded = await seedCollection(page);
+ if (!seeded) {
+ return { passed: false, message: 'Could not seed collection for card-structure test' };
+ }
+ try {
+ // navigateTo no-ops (already on this path); reload to render the new card.
+ await page.reload({ waitUntil: 'domcontentloaded' });
+ await page.waitForSelector(`.ldr-collection-card[data-id="${seeded.id}"]`, { timeout: 10000 });
- const result = await page.evaluate(() => {
- const cards = document.querySelectorAll('.collection-card, .collection-item, [data-collection-id]');
- if (cards.length === 0) return { hasCards: false };
+ const result = await page.evaluate((id) => {
+ const card = document.querySelector(`.ldr-collection-card[data-id="${id}"]`);
+ if (!card) return { found: false };
+ return {
+ found: true,
+ name: card.querySelector('.ldr-collection-header h3')?.textContent?.trim(),
+ hasStats: !!card.querySelector('.ldr-collection-stats'),
+ hasViewLink: !!card.querySelector('.ldr-collection-view-link'),
+ };
+ }, seeded.id);
- const firstCard = cards[0];
+ const passed = result.found && result.name === seeded.name && result.hasStats && result.hasViewLink;
return {
- hasCards: true,
- cardCount: cards.length,
- hasName: !!firstCard.querySelector('.collection-name, .card-title, h3, h4, .name'),
- hasCount: !!firstCard.querySelector('.document-count, .count, .badge'),
- hasActions: !!firstCard.querySelector('.card-actions, .btn, button, .actions')
+ passed,
+ message: passed
+ ? `Collection card renders real structure (name="${result.name}", stats + view-link present)`
+ : `Collection card structure incomplete (found=${result.found}, name="${result.name}", stats=${result.hasStats}, viewLink=${result.hasViewLink})`
};
- });
-
- if (!result.hasCards) {
- return { passed: null, skipped: true, message: 'No collections to test card structure' };
+ } finally {
+ await deleteCollection(page, seeded.id);
}
-
- const hasRequiredParts = result.hasName;
- return {
- passed: hasRequiredParts,
- message: hasRequiredParts
- ? `Collection cards: ${result.cardCount} found (name=${result.hasName}, count=${result.hasCount}, actions=${result.hasActions})`
- : 'Collection cards missing required elements'
- };
},
async uploadDocumentButton(page, baseUrl) {
diff --git a/tests/ui_tests/test_library_documents_ci.js b/tests/ui_tests/test_library_documents_ci.js
index c21811ac5e..b93fef50d9 100644
--- a/tests/ui_tests/test_library_documents_ci.js
+++ b/tests/ui_tests/test_library_documents_ci.js
@@ -185,32 +185,33 @@ const FilterControlsTests = {
},
async searchFilterFunctionality(page, baseUrl) {
+ // #search-documents (library.html) is the real document search input,
+ // wired to filter .ldr-document-card client-side on the 'input' event
+ // (library_search_ui.js:142). The old test typed a query but returned
+ // passed:true regardless. Assert the real input exists and reflects
+ // typed input.
await navigateTo(page, `${baseUrl}/library`);
+ await page.waitForSelector('#search-documents', { timeout: 10000 });
- const searchInput = await page.$('#search-documents, input[type="search"], input[placeholder*="search" i], #search, .search-input');
-
- if (!searchInput) {
- return { passed: null, skipped: true, message: 'No search input found' };
- }
-
- // Count initial items
- const initialCount = await page.evaluate(() => {
- const items = document.querySelectorAll('.ldr-document-card, .doc-item, .library-item, [class*="document"]');
- return items.length;
- });
-
- // Type search query
- await searchInput.type('test search query');
- await delay(500);
-
- const afterSearchCount = await page.evaluate(() => {
- const items = document.querySelectorAll('.ldr-document-card, .doc-item, .library-item, [class*="document"]');
- return items.length;
+ const info = await page.evaluate(() => {
+ const el = document.getElementById('search-documents');
+ return { exists: !!el, type: el?.type, placeholder: el?.placeholder || '' };
});
+ if (!info.exists) {
+ return { passed: false, message: '#search-documents input not found on /library' };
+ }
+ // Clear any pre-filled value first so the assertion is deterministic
+ // (Puppeteer's page.type appends — there is no page.fill).
+ await page.$eval('#search-documents', el => { el.value = ''; });
+ await page.type('#search-documents', 'fixture');
+ const value = await page.$eval('#search-documents', el => el.value);
+ const passed = value === 'fixture';
return {
- passed: true,
- message: `Search input works (initial: ${initialCount} items, after search: ${afterSearchCount} items)`
+ passed,
+ message: passed
+ ? `Document search input accepts input (placeholder="${info.placeholder}")`
+ : `Search input did not reflect typed value (got "${value}")`
};
},
@@ -398,6 +399,13 @@ const DocumentCardTests = {
},
async documentCardActions(page, baseUrl) {
+ // NOTE: deferred from the dead-field audit's PR 3. The real assertion
+ // (seed collection + upload a doc, then assert .ldr-action-btn-txt +
+ // .ldr-btn-delete-doc on the card) works, but the uploaded doc leaks
+ // into this file's later PDF/Text viewer tests (collection deletion
+ // doesn't cascade-delete the doc), turning their skips into failures.
+ // Needs document-level cleanup or test reordering — tracked as a
+ // follow-up so it doesn't destabilise the library shard here.
await navigateTo(page, `${baseUrl}/library`);
const result = await page.evaluate(() => {