spb/social-runtime-crawler
Public
TypeScript 91.8%
HTML 3.2%
JavaScript 3%
SQL 1.4%
CSS 0.7%
1import { describe, expect, it } from "vitest";2import { classifyPage } from "./PageClassifier.ts";3import type { DomSnapshot } from "./dom/PageSummarizer.ts";4import { youtubeAdapter, redditAdapter } from "@src/connectors";56const base = (url: string, extra: Partial<DomSnapshot> = {}): DomSnapshot => ({ url, title: "t", landmarks: ["main", "navigation"], candidates: [], video_elements: [], text_excerpt: "", scroll: { y: 0, height: 5000, viewport: 900 }, has_login_form: false, dialog_open: false, ...extra });78describe("classifyPage", () => {9 it("uses adapter url hints", () => {10 expect(classifyPage(base("https://www.youtube.com/results?search_query=ai"), youtubeAdapter.pageTypeHints).page_type).toBe("SEARCH_RESULTS");11 expect(classifyPage(base("https://www.youtube.com/watch?v=dQw4w9WgXcQ"), youtubeAdapter.pageTypeHints).page_type).toBe("VIDEO_DETAIL");12 expect(classifyPage(base("https://www.youtube.com/@someone/videos"), youtubeAdapter.pageTypeHints).page_type).toBe("CHANNEL");13 expect(classifyPage(base("https://www.reddit.com/r/quebec/comments/abc123/titre/"), redditAdapter.pageTypeHints).page_type).toBe("POST_DETAIL");14 expect(classifyPage(base("https://www.reddit.com/r/quebec/"), redditAdapter.pageTypeHints).page_type).toBe("GROUP");15 });16 it("flags login pages and unknown pages without throwing", () => {17 expect(classifyPage(base("https://example.com/x", { has_login_form: true })).page_type).toBe("LOGIN");18 const u = classifyPage(base("https://example.com/whatever"));19 expect(u.page_type).toBe("UNKNOWN");20 expect(u.confidence).toBeLessThan(0.5);21 });22});23