Fix Threads dynamic post discovery
This commit is contained in:
parent
a6689e2975
commit
134157bc71
5 changed files with 28 additions and 8 deletions
|
|
@ -61,6 +61,21 @@ describe("DefinitionEngine", () => {
|
|||
expect(observed).toContain("content warning revealed text");
|
||||
});
|
||||
|
||||
it("discovers Threads posts appended after observation starts", async () => {
|
||||
document.body.innerHTML = '<main><div role="article"><span dir="auto">Initial post</span></div></main>';
|
||||
const threads = BUILTIN_DEFINITIONS.find((candidate) => candidate.id === "threads")!;
|
||||
const engine = new DefinitionEngine(threads);
|
||||
const observed: string[] = [];
|
||||
const stop = engine.observe((posts) => observed.push(...posts.map((post) => post.text)));
|
||||
const post = document.createElement("div");
|
||||
post.setAttribute("role", "article");
|
||||
post.innerHTML = '<span dir="auto">Scrolled-in post</span>';
|
||||
document.querySelector("main")?.append(post);
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
stop();
|
||||
expect(observed).toContain("scrolled-in post");
|
||||
});
|
||||
|
||||
it("discovers Threads posts from stable semantic/data selectors and permalink IDs", () => {
|
||||
document.body.innerHTML = readFileSync("tests/fixtures/threads-feed.html", "utf8");
|
||||
const threads = BUILTIN_DEFINITIONS.find((candidate) => candidate.id === "threads")!;
|
||||
|
|
@ -71,7 +86,7 @@ describe("DefinitionEngine", () => {
|
|||
|
||||
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>';
|
||||
document.body.innerHTML = '<div role="article" data-pressable-container="true"></div>';
|
||||
for (const url of ["https://threads.com/home", "https://www.threads.com/@alice/post/ABC123", "https://threads.net/home", "https://www.threads.net/@alice/post/ABC123"]) {
|
||||
expect(selectDefinition([threads], url)).toBe(threads);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue