Support Top, Latest, Media, and Lists search

Fixes #1335
This commit is contained in:
Zed 2026-07-08 18:56:12 +02:00
commit 61246df9de
14 changed files with 475 additions and 78 deletions

View file

@ -263,12 +263,19 @@ proc getGraphTweetSearch*(query: Query; after=""): Future[Timeline] {.async.} =
if q.len == 0 or q == emptyQuery:
return Timeline(query: query, beginning: true)
let product =
case query.kind
of top: "Top"
# profile media feeds (RSS, multi-user timelines) must stay chronological
of media: (if query.fromUser.len == 0: "Media" else: "Latest")
else: "Latest"
var
variables = %*{
"rawQuery": q,
"count": 20,
"querySource": "typed_query",
"product": "Latest",
"product": product,
"withGrokTranslatedBio":true,
"withQuickPromoteEligibilityTweetFields":false
}
@ -283,33 +290,40 @@ proc getGraphTweetSearch*(query: Query; after=""): Future[Timeline] {.async.} =
# when no more items are available the API just returns the last page in
# full. this detects that and clears the page instead.
if after.len > 0 and result.bottom.len > 0 and maxId.len == 0 and
after[0..<64] == result.bottom[0..<64]:
let prefix = min(64, min(after.len, result.bottom.len))
if prefix > 0 and maxId.len == 0 and
after[0..<prefix] == result.bottom[0..<prefix]:
result.content.setLen(0)
proc getGraphUserSearch*(query: Query; after=""): Future[Result[User]] {.async.} =
proc getGraphProductSearch[T](query: Query; product: string;
after=""): Future[Result[T]] {.async.} =
if query.text.len == 0:
return Result[User](query: query, beginning: true)
return Result[T](query: query, beginning: true)
var
variables = %*{
"rawQuery": query.text,
"count": 20,
"querySource": "typed_query",
"product": "People",
"product": product,
"withGrokTranslatedBio":true,
"withQuickPromoteEligibilityTweetFields":false
}
if after.len > 0:
variables["cursor"] = % after
result.beginning = false
let
let
url = apiReq(graphSearchTimeline, $variables)
js = await fetch(url)
result = parseGraphSearch[User](js, after)
result = parseGraphSearch[T](js, after)
result.query = query
proc getGraphUserSearch*(query: Query; after=""): Future[Result[User]] =
getGraphProductSearch[User](query, "People", after)
proc getGraphListSearch*(query: Query; after=""): Future[Result[ListSearchResult]] =
getGraphProductSearch[ListSearchResult](query, "Lists", after)
proc getPhotoRail*(id: string): Future[PhotoRail] {.async.} =
if id.len == 0: return
let js = await fetch(mediaUrl(id, "", 30))

View file

