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 assertion for news subscription card (dead-field audit PR 4) (#4624)

LearningCircuitef94a3ba9d8a
diff --git a/tests/ui_tests/test_lib/fixtures.js b/tests/ui_tests/test_lib/fixtures.js
index c6e5cd74c3..53a3d2955e 100644
--- a/tests/ui_tests/test_lib/fixtures.js
+++ b/tests/ui_tests/test_lib/fixtures.js
@@ -1,8 +1,9 @@
/**
- * Shared per-test fixture helpers for library / collection UI tests.
+ * Shared per-test fixture helpers for library / collection / news-subscription
+ * 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
+ * Seed and clean up a collection or a news subscription via the synchronous 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
@@ -45,6 +46,39 @@ async function deleteCollection(page, collectionId) {
} catch { /* swallow page.evaluate errors so cleanup never masks the test result */ }
}
+async function seedSubscription(page, { isActive = true } = {}) {
+ const r = await page.evaluate(async (active) => {
+ const csrf = document.querySelector('meta[name="csrf-token"]')?.content;
+ // Best-effort uniqueness (not guaranteed): timestamp + random suffix.
+ const query = `ldr-ui-test-sub-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
+ const res = await fetch('/news/api/subscribe', {
+ method: 'POST',
+ credentials: 'same-origin',
+ headers: { 'Content-Type': 'application/json', 'X-CSRFToken': csrf || '' },
+ body: JSON.stringify({ query, subscription_type: 'search', is_active: active }),
+ });
+ const body = await res.json().catch(() => ({}));
+ return { ok: res.ok, status: res.status, query, id: body?.subscription_id };
+ }, isActive);
+ return r.ok && r.id ? { id: r.id, query: r.query } : null;
+}
+
+async function deleteSubscription(page, subscriptionId) {
+ if (!subscriptionId) return;
+ try {
+ await page.evaluate(async (id) => {
+ const csrf = document.querySelector('meta[name="csrf-token"]')?.content;
+ try {
+ await fetch(`/news/api/subscriptions/${id}`, {
+ method: 'DELETE',
+ credentials: 'same-origin',
+ headers: { 'X-CSRFToken': csrf || '' },
+ });
+ } catch { /* swallow fetch errors */ }
+ }, subscriptionId);
+ } 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
@@ -52,4 +86,4 @@ async function deleteCollection(page, collectionId) {
// uploadFixtureDocument here returning the document id(s) so callers can delete
// the doc, not just the collection.
-module.exports = { seedCollection, deleteCollection };
+module.exports = { seedCollection, deleteCollection, seedSubscription, deleteSubscription };
diff --git a/tests/ui_tests/test_news_subscriptions_ci.js b/tests/ui_tests/test_news_subscriptions_ci.js
index f08afdc79e..06287edca8 100644
--- a/tests/ui_tests/test_news_subscriptions_ci.js
+++ b/tests/ui_tests/test_news_subscriptions_ci.js
@@ -8,6 +8,7 @@
*/
const { setupTest, teardownTest, TestResults, log, navigateTo, withTimeout, findActionButton } = require('./test_lib');
+const { seedSubscription, deleteSubscription } = require('./test_lib/fixtures');
// ============================================================================
// News Feed Page Tests
@@ -255,37 +256,46 @@ const SubscriptionsPageTests = {
},
async subscriptionCardStructure(page, baseUrl) {
+ // Subscription cards render client-side (subscriptions.js::
+ // createSubscriptionCard) as .ldr-subscription-card[data-subscription-id]
+ // with .ldr-card-header h4 (title) + .ldr-query-text + .ldr-status-badge,
+ // an edit link (a[href*="/edit"]) and a .btn-danger delete button. The old
+ // test scanned for `.subscription-card` (no such class) and SKIPped on an
+ // empty DB. Seed a subscription and assert the real card markup.
await navigateTo(page, `${baseUrl}/news/subscriptions`);
+ const seeded = await seedSubscription(page);
+ if (!seeded) {
+ return { passed: false, message: 'Could not seed subscription for card-structure test' };
+ }
+ try {
+ // navigateTo no-ops (already on this path); reload to render the card.
+ await page.reload({ waitUntil: 'domcontentloaded' });
+ await page.waitForSelector(`.ldr-subscription-card[data-subscription-id="${seeded.id}"]`, { timeout: 10000 });
- const result = await page.evaluate(() => {
- const cards = document.querySelectorAll('.subscription-card, .subscription-item, [data-subscription-id]');
- if (cards.length === 0) return { hasCards: false };
+ const result = await page.evaluate((id) => {
+ const card = document.querySelector(`.ldr-subscription-card[data-subscription-id="${id}"]`);
+ if (!card) return { found: false };
+ return {
+ found: true,
+ hasTitle: !!card.querySelector('.ldr-card-header h4'),
+ hasQuery: !!card.querySelector('.ldr-query-text'),
+ hasStatus: !!card.querySelector('.ldr-status-badge'),
+ hasEdit: !!card.querySelector('a[href*="/edit"]'),
+ hasDelete: !!card.querySelector('.btn-danger'),
+ };
+ }, seeded.id);
- const firstCard = cards[0];
+ const passed = result.found && result.hasTitle && result.hasQuery
+ && result.hasStatus && result.hasEdit && result.hasDelete;
return {
- hasCards: true,
- cardCount: cards.length,
- hasName: !!firstCard.querySelector('.subscription-name, .card-title, h3, h4, .name'),
- hasQuery: !!firstCard.querySelector('.query, .search-query, .subscription-query'),
- hasStatus: !!firstCard.querySelector('.status, .badge, .subscription-status'),
- hasFrequency: !!firstCard.querySelector('.frequency, .interval, .refresh'),
- hasLastUpdated: !!firstCard.querySelector('.last-updated, .updated, time'),
- hasEditButton: !!firstCard.querySelector('.edit-btn, button[onclick*="edit"], .btn-edit'),
- hasDeleteButton: !!firstCard.querySelector('.delete-btn, button[onclick*="delete"], .btn-danger')
+ passed,
+ message: passed
+ ? 'Subscription card renders real structure (title + query + status badge + edit + delete)'
+ : `Subscription card structure incomplete (${JSON.stringify(result)})`
};
- });
-
- if (!result.hasCards) {
- return { passed: null, skipped: true, message: 'No subscription cards to test structure' };
+ } finally {
+ await deleteSubscription(page, seeded.id);
}
-
- const hasRequiredParts = result.hasName || result.hasQuery;
- return {
- passed: hasRequiredParts,
- message: hasRequiredParts
- ? `Subscription cards: ${result.cardCount} found (name=${result.hasName}, query=${result.hasQuery}, status=${result.hasStatus}, edit=${result.hasEditButton}, delete=${result.hasDeleteButton})`
- : 'Subscription cards missing required elements'
- };
},
async subscriptionFormPage(page, baseUrl) {