// AN INVENTED TRENDING-PAGE CAPTURE, for tests and the editor's e2e fake // browser (fakeXProfileBrowser.ts). Every id, handle, name and word here is // made up; the SHAPES are X's public GraphQL tweet-result shapes as this repo // already reads them (xPlaywrightFetcher.ts): `{__typename: "Tweet", rest_id, // core.user_results.result, legacy}`, a TweetWithVisibilityResults wrapper, a // quoted result, a promoted entry. The operation names are invented too. The // page's own answer (title, summary, tabs) and the timeline id its requests // name are in the shape the first real read showed (lane x-followups); the // whole real shape, instruction by instruction, is xTrendingRealShape.ts. export const FIXTURE_TREND_ID = "1900000000000000001"; export const FIXTURE_TREND_URL = `https://x.com/i/trending/${FIXTURE_TREND_ID}`; export const FIXTURE_TREND_OP = "ExampleTrendPage"; export const FIXTURE_TIMELINE_OP = "ExampleTrendTimeline"; // X's own words for the page (invented), and the page's two tabs: the // timeline the fixture's requests name is the first. export const FIXTURE_TITLE = "Kettle festival opens"; export const FIXTURE_SUMMARY = "The annual kettle festival opened this morning to a long queue."; export const FIXTURE_LAST_UPDATED_MS = Date.UTC(2026, 10, 16, 11, 30, 0); export const FIXTURE_TOP_TIMELINE = "fixture-timeline-top"; export const FIXTURE_LATEST_TIMELINE = "fixture-timeline-latest"; // The page's own answer, as the real page shapes it. export function fixtureTrendPageBody(): Record { return { data: { ai_trend_by_rest_id: { rest_id: FIXTURE_TREND_ID, result: { page: { article: { article_text: { entities: [], text: FIXTURE_SUMMARY }, title: FIXTURE_TITLE }, last_updated_at_ms: FIXTURE_LAST_UPDATED_MS, post_timelines: [ { label: "Top", post_timeline: { id: FIXTURE_TOP_TIMELINE } }, { label: "Latest", post_timeline: { id: FIXTURE_LATEST_TIMELINE } }, ], }, rest_id: FIXTURE_TREND_ID, }, }, }, }; } export type FixtureTweet = { id: string; handle: string; name?: string; text: string; // "Wed Oct 10 20:19:24 +0000 2018", X's legacy form. createdAt?: string; media?: Array<"photo" | "video" | "animated_gif">; quoted?: FixtureTweet; replyTo?: { id: string; handle: string }; // Names under user.core (newer answers) instead of user.legacy. namesInCore?: boolean; // Wrapped in a TweetWithVisibilityResults, the inner tweet untagged. wrapped?: boolean; promoted?: boolean; }; export function fixtureTweetResult(t: FixtureTweet): Record { const names = { screen_name: t.handle, name: t.name ?? t.handle }; const tweet: Record = { rest_id: t.id, core: { user_results: { result: { __typename: "User", rest_id: `9${t.id.slice(-6)}`, ...(t.namesInCore ? { core: names, legacy: {} } : { legacy: names }) } } }, legacy: { id_str: t.id, conversation_id_str: t.replyTo?.id ?? t.id, created_at: t.createdAt ?? "Mon Nov 16 12:00:00 +0000 2026", full_text: t.text, lang: "en", favorite_count: 12, retweet_count: 3, reply_count: 1, quote_count: 0, entities: { urls: [] }, ...(t.media?.length ? { extended_entities: { media: t.media.map((type, i) => ({ type, media_key: `3_${t.id}${i}`, media_url_https: `https://pbs.twimg.com/media/Fixture${t.id.slice(-4)}${i}.jpg`, // A video or a GIF: two progressive mp4s and a playlist, as X lists them. ...(type === "photo" ? {} : { video_info: { variants: [ { content_type: "application/x-mpegURL", url: `https://video.twimg.com/ext_tw_video/${t.id}${i}/pl/list.m3u8` }, { content_type: "video/mp4", bitrate: 632000, url: `https://video.twimg.com/ext_tw_video/${t.id}${i}/vid/320x180/low.mp4?tag=12` }, { content_type: "video/mp4", bitrate: 2176000, url: `https://video.twimg.com/ext_tw_video/${t.id}${i}/vid/1280x720/high.mp4?tag=12` }, ], }, }), })), }, } : {}), ...(t.quoted ? { quoted_status_id_str: t.quoted.id, is_quote_status: true } : {}), ...(t.replyTo ? { in_reply_to_status_id_str: t.replyTo.id, in_reply_to_screen_name: t.replyTo.handle } : {}), }, ...(t.quoted ? { quoted_status_result: { result: fixtureTweetResult(t.quoted) } } : {}), }; return t.wrapped ? { __typename: "TweetWithVisibilityResults", tweet } : { __typename: "Tweet", ...tweet }; } function entry(t: FixtureTweet): Record { return { entryId: `tweet-${t.id}`, content: { entryType: "TimelineTimelineItem", itemContent: { itemType: "TimelineTweet", tweet_results: { result: fixtureTweetResult(t) }, ...(t.promoted ? { promotedMetadata: { advertiser_results: {} } } : {}), }, }, }; } // One timeline answer holding these posts. export function fixtureTimelineBody(tweets: FixtureTweet[], bottom: string = FIXTURE_BOTTOM_CURSOR): Record { return { data: { timeline: { instructions: [ { type: "TimelineAddEntries", entries: [...tweets.map(entry), { entryId: "cursor-bottom-1", content: { entryType: "TimelineTimelineCursor", cursorType: "Bottom", value: bottom } }] }, ], }, }, }; } export const FIXTURE_FIRST_PAGE: FixtureTweet[] = [ { id: "1900000000000001001", handle: "teapot_news", name: "Teapot News", text: "The kettle festival opens today.", media: ["photo", "photo"] }, { id: "1900000000000001002", handle: "saucer_fan", text: "Quoting the festival post.", wrapped: true, quoted: { id: "1900000000000000900", handle: "kettle_org", text: "Festival programme attached.", media: ["photo"] }, }, { id: "1900000000000001003", handle: "advert_co", text: "Buy our kettles.", promoted: true }, { id: "1900000000000001004", handle: "spout_clips", name: "Spout Clips", text: "Video from the opening.", media: ["video"], namesInCore: true }, ]; export const FIXTURE_SECOND_PAGE: FixtureTweet[] = [ { id: "1900000000000001004", handle: "spout_clips", name: "Spout Clips", text: "Video from the opening.", media: ["video"], namesInCore: true }, { id: "1900000000000001005", handle: "lid_watch", text: "A reply about the queue.", replyTo: { id: "1900000000000001001", handle: "teapot_news" }, media: ["animated_gif"] }, ]; // The bottom cursor every fixture timeline answer ends with, and which the // page's next request for that timeline carries. export const FIXTURE_BOTTOM_CURSOR = "fixture-cursor"; const graphqlUrl = (op: string, n: number, cursor?: string, timelineId: string = FIXTURE_TOP_TIMELINE) => `https://x.com/i/api/graphql/fixtureQueryId${n}/${op}?variables=${encodeURIComponent( JSON.stringify({ rest_id: FIXTURE_TREND_ID, ...(op === FIXTURE_TIMELINE_OP ? { timelineId } : {}), ...(cursor ? { cursor } : {}), }), )}`; // The address of a request for the page's timeline (the tab the page opens // on): its `variables` name the timeline, and the cursor it continues from // when it is not the first. export function fixtureTimelineUrl(n = 2, cursor?: string, timelineId: string = FIXTURE_TOP_TIMELINE): string { return graphqlUrl(FIXTURE_TIMELINE_OP, n, cursor, timelineId); } // THE PAGE'S OTHER TAB, "Latest" (lane x-followups): its own timeline and its // own cursor. `fixtureLatestFirst` is what pressing the tab brings; // `fixtureLatestContinuation` what a scroll then brings (no post: the tab's end). export const FIXTURE_LATEST_CURSOR = "fixture-latest-cursor"; export function fixtureLatestFirst(tweets: FixtureTweet[], n = 20): FixtureResponse { return { url: graphqlUrl(FIXTURE_TIMELINE_OP, n, undefined, FIXTURE_LATEST_TIMELINE), status: 200, body: fixtureTimelineBody(tweets, FIXTURE_LATEST_CURSOR) }; } export function fixtureLatestContinuation(tweets: FixtureTweet[] = [], n = 21): FixtureResponse { return { url: graphqlUrl(FIXTURE_TIMELINE_OP, n, FIXTURE_LATEST_CURSOR, FIXTURE_LATEST_TIMELINE), status: 200, body: fixtureTimelineBody(tweets, FIXTURE_LATEST_CURSOR) }; } // What "Latest" lists: a post only it shows, and two that "Top" shows too. export const FIXTURE_LATEST_PAGE: FixtureTweet[] = [ { id: "1900000000000001009", handle: "lid_watch", text: "Just now: the doors are open." }, { id: "1900000000000001001", handle: "teapot_news", name: "Teapot News", text: "The kettle festival opens today.", media: ["photo", "photo"] }, { id: "1900000000000001005", handle: "lid_watch", text: "A reply about the queue.", replyTo: { id: "1900000000000001001", handle: "teapot_news" }, media: ["animated_gif"] }, ]; // The page with both tabs: "Top" as fixtureTrendingResponses plays it (read // to its end by a continuation that brings nothing), and a "Latest" tab that // can be pressed and is read to its end too. export function fixtureTwoTabResponses(latest: FixtureTweet[] = FIXTURE_LATEST_PAGE): { load: FixtureResponse[]; scrolls: FixtureResponse[][]; tabs: Record< string, { load?: FixtureResponse[]; scrolls?: FixtureResponse[][]; hidden?: boolean; // The fake page's other ways a "Latest" may be (social/fakeXProfileBrowser.ts FakeTrendingTab). role?: "tab" | "link" | "button"; outsideTablist?: boolean; clickError?: string; countHangs?: boolean; navigatesTo?: string; scrollHangs?: boolean; } >; } { const top = fixtureTrendingResponses(); return { load: top.load, scrolls: [top.scrolls[0], [fixtureContinuation([], 5)], []], tabs: { Latest: { load: [fixtureLatestFirst(latest)], scrolls: [[fixtureLatestContinuation([])], []] } }, }; } // The page asking its timeline for MORE: the request carries the bottom cursor // of the answer before it. With no post it is how a page's end looks. export function fixtureContinuation(tweets: FixtureTweet[] = [], n = 9, cursor: string = FIXTURE_BOTTOM_CURSOR): FixtureResponse { return { url: graphqlUrl(FIXTURE_TIMELINE_OP, n, cursor), status: 200, body: fixtureTimelineBody(tweets) }; } export type FixtureResponse = { url: string; status: number; body?: unknown; text?: string }; // What the page fetches on load, and after each scroll to the bottom. export function fixtureTrendingResponses(): { load: FixtureResponse[]; scrolls: FixtureResponse[][] } { return { load: [ { url: graphqlUrl(FIXTURE_TREND_OP, 1), status: 200, body: fixtureTrendPageBody() }, { url: graphqlUrl(FIXTURE_TIMELINE_OP, 2), status: 200, body: fixtureTimelineBody(FIXTURE_FIRST_PAGE) }, // Not GraphQL: never saved. { url: "https://x.com/i/api/1.1/example.json", status: 200, body: { ok: true } }, // Another surface's posts: saved, never read as the page's. { url: graphqlUrl("HomeTimeline", 3), status: 200, body: fixtureTimelineBody([{ id: "1900000000000007777", handle: "home_only", text: "Not on the trending page." }]) }, ], scrolls: [[fixtureContinuation(FIXTURE_SECOND_PAGE, 4)], [], []], }; }