@ -206,6 +206,20 @@ proc parseGraphCommunity*(js: JsonNode): Community =
if tag.len > 0:
result.hashtags.add tag
proc parseListObject(js: JsonNode; owner: User): List =
List(
id: js{"id_str"}.getStr,
name: js{"name"}.getStr,
username: owner.username,
userId: owner.id,
description: js{"description"}.getStr,
members: js{"member_count"}.getInt,
banner: select(
js{"custom_banner_media", "media_info", "original_img_url"},
js{"default_banner_media", "media_info", "original_img_url"}
).getImageStr
)
proc parseGraphList*(js: JsonNode): List =
if js.isNull: return
@ -215,15 +229,17 @@ proc parseGraphList*(js: JsonNode): List =
if list.isNull:
return
result = List(
id: list{"id_str"}.getStr,
name: list{"name"}.getStr,
username: list{"user_results", "result", "legacy", "screen_name"}.getStr,
userId: list{"user_results", "result", "rest_id"}.getStr,
description: list{"description"}.getStr,
members: list{"member_count"}.getInt,
banner: list{"custom_banner_media", "media_info", "original_img_url"}.getImageStr
result = parseListObject(list, parseGraphUser(list))
proc parseGraphSearchList(js: JsonNode): ListSearchResult =
let owner = parseGraphUser(js)
result = ListSearchResult(
list: parseListObject(js, owner),
owner: owner,
followersContext: js{"followers_context"}.getStr
)
for url in js{"facepile_urls"}:
result.facepiles.add url.getStr
proc parsePoll(js: JsonNode): Poll =
let vals = js{"binding_values"}
@ -808,20 +824,31 @@ proc parseGraphEditHistory*(js: JsonNode; tweetId: string): EditHistory =
if tweetResult.notNull:
result.history.add parseGraphTweet(tweetResult)
iterator extractTweetsFromModuleItems(items: JsonNode): Tweet =
for item in items:
with tweetResult, item.getTweetResult("item"):
let tweet = parseGraphTweet(tweetResult)
if not tweet.available:
tweet.id = item.getEntryId.getId
yield tweet
iterator extractListsFromItems(items: JsonNode): ListSearchResult =
for item in items:
with listJs, item{"item", "itemContent", "list"}:
let r = parseGraphSearchList(listJs)
if r.list.id.len > 0:
yield r
proc extractTweetsFromEntry*(e: JsonNode): seq[Tweet] =
with tweetResult, getTweetResult(e):
var tweet = parseGraphTweet(tweetResult)
let tweet = parseGraphTweet(tweetResult)
if not tweet.available:
tweet.id = e.getEntryId.getId
result.add tweet
return
for item in e{"content", "items"}:
with tweetResult, item.getTweetResult("item"):
var tweet = parseGraphTweet(tweetResult)
if not tweet.available:
tweet.id = item.getEntryId.getId
result.add tweet
for tweet in extractTweetsFromModuleItems(e{"content", "items"}):
result.add tweet
proc parseGraphTimeline*(js: JsonNode; after=""): Profile =
result = Profile(tweets: Timeline(beginning: after.len == 0))
@ -836,12 +863,8 @@ proc parseGraphTimeline*(js: JsonNode; after=""): Profile =
for i in instructions:
if i{"moduleItems"}.notNull:
for item in i{"moduleItems"}:
with tweetResult, item.getTweetResult("item"):
let tweet = parseGraphTweet(tweetResult)
if not tweet.available:
tweet.id = item.getEntryId.getId
result.tweets.content.add tweet
for tweet in extractTweetsFromModuleItems(i{"moduleItems"}):
result.tweets.content.add tweet
continue
if i{"entries"}.notNull:
@ -876,18 +899,13 @@ proc parseGraphPhotoRail*(js: JsonNode): PhotoRail =
for i in instructions:
if i{"moduleItems"}.notNull:
for item in i{"moduleItems"}:
with tweetResult, item.getTweetResult("item"):
let t = parseGraphTweet(tweetResult)
if not t.available:
t.id = item.getEntryId.getId
for t in extractTweetsFromModuleItems(i{"moduleItems"}):
let photo = extractGalleryPhoto(t)
if photo.url.len > 0:
result.add photo
let photo = extractGalleryPhoto(t)
if photo.url.len > 0:
result.add photo
if result.len == 16:
return
if result.len == 16:
return
continue
if i.getTypeName != "TimelineAddEntries":
@ -904,7 +922,7 @@ proc parseGraphPhotoRail*(js: JsonNode): PhotoRail =
if result.len == 16:
return
proc parseGraphSearch*[T: User | Tweets](js: JsonNode; after=""): Result[T] =
proc parseGraphSearch*[T: User | Tweets | ListSearchResult](js: JsonNode; after=""): Result[T] =
result = Result[T](beginning: after.len == 0)
let instructions = select(
@ -920,19 +938,27 @@ proc parseGraphSearch*[T: User | Tweets](js: JsonNode; after=""): Result[T] =
for e in instruction{"entries"}:
let entryId = e.getEntryId
when T is Tweets:
if entryId.startsWith("tweet"):
with tweetRes, getTweetResult(e):
let tweet = parseGraphTweet(tweetRes)
if not tweet.available:
tweet.id = entryId.getId
if entryId.startsWith("tweet") or entryId.startsWith("search-grid"):
for tweet in extractTweetsFromEntry(e):
result.content.add tweet
elif T is User:
if entryId.startsWith("user"):
with userRes, e{"content", "itemContent"}:
result.content.add parseGraphUser(userRes)
elif T is ListSearchResult:
if entryId.startsWith("list-search"):
for list in extractListsFromItems(e{"content", "items"}):
result.content.add list
if entryId.startsWith("cursor-bottom"):
result.bottom = e{"content", "value"}.getStr
elif typ == "TimelineAddToModule":
when T is Tweets:
for tweet in extractTweetsFromModuleItems(instruction{"moduleItems"}):
result.content.add tweet
elif T is ListSearchResult:
for list in extractListsFromItems(instruction{"moduleItems"}):
result.content.add list
elif typ == "TimelineReplaceEntry":
if instruction{"entry_id_to_replace"}.getStr.startsWith("cursor-bottom"):
result.bottom = instruction{"entry", "content", "value"}.getStr

View file

@ -98,9 +98,9 @@ proc getTimeFromMsStr*(js: JsonNode): DateTime =
proc getId*(id: string): int64 {.inline.} =
let start = id.rfind("-")
if start < 0:
return parseBiggestInt(id)
return parseBiggestInt(id[start + 1 ..< id.len])
try:
parseBiggestInt(if start < 0: id else: id[start + 1 ..< id.len])
except ValueError: 0'i64
proc getId*(js: JsonNode): int64 {.inline.} =
case js.kind

View file

@ -104,7 +104,9 @@ proc genQueryUrl*(query: Query): string =
if query.view.len > 0:
params.add "view=" & encodeUrl(query.view)
if query.kind in {tweets, users}:
# media doubles as the profile media tab, where f isn't part of the URL scheme
if query.kind in {tweets, users, lists, top} or
(query.kind == media and query.fromUser.len == 0):
params.add &"f={query.kind}"
if query.text.len > 0:
params.add "q=" & encodeUrl(query.text)

View file

@ -68,7 +68,7 @@ proc createRssRouter*(cfg: Config) =
let
prefs = requestPrefs()
query = initQuery(params(request))
if query.kind != tweets:
if query.kind notin {tweets, top, media}:
resp Http400, showError("Only Tweet searches are allowed for RSS feeds.", cfg)
let

View file

@ -20,9 +20,21 @@ proc createSearchRouter*(cfg: Config) =
let
prefs = requestPrefs()
query = initQuery(params(request))
title = "Search" & (if q.len > 0: " (" & q & ")" else: "")
var query = initQuery(params(request))
# x.com URL compat: f=user and f=list map to our kind names
# (f=live already falls back to tweets/Latest; f=media matches natively)
if @"f" == "user":
query.kind = users
elif @"f" == "list":
query.kind = lists
# media searches support view modes, defaulting like /user/media
if query.kind == QueryKind.media and
query.view notin ["timeline", "grid", "gallery"]:
query.view = prefs.mediaView.toLowerAscii
case query.kind
of users:
if "," in q:
@ -33,12 +45,16 @@ proc createSearchRouter*(cfg: Config) =
except InternalError:
users = Result[User](beginning: true, query: query)
resp renderMain(renderUserSearch(users, prefs), request, cfg, prefs, title)
of tweets:
of tweets, top, QueryKind.media:
let
tweets = await getGraphTweetSearch(query, getCursor())
rss = if cfg.enableRSSSearch: "/search/rss?" & genQueryUrl(query) else: ""
resp renderMain(renderTweetSearch(tweets, prefs, getPath()),
request, cfg, prefs, title, rss=rss)
of lists:
let listResults = await getGraphListSearch(query, getCursor())
resp renderMain(renderListSearch(listResults, prefs, getPath()),
request, cfg, prefs, title)
else:
resp Http404, showError("Invalid search", cfg)

View file

@ -107,6 +107,80 @@
grid-column-gap: 10px;
}
.list-result {
display: flex;
align-items: flex-start;
.list-result-banner {
flex-shrink: 0;
width: 56px;
height: 56px;
margin-right: 10px;
border-radius: 8px;
overflow: hidden;
background-color: var(--darker_grey);
// stay above the tweet-link overlay's hover background
z-index: 1;
img {
width: 100%;
height: 100%;
object-fit: cover;
}
}
.list-result-body {
min-width: 0;
pointer-events: none;
z-index: 1;
a {
pointer-events: all;
}
}
.list-result-title {
align-items: baseline;
}
.list-members {
flex-shrink: 0;
margin-left: 0.3em;
color: var(--fg_faded);
}
.list-result-context {
display: flex;
align-items: center;
flex-wrap: wrap;
margin-top: 2px;
color: var(--fg_faded);
a {
color: var(--fg_dark);
}
a.fullname {
color: var(--fg_color);
}
.list-facepile {
width: 20px;
height: 20px;
border-radius: 50%;
margin-right: 4px;
}
}
.list-result-description {
margin-top: 2px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
pointer-events: all;
}
}
.profile-tabs {
@include search-resize(820px, 5);
@include search-resize(715px, 4);

View file

@ -4,6 +4,26 @@
@include panel(100%, 600px);
}
.timeline-container.media-only {
max-width: none;
width: 100%;
padding: 0 10px;
box-sizing: border-box;
> .tab,
> .timeline-header {
max-width: 900px;
margin-left: auto;
margin-right: auto;
}
}
@media (max-width: 700px) {
.timeline-container.media-only {
padding: 0;
}
}
.timeline > div:not(:first-child) {
border-top: 1px solid var(--border_grey);
}

View file

@ -174,7 +174,7 @@ type
variants*: seq[VideoVariant]
QueryKind* = enum
posts, replies, media, users, tweets, userList, followers, following
posts, replies, media, users, tweets, userList, followers, following, lists, top
RankingMode* = enum
Relevance, Recency, Likes
@ -388,6 +388,12 @@ type
members*: int
banner*: string
ListSearchResult* = object
list*: List
owner*: User
followersContext*: string
facepiles*: seq[string]
CommunityRule* = object
name*: string
description*: string

View file

@ -50,7 +50,7 @@ proc renderHead*(prefs: Prefs; cfg: Config; req: Request; titleText=""; desc="";
let opensearchUrl = getUrlPrefix(cfg) & "/opensearch"
buildHtml(head):
link(rel="stylesheet", type="text/css", href="/css/style.css?v=46")
link(rel="stylesheet", type="text/css", href="/css/style.css?v=50")
link(rel="stylesheet", type="text/css", href="/css/fontello.css?v=7")
if theme.len > 0:

View file

@ -39,28 +39,45 @@ proc renderProfileTabs*(query: Query; username: string): VNode =
li(class=query.getTabClass(tweets)):
a(href=(link & "/search")): text "Search"
proc renderMediaViewTabs*(query: Query; username: string): VNode =
proc mediaViewUrl(query: Query; view: string): string =
var q = query
q.view = view
"?" & genQueryUrl(q)
proc renderMediaViewTabs*(query: Query): VNode =
let currentView = if query.view.len > 0: query.view else: "timeline"
let base = "/" & username & "/media?view="
func cls(view: string): string =
if currentView == view: "tab-item active" else: "tab-item"
buildHtml(ul(class="tab media-view-tabs")):
li(class=cls("timeline")):
a(href=(base & "timeline")): text "Timeline"
a(href=query.mediaViewUrl("timeline")): text "Timeline"
li(class=cls("grid")):
a(href=(base & "grid")): text "Grid"
a(href=query.mediaViewUrl("grid")): text "Grid"
li(class=cls("gallery")):
a(href=(base & "gallery")): text "Gallery"
a(href=query.mediaViewUrl("gallery")): text "Gallery"
proc renderSearchTabs*(query: Query): VNode =
var q = query
# the media view mode only applies to the Media tab
q.view = ""
buildHtml(ul(class="tab")):
li(class=query.getTabClass(top)):
q.kind = top
a(href=("?" & genQueryUrl(q))): text "Top"
li(class=query.getTabClass(tweets)):
q.kind = tweets
a(href=("?" & genQueryUrl(q))): text "Tweets"
a(href=("?" & genQueryUrl(q))): text "Latest"
li(class=query.getTabClass(media)):
q.kind = media
q.view = query.view
a(href=("?" & genQueryUrl(q))): text "Media"
li(class=query.getTabClass(users)):
q.kind = users
q.view = ""
a(href=("?" & genQueryUrl(q))): text "Users"
li(class=query.getTabClass(lists)):
q.kind = lists
a(href=("?" & genQueryUrl(q))): text "Lists"
proc isPanelOpen(q: Query): bool =
q.fromUser.len == 0 and (q.filters.len > 0 or q.excludes.len > 0 or
@ -71,7 +88,7 @@ proc renderSearchPanel*(query: Query): VNode =
let action = if user.len > 0: &"/{user}/search" else: "/search"
buildHtml(form(`method`="get", action=action,
class="search-field", autocomplete="off")):
hiddenField("f", "tweets")
hiddenField("f", $query.kind)
genInput("q", "", query.text, "Enter search...", class="pref-inline")
button(`type`="submit"): icon "search"
@ -102,7 +119,11 @@ proc renderSearchPanel*(query: Query): VNode =
proc renderTweetSearch*(results: Timeline; prefs: Prefs; path: string;
pinned=none(Tweet)): VNode =
let query = results.query
buildHtml(tdiv(class="timeline-container")):
let containerClass =
if query.fromUser.len == 0 and query.kind == media and
query.view == "gallery": "timeline-container media-only"
else: "timeline-container"
buildHtml(tdiv(class=containerClass)):
if query.fromUser.len > 1:
tdiv(class="timeline-header"):
text query.fromUser.join(" | ")
@ -111,7 +132,7 @@ proc renderTweetSearch*(results: Timeline; prefs: Prefs; path: string;
if query.kind != media or query.view != "gallery":
renderProfileTabs(query, query.fromUser.join(","))
if query.kind == media and query.fromUser.len == 1:
renderMediaViewTabs(query, query.fromUser[0])
renderMediaViewTabs(query)
if query.fromUser.len == 0 or query.kind == tweets:
tdiv(class="timeline-header"):
@ -119,16 +140,31 @@ proc renderTweetSearch*(results: Timeline; prefs: Prefs; path: string;
if query.fromUser.len == 0:
renderSearchTabs(query)
if query.kind == media:
renderMediaViewTabs(query)
renderTimelineTweets(results, prefs, path, pinned)
proc renderSearchForm(kind, placeholder, value: string): VNode =
buildHtml(form(`method`="get", action="/search",
class="search-field", autocomplete="off")):
hiddenField("f", kind)
genInput("q", "", value, placeholder, class="pref-inline")
button(`type`="submit"): icon "search"
proc renderUserSearch*(results: Result[User]; prefs: Prefs): VNode =
buildHtml(tdiv(class="timeline-container")):
tdiv(class="timeline-header"):
form(`method`="get", action="/search", class="search-field", autocomplete="off"):
hiddenField("f", "users")
genInput("q", "", results.query.text, "Enter username...", class="pref-inline")
button(`type`="submit"): icon "search"
renderSearchForm("users", "Enter username...", results.query.text)
renderSearchTabs(results.query)
renderTimelineUsers(results, prefs)
proc renderListSearch*(results: Result[ListSearchResult]; prefs: Prefs;
path: string): VNode =
buildHtml(tdiv(class="timeline-container")):
tdiv(class="timeline-header"):
renderSearchForm("lists", "Enter search...", results.query.text)
renderSearchTabs(results.query)
renderTimelineLists(results, prefs, path)

View file

@ -114,6 +114,84 @@ proc renderTimelineUsers*(results: Result[User]; prefs: Prefs; path=""): VNode =
else:
renderNoMore()
proc mentionUsername(word: string): string =
# "@user" -> "user" for well-formed mentions, "" otherwise
if word.len > 1 and word[0] == '@' and
word[1 .. ^1].allCharsInSet({'A'..'Z', 'a'..'z', '0'..'9', '_'}):
word[1 .. ^1]
else: ""
proc mentionedUser(s: string): string =
# last @mention in strings like "65 followers including @user"
let words = s.split(' ')
for i in countdown(words.high, 0):
result = mentionUsername(words[i])
if result.len > 0: return
proc renderMentionedText(s: string): VNode =
# linkify @mentions in plain API strings like "65 followers including @user"
let words = s.split(' ')
buildHtml(span):
for i in 0 ..< words.len:
if i > 0: text " "
let username = mentionUsername(words[i])
if username.len > 0:
a(href=("/" & username)): text words[i]
else:
text words[i]
proc renderListCard(r: ListSearchResult): VNode =
let listUrl = "/i/lists/" & r.list.id
buildHtml(tdiv(class="timeline-item list-result")):
a(class="tweet-link", href=listUrl)
a(class="list-result-banner", href=listUrl):
if r.list.banner.len > 0:
genImg(r.list.banner)
tdiv(class="list-result-body"):
tdiv(class="list-result-title fullname-and-username"):
a(class="list-name fullname", href=listUrl): text r.list.name
span(class="list-members"):
text &"· {insertSep($r.list.members, ',')} members"
tdiv(class="list-result-context"):
if r.followersContext.len > 0:
# the first facepile belongs to the "including @user" account
let mentioned = mentionedUser(r.followersContext)
for i in 0 ..< r.facepiles.len:
if i == 0 and mentioned.len > 0:
a(class="facepile-link", href=("/" & mentioned)):
genImg(r.facepiles[i], class="list-facepile")
else:
genImg(r.facepiles[i], class="list-facepile")
renderMentionedText(r.followersContext)
else:
if r.owner.username.len > 0:
a(class="facepile-link", href=("/" & r.owner.username)):
genImg(r.owner.getUserPic("_mini"), class="list-facepile")
else:
genImg(r.owner.getUserPic("_mini"), class="list-facepile")
linkUser(r.owner, class="fullname")
linkUser(r.owner, class="username")
if r.list.description.len > 0:
tdiv(class="list-result-description"):
text r.list.description
proc renderTimelineLists*(results: Result[ListSearchResult]; prefs: Prefs;
path=""): VNode =
buildHtml(tdiv(class="timeline")):
if not results.beginning:
renderNewer(results.query, path)
if results.content.len > 0:
for list in results.content:
renderListCard(list)
if results.bottom.len > 0:
renderMore(results.query, results.bottom)
renderToTop()
elif results.beginning:
renderNoneFound()
else:
renderNoMore()
proc filterThreads(threads: seq[Tweets]; prefs: Prefs): seq[Tweets] =
var retweets: seq[int64]
for thread in threads:

View file

@ -55,14 +55,19 @@ class Timeline(object):
protected = '.timeline-protected'
photo_rail = '.photo-rail-grid'
media_view_tabs = '.media-view-tabs'
media_view_timeline = '.media-view-tabs a[href$="media?view=timeline"]'
media_view_grid = '.media-view-tabs a[href$="media?view=grid"]'
media_view_gallery = '.media-view-tabs a[href$="media?view=gallery"]'
media_view_timeline = '.media-view-tabs a[href*="view=timeline"]'
media_view_grid = '.media-view-tabs a[href*="view=grid"]'
media_view_gallery = '.media-view-tabs a[href*="view=gallery"]'
media_view_active = '.media-view-tabs .tab-item.active a'
grid_view = '.timeline.media-grid-view'
gallery_view = '.timeline.media-gallery-view'
class Search(object):
tab_item = '.tab .tab-item'
tab_active = '.tab .tab-item.active a'
class Conversation(object):
main = '.main-tweet'
before = '.before-tweet'

View file

@ -1,9 +1,129 @@
from base import BaseTestCase
from parameterized import parameterized
from base import BaseTestCase, Search
#class SearchTest(BaseTestCase):
#@parameterized.expand([['@mobile_test'], ['@mobile_test_2']])
#def test_username_search(self, username):
#self.search_username(username)
#self.assert_text(f'{username}')
# [url, expected active tab label]
active_tabs = [
['search?f=tweets&q=nasa', 'Latest'],
['search?f=top&q=nasa', 'Top'],
['search?f=media&q=nasa', 'Media'],
['search?f=users&q=nasa', 'Users'],
['search?f=lists&q=test', 'Lists'],
# unknown/hostile values fall back to Latest
['search?f=garbage&q=nasa', 'Latest'],
['search?f=%3Cscript%3E&q=nasa', 'Latest'],
# x.com URL compat: f=live/user/list (f=media/top match natively)
['search?f=live&q=nasa', 'Latest'],
['search?f=user&q=nasa', 'Users'],
['search?f=list&q=test', 'Lists'],
]
results_pages = [
['search?f=tweets&q=nasa'],
['search?f=top&q=nasa'],
['search?f=media&q=nasa'],
]
class SearchProductTest(BaseTestCase):
@parameterized.expand(active_tabs)
def test_active_tab(self, page, expected_active):
self.open_nitter(page)
active = self.get_text(Search.tab_active)
self.assert_equal(active.strip(), expected_active)
def test_all_tabs_present(self):
self.open_nitter('search?f=tweets&q=nasa')
tabs = self.find_elements(Search.tab_item)
labels = [t.text.strip() for t in tabs]
self.assert_equal(labels, ['Top', 'Latest', 'Media', 'Users', 'Lists'])
@parameterized.expand(results_pages)
def test_results_render(self, page):
self.open_nitter(page)
self.assert_element('.timeline .timeline-item')
def test_tab_links_carry_kind(self):
self.open_nitter('search?f=tweets&q=nasa')
self.assert_element('.tab-item a[href="?f=top&q=nasa"]')
self.assert_element('.tab-item a[href="?f=media&q=nasa"]')
self.assert_element('.tab-item a[href="?f=tweets&q=nasa"]')
self.assert_element('.tab-item a[href="?f=users&q=nasa"]')
self.assert_element('.tab-item a[href="?f=lists&q=nasa"]')
def test_show_more_preserves_kind(self):
self.open_nitter('search?f=media&q=nasa')
href = self.get_attribute('.show-more a', 'href')
self.assert_true('f=media' in href, f'f=media missing from: {href}')
def test_search_form_preserves_kind(self):
self.open_nitter('search?f=top&q=nasa')
self.assert_element_present('.search-field input[name="f"][value="top"]')
def test_media_operators_compose(self):
self.open_nitter('search?f=media&q=nasa&e-nativeretweets=on')
self.assert_element('.timeline .timeline-item')
@parameterized.expand([['DAAC'], ['AB'], ['maxid:'], ['maxid:abc']])
def test_garbage_cursor_no_crash(self, cursor):
# short/invalid cursors must render the page, not a 500 error
self.open_nitter(f'search?f=media&q=nasa&cursor={cursor}')
self.assert_element(Search.tab_active)
def test_no_results(self):
self.open_nitter('search?f=media&q=xkqzjwv_no_results_2026')
self.assert_text('No items found', '.timeline-none')
def test_list_results_render(self):
self.open_nitter('search?f=lists&q=test')
self.assert_element('.timeline-item.list-result')
self.assert_element('.list-result .list-name')
self.assert_element('.list-result .list-members')
def test_list_card_links_to_list(self):
self.open_nitter('search?f=lists&q=test')
href = self.get_attribute('.list-result .list-name', 'href')
self.assert_true('/i/lists/' in href, f'unexpected list link: {href}')
def test_list_row_clickable(self):
self.open_nitter('search?f=lists&q=test')
href = self.get_attribute('.list-result a.tweet-link', 'href')
self.assert_true('/i/lists/' in href, f'unexpected row link: {href}')
def test_list_avatar_links_to_user(self):
self.open_nitter('search?f=lists&q=test')
# the avatar link in a row must point at the user named in that row
row = '.list-result:has(a.facepile-link)'
self.assert_element(f'{row} a.facepile-link > img')
href = self.get_attribute(f'{row} a.facepile-link', 'href')
ctx = self.get_text(f'{row} .list-result-context')
mentioned = ctx.split('@')[-1].strip()
self.assert_true(href.endswith('/' + mentioned),
f'avatar link {href} does not match @{mentioned}')
def test_list_pagination_preserves_kind(self):
self.open_nitter('search?f=lists&q=test')
href = self.get_attribute('.show-more a', 'href')
self.assert_true('f=lists' in href, f'f=lists missing from: {href}')
def test_list_garbage_cursor_no_crash(self):
self.open_nitter('search?f=lists&q=test&cursor=DAAC')
self.assert_element(Search.tab_active)
def test_media_view_tabs_present(self):
self.open_nitter('search?f=media&q=nasa')
tabs = self.find_elements('.media-view-tabs .tab-item')
labels = [t.text.strip() for t in tabs]
self.assert_equal(labels, ['Timeline', 'Grid', 'Gallery'])
def test_media_view_grid(self):
self.open_nitter('search?f=media&q=nasa&view=grid')
self.assert_element('.timeline.media-grid-view')
def test_media_view_gallery(self):
self.open_nitter('search?f=media&q=nasa&view=gallery')
self.assert_element('.timeline.media-gallery-view .gallery-masonry')
def test_media_view_tabs_only_on_media(self):
self.open_nitter('search?f=tweets&q=nasa')
self.assert_element_not_present('.media-view-tabs')