feat: add search diagnostics logging and tag cardinality tracking
This commit is contained in:
+54
-3
@@ -1,4 +1,28 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { test, expect, Page } from '@playwright/test';
|
||||
|
||||
const SEARCH_QUEUE_KEY = 'obsiviewer.searchdiag.queue';
|
||||
|
||||
async function clearDiagnostics(page: Page): Promise<void> {
|
||||
await page.evaluate(key => {
|
||||
localStorage.removeItem(key);
|
||||
}, SEARCH_QUEUE_KEY);
|
||||
}
|
||||
|
||||
async function readDiagnostics(page: Page): Promise<any[]> {
|
||||
const raw = await page.evaluate(key => localStorage.getItem(key), SEARCH_QUEUE_KEY);
|
||||
if (!raw) {
|
||||
return [];
|
||||
}
|
||||
try {
|
||||
return JSON.parse(raw);
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function findStage(events: any[], stage: string): any | undefined {
|
||||
return events.find(event => event?.stage === stage);
|
||||
}
|
||||
|
||||
test.describe('Search Functionality', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
@@ -69,16 +93,43 @@ test.describe('Search Functionality', () => {
|
||||
});
|
||||
|
||||
test('should filter by tag', async ({ page }) => {
|
||||
await clearDiagnostics(page);
|
||||
const searchInput = page.locator('input[type="text"]').first();
|
||||
|
||||
|
||||
await searchInput.fill('tag:#work');
|
||||
await searchInput.press('Enter');
|
||||
|
||||
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
// Should show results with #work tag
|
||||
const results = page.locator('.search-result');
|
||||
await expect(results.first()).toBeVisible({ timeout: 5000 });
|
||||
|
||||
const events = await readDiagnostics(page);
|
||||
const summary = findStage(events, 'SEARCH_DIAG_SUMMARY');
|
||||
expect(summary).toBeTruthy();
|
||||
expect(summary.data?.counts?.displayed).toBeGreaterThan(0);
|
||||
expect(summary.data?.userVisible?.emptyStateShown).toBe(false);
|
||||
});
|
||||
|
||||
test('should record diagnostics when tag search misses index', async ({ page }) => {
|
||||
await clearDiagnostics(page);
|
||||
const searchInput = page.locator('input[type="text"]').first();
|
||||
|
||||
await searchInput.fill('tag:#home');
|
||||
await searchInput.press('Enter');
|
||||
|
||||
await page.waitForTimeout(500);
|
||||
|
||||
const events = await readDiagnostics(page);
|
||||
const summary = findStage(events, 'SEARCH_DIAG_SUMMARY');
|
||||
expect(summary).toBeTruthy();
|
||||
expect(summary.data?.counts?.displayed ?? 0).toBe(0);
|
||||
expect(summary.data?.userVisible?.emptyStateShown).toBe(true);
|
||||
|
||||
const resultMap = findStage(events, 'SEARCH_DIAG_RESULT_MAP');
|
||||
expect(resultMap).toBeTruthy();
|
||||
expect(resultMap.data?.reasonsEmpty).toEqual(expect.arrayContaining(['tagNotInIndex']));
|
||||
});
|
||||
|
||||
test('should toggle case sensitivity', async ({ page }) => {
|
||||
|
||||
Reference in New Issue
Block a user