Add Reddit comments and X definitions
This commit is contained in:
parent
40895e05db
commit
1a9ab6ebdf
7 changed files with 129 additions and 2 deletions
|
|
@ -95,6 +95,22 @@ describe("DefinitionEngine", () => {
|
|||
expect(posts.map((post) => post.text)).toEqual(["the main post on the threads detail page", "a reply on the threads detail page"]);
|
||||
});
|
||||
|
||||
it("discovers posts from the old Reddit interface using fullname IDs", () => {
|
||||
document.body.innerHTML = readFileSync("tests/fixtures/reddit-old-feed.html", "utf8");
|
||||
const reddit = BUILTIN_DEFINITIONS.find((candidate) => candidate.id === "reddit-old")!;
|
||||
const posts = new DefinitionEngine(reddit).discover(document);
|
||||
expect(posts.map((post) => post.id)).toEqual(["reddit-old:t3_abc123", "reddit-old:t1_def456"]);
|
||||
expect(posts.map((post) => post.text)).toEqual(["the post body with visible text.", "a useful comment with visible text."]);
|
||||
});
|
||||
|
||||
it("discovers X posts using semantic tweet markers and permalink IDs", () => {
|
||||
document.body.innerHTML = readFileSync("tests/fixtures/x-feed.html", "utf8");
|
||||
const x = BUILTIN_DEFINITIONS.find((candidate) => candidate.id === "x")!;
|
||||
const posts = new DefinitionEngine(x).discover(document);
|
||||
expect(posts.map((post) => post.id)).toEqual(["x:http://localhost:3000/alice/status/1234567890"]);
|
||||
expect(posts[0]?.text).toBe("a useful post on x.");
|
||||
});
|
||||
|
||||
it("selects Threads on current and legacy domains", () => {
|
||||
const threads = BUILTIN_DEFINITIONS.find((candidate) => candidate.id === "threads")!;
|
||||
document.body.innerHTML = '<div data-pressable-container="true"></div>';
|
||||
|
|
@ -104,6 +120,17 @@ describe("DefinitionEngine", () => {
|
|||
expect(selectDefinition([threads], "https://example.com/home")).toBeUndefined();
|
||||
});
|
||||
|
||||
it("selects Reddit old and X only on their supported domains", () => {
|
||||
const reddit = BUILTIN_DEFINITIONS.find((candidate) => candidate.id === "reddit-old")!;
|
||||
const x = BUILTIN_DEFINITIONS.find((candidate) => candidate.id === "x")!;
|
||||
document.body.innerHTML = '<div id="siteTable"><div class="thing link"></div></div><article data-testid="tweet"></article>';
|
||||
expect(selectDefinition([reddit], "https://old.reddit.com/r/all")).toBe(reddit);
|
||||
expect(selectDefinition([reddit], "https://www.reddit.com/r/all")).toBeUndefined();
|
||||
expect(selectDefinition([x], "https://x.com/home")).toBe(x);
|
||||
expect(selectDefinition([x], "https://twitter.com/alice/status/123")).toBe(x);
|
||||
expect(selectDefinition([x], "https://example.com/home")).toBeUndefined();
|
||||
});
|
||||
|
||||
it("can identify a specific site while its SPA markers are still loading", () => {
|
||||
const threads = BUILTIN_DEFINITIONS.find((candidate) => candidate.id === "threads")!;
|
||||
document.body.innerHTML = "";
|
||||
|
|
|
|||
Loading…
Reference in a new issue