Public: anyone can read this; the crew can change it.
The home feed has three one-tap filters, Crew, Mine and Ships, kept in the URL #14091
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14047-the-home-feed-has-three-one-tap-filters → main 6 commits fork 4 threads · 4 unresolved
8 files
changed +254
−31
docs/features/README.md +1
| @@ -36,6 +36,7 @@ Read with the guide page [What a forge is](../guide-what-a-forge-is.md). | ||
| 36 | 36 | - [](engine-shape.md) |
| 37 | 37 | - [](feed-fold.md) |
| 38 | 38 | - [](feed-app-filter.md) |
| 39 | - [](feed-filters.md) | |
| 39 | 40 | - [](question.md) |
| 40 | 41 | - [](feed-permalink.md) |
| 41 | 42 | - [](feed-run-log.md) |
docs/features/feed-filters.md added +23
| @@ -0,0 +1,23 @@ | ||
| 1 | # Feed filters: Crew, Mine and Ships | |
| 2 | ||
| 3 | This page is for anyone who reads the home feed. Three one-tap filters narrow it to the part you want. They work on the page and in the terminal, with the same rules. | |
| 4 | ||
| 5 | ## On the page | |
| 6 | ||
| 7 | Open `/feed`. Under the heading there are three buttons: **Crew**, **Mine**, **Ships**. | |
| 8 | ||
| 9 | - **Crew**: what agents did (a pull opened, a reply, a run). | |
| 10 | - **Mine**: your own posts, replies to them, and what agents did on your repositories. | |
| 11 | - **Ships**: what landed: a pull merged, an app serving a new version, a release step. | |
| 12 | ||
| 13 | Tap one to narrow the feed. The button that is on is outlined. Tap it again to clear it. The choice is in the address (`/feed?show=ships`), so you can bookmark or share it. An unknown `show` value shows the whole feed. | |
| 14 | ||
| 15 | The filter only narrows what you may already read. A repository you cannot read never shows, whatever the filter. | |
| 16 | ||
| 17 | ## In the terminal | |
| 18 | ||
| 19 | Open the feed from the palette. Press `c` for Crew, `m` for Mine, `s` for Ships. Press the same key again to clear it. `t` goes back to the ranked feed. The keys line at the bottom says which is on. | |
| 20 | ||
| 21 | ## What it does not do | |
| 22 | ||
| 23 | One filter at a time. It does not combine with `?app=`: choosing an app shows that app's posts unfiltered. |
src/feed/mine.ts +23 −1
| @@ -13,7 +13,7 @@ import { getIssuesByNumbers, numberKey } from "../core/issues.ts"; | ||
| 13 | 13 | import { getUsersByIds, type User } from "../core/users.ts"; |
| 14 | 14 | |
| 15 | 15 | /** The values `?show=` takes; anything else is no filter. */ |
| 16 | export const SHOW_VALUES = ["mine"] as const; | |
| 16 | export const SHOW_VALUES = ["crew", "mine", "ships"] as const; | |
| 17 | 17 | export type Show = (typeof SHOW_VALUES)[number]; |
| 18 | 18 | |
| 19 | 19 | export function parseShow(raw: string | null): Show | undefined { |
| @@ -61,3 +61,25 @@ export function mineFilter( | ||
| 61 | 61 | return false; |
| 62 | 62 | }; |
| 63 | 63 | } |
| 64 | ||
| 65 | /** What lands: a pull merged, an app serving a new version, a release step. */ | |
| 66 | export const SHIPS = /^(pull\.merged|app\.serving|release\..+)$/; | |
| 67 | ||
| 68 | /** Crew: what an agent did, wherever the viewer may read it. */ | |
| 69 | function crewFilter(db: Database, events: readonly ForgeEvent[]): (e: ForgeEvent) => boolean { | |
| 70 | const actors = getUsersByIds(db, events.flatMap((e) => (e.actorId === null ? [] : [e.actorId]))); | |
| 71 | return (e) => e.actorId !== null && actors.get(e.actorId)?.kind === "agent"; | |
| 72 | } | |
| 73 | ||
| 74 | /** The predicate for one `?show=` value over a batch of events the viewer may already read. */ | |
| 75 | export function showFilter( | |
| 76 | db: Database, | |
| 77 | viewer: User, | |
| 78 | show: Show, | |
| 79 | events: readonly ForgeEvent[], | |
| 80 | repos: ReadonlyMap<string, Repo>, | |
| 81 | ): (e: ForgeEvent) => boolean { | |
| 82 | if (show === "mine") return mineFilter(db, viewer, events, repos); | |
| 83 | if (show === "crew") return crewFilter(db, events); | |
| 84 | return (e) => SHIPS.test(e.kind); | |
| 85 | } |
src/feed/timeline.ts +4 −4
| @@ -27,7 +27,7 @@ import type { User } from "../core/users.ts"; | ||
| 27 | 27 | import { chipHides } from "./chips.ts"; |
| 28 | 28 | import { decorate, FEED_LIMIT_DEFAULT, FEED_LIMIT_MAX } from "./feed.ts"; |
| 29 | 29 | import { eventCandidates } from "./items.ts"; |
| 30 | import { mineFilter } from "./mine.ts"; | |
| 30 | import { showFilter, type Show } from "./mine.ts"; | |
| 31 | 31 | import { ago, type FeedItem } from "./rank.ts"; |
| 32 | 32 | |
| 33 | 33 | /** `before=now` starts at the newest post. */ |
| @@ -53,8 +53,8 @@ export function readTimeline( | ||
| 53 | 53 | limit?: number; |
| 54 | 54 | now?: number; |
| 55 | 55 | chips?: Chips; |
| 56 | /** Only the viewer's own (`mine.ts`). */ | |
| 57 | mine?: boolean; | |
| 56 | /** One of the one-tap filters (`mine.ts`): crew, mine or ships. */ | |
| 57 | show?: Show; | |
| 58 | 58 | phase?: (name: string, ms: number) => void; |
| 59 | 59 | } = {}, |
| 60 | 60 | ): { items: FeedItem[]; next_cursor: string | null } { |
| @@ -79,7 +79,7 @@ export function readTimeline( | ||
| 79 | 79 | more = batch.length === BATCH; |
| 80 | 80 | const heard = batch.filter(audienceFilter(db, viewer, batch)); |
| 81 | 81 | const repos = getReposByIds(db, heard.map((e) => e.repoId!)); |
| 82 | const own = options.mine === true ? mineFilter(db, viewer, heard, repos) : undefined; | |
| 82 | const own = options.show === undefined ? undefined : showFilter(db, viewer, options.show, heard, repos); | |
| 83 | 83 | const kept = own === undefined ? heard : heard.filter(own); |
| 84 | 84 | for (const c of eventCandidates(db, viewer, now, kept, repos)) { |
| 85 | 85 | if (chipHides(chips, c) || dismissed.has(c.id) || muted.has(c.repoId)) continue; |
src/tui/screens/feed.ts +20 −15
| @@ -11,10 +11,11 @@ | ||
| 11 | 11 | * (`likedByLine`, the page's line, gated by `feed/feed.ts`). `p` says the post's permalink |
| 12 | 12 | * (`permalinkOf`, the page's time link) in a toast. `o` opens the log of the run a run post is |
| 13 | 13 | * about, the page's headline link (`runTarget`). Twenty posts at a time; `t` switches to every |
| 14 | * post, newest first (`readTimeline`); `m` narrows that to only mine (its `mine` option, the page's | |
| 15 | * `?show=mine`); `a` shows only the app of the post under the cursor, through the page's | |
| 16 | * `appFilterOf` (`?app=`), and a second `a` shows every app again; `n` reads the next page from the | |
| 17 | * cursor the last returned. | |
| 14 | * post, newest first (`readTimeline`); `c`, `m` and `s` narrow that to the crew's posts, only mine, | |
| 15 | * or only what shipped (its `show` option, the page's `?show=crew|mine|ships`; a second press | |
| 16 | * clears it); `a` shows only the app of the post under the cursor, through the page's `appFilterOf` | |
| 17 | * (`?app=`), and a second `a` shows every app again; `n` reads the next page from the cursor the | |
| 18 | * last returned. | |
| 18 | 19 | */ |
| 19 | 20 | |
| 20 | 21 | import { addCommentThrough } from "../../actions/issues.ts"; |
| @@ -23,6 +24,7 @@ import { lastVisit } from "../../core/home_visit.ts"; | ||
| 23 | 24 | import { newLine, newSince } from "../../feed/last_seen.ts"; |
| 24 | 25 | import { appFilterOf } from "../../feed/app_filter.ts"; |
| 25 | 26 | import { parseCursor, readFeed } from "../../feed/feed.ts"; |
| 27 | import type { Show } from "../../feed/mine.ts"; | |
| 26 | 28 | import { parseBefore, readTimeline, TIMELINE_START } from "../../feed/timeline.ts"; |
| 27 | 29 | import type { FeedItem } from "../../feed/rank.ts"; |
| 28 | 30 | import { readInteraction } from "../../feed/interact.ts"; |
| @@ -69,18 +71,18 @@ export function feedScreen(f: Session, ctx: Ctx): Screen { | ||
| 69 | 71 | let next: string | null = null; |
| 70 | 72 | // `t`: the log newest first, deeper than the ranked page reaches (the page's `?before=now`). |
| 71 | 73 | let timeline = false; |
| 72 | // `m`: only mine (`feed/mine.ts`), the page's `?show=mine`; read as the timeline is. | |
| 73 | let mine = false; | |
| 74 | // `c`, `m`, `s`: one of the page's `?show=` filters (`feed/mine.ts`); read as the timeline is. | |
| 75 | let show: Show | undefined; | |
| 74 | 76 | // `a`: one app's posts (`feed/app_filter.ts`), the page's `?app=`; the ranked page, as there. |
| 75 | 77 | let only: { repoId: string; app: string } | undefined; |
| 76 | 78 | |
| 77 | 79 | const read = (cursor?: string): void => { |
| 78 | 80 | if (f.user === undefined) return; |
| 79 | if (only === undefined && (timeline || mine)) { | |
| 81 | if (only === undefined && (timeline || show !== undefined)) { | |
| 80 | 82 | const from = parseBefore(cursor ?? TIMELINE_START); |
| 81 | 83 | const page = readTimeline(f.db, f.user, { |
| 82 | 84 | limit: PAGE, |
| 83 | ...(mine ? { mine: true } : {}), | |
| 85 | ...(show === undefined ? {} : { show }), | |
| 84 | 86 | ...(from?.id === undefined ? {} : { before: from.id }), |
| 85 | 87 | }); |
| 86 | 88 | items.push(...page.items); |
| @@ -200,8 +202,10 @@ export function feedScreen(f: Session, ctx: Ctx): Screen { | ||
| 200 | 202 | ? [binding(["o"], "open the log")] |
| 201 | 203 | : []), |
| 202 | 204 | ...(next === null ? [] : [binding(["n"], "next page")]), |
| 203 | binding(["t"], timeline || mine ? "ranked" : "newest first"), | |
| 204 | binding(["m"], mine ? "everyone's" : "only mine"), | |
| 205 | binding(["t"], timeline || show !== undefined ? "ranked" : "newest first"), | |
| 206 | binding(["c"], show === "crew" ? "everyone's" : "only crew"), | |
| 207 | binding(["m"], show === "mine" ? "everyone's" : "only mine"), | |
| 208 | binding(["s"], show === "ships" ? "everyone's" : "only ships"), | |
| 205 | 209 | ...(only !== undefined || items[state.index] !== undefined ? [binding(["a"], only === undefined ? "only this app" : "every app")] : []), |
| 206 | 210 | binding(["esc", "q"], "back"), |
| 207 | 211 | ]; |
| @@ -267,12 +271,13 @@ export function feedScreen(f: Session, ctx: Ctx): Screen { | ||
| 267 | 271 | else if (e.key === "h") showHistory(); |
| 268 | 272 | else if (e.key === "p") permalink(); |
| 269 | 273 | else if (e.key === "o") openLog(); |
| 270 | else if (e.key === "t" || e.key === "m") { | |
| 274 | else if (e.key === "t" || e.key === "c" || e.key === "m" || e.key === "s") { | |
| 271 | 275 | only = undefined; |
| 272 | if (e.key === "m") mine = !mine; | |
| 276 | const pick = e.key === "c" ? "crew" : e.key === "m" ? "mine" : e.key === "s" ? "ships" : undefined; | |
| 277 | if (pick !== undefined) show = show === pick ? undefined : pick; | |
| 273 | 278 | else { |
| 274 | timeline = mine ? false : !timeline; | |
| 275 | mine = false; | |
| 279 | timeline = show !== undefined ? false : !timeline; | |
| 280 | show = undefined; | |
| 276 | 281 | } |
| 277 | 282 | items.length = 0; |
| 278 | 283 | state.index = 0; |
| @@ -284,7 +289,7 @@ export function feedScreen(f: Session, ctx: Ctx): Screen { | ||
| 284 | 289 | if (only === undefined && found?.kind !== "app") return true; |
| 285 | 290 | only = found?.kind === "app" ? { repoId: found.repo.id, app: found.app } : undefined; |
| 286 | 291 | timeline = false; |
| 287 | mine = false; | |
| 292 | show = undefined; | |
| 288 | 293 | items.length = 0; |
| 289 | 294 | state.index = 0; |
| 290 | 295 | state.offset = 0; |
src/web/studio/feed.ts +16 −10
| @@ -19,7 +19,7 @@ import { placementsOf, type Placement } from "../../core/placements.ts"; | ||
| 19 | 19 | import { recentThoughts, type Thought } from "../../core/thoughts.ts"; |
| 20 | 20 | import { appFilterOf, APP_UNKNOWN_LINE, type AppFilter } from "../../feed/app_filter.ts"; |
| 21 | 21 | import { parseCursor, readFeedPage } from "../../feed/feed.ts"; |
| 22 | import { parseShow, type Show } from "../../feed/mine.ts"; | |
| 22 | import { parseShow, SHOW_VALUES, type Show } from "../../feed/mine.ts"; | |
| 23 | 23 | import { parseBefore, readTimeline, TIMELINE_START } from "../../feed/timeline.ts"; |
| 24 | 24 | import type { FeedItem } from "../../feed/rank.ts"; |
| 25 | 25 | import { permalinkOf, replyPath, replyRepo, threadOf } from "../../feed/reply.ts"; |
| @@ -373,15 +373,21 @@ function chipsBar(user: User, ctx: Ctx, items: readonly FeedItem[]): Html { | ||
| 373 | 373 | </div>`; |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | const SHOW_LABEL: Record<Show, string> = { crew: "Crew", mine: "Mine", ships: "Ships" }; | |
| 377 | ||
| 376 | 378 | /** |
| 377 | * Mine: a plain link that toggles `?show=mine`; the page says which is on | |
| 378 | * (`aria-current`, "Mine ✓"); the chip is the one signal. No script. | |
| 379 | * Crew, Mine, Ships: three plain links, each `?show=<it>`; the one on says `aria-current` and | |
| 380 | * takes the outlined button, and links to the bare feed, so a second tap clears it. The text is | |
| 381 | * the same on or off and ghost and outline buttons share one border box, so no chip changes width | |
| 382 | * and nothing moves. A `<nav>`, so a screen reader announces the group. No script. | |
| 379 | 383 | */ |
outdated
Both doors: add the same three filters to src/tui/. Also, |
||
| 380 | function mineChip(show: Show | undefined): Html { | |
| 381 | const on = show === "mine"; | |
| 382 | return html`<p class="bar small" data-show="${on ? "mine" : "all"}"> | |
| 383 | <a class="btn" data-variant="ghost" data-size="sm" href="${on ? "/feed" : "/feed?show=mine"}" ${on ? html`aria-current="true"` : html``}>${on ? "Mine ✓" : "Mine"}</a> | |
| 384 | </p>`; | |
| 384 | function showChips(show: Show | undefined): Html { | |
| 385 | return html`<nav class="bar small" data-show="${show ?? "all"}" aria-label="Narrow the feed"> | |
| 386 | ${SHOW_VALUES.map((v) => { | |
| 387 | const on = show === v; | |
outdated
Principle 3/6 and layout: the tick text changes this chip's width and shifts the others. Keep the width fixed. |
||
| 388 | return html`<a class="btn" data-variant="${on ? "outline" : "ghost"}" data-size="sm" data-show-chip="${v}" href="${on ? "/feed" : `/feed?show=${v}`}" ${on ? html`aria-current="true"` : html``}>${SHOW_LABEL[v]}</a>`; | |
| 389 | })} | |
| 390 | </nav>`; | |
| 385 | 391 | } |
| 386 | 392 | |
| 387 | 393 | /** |
| @@ -427,7 +433,7 @@ function readRegion(user: User, ctx: Ctx) { | ||
| 427 | 433 | : { |
| 428 | 434 | ...readTimeline(ctx.app.db, user, { |
| 429 | 435 | limit: FEED_FIRST_PAGE, |
| 430 | mine: show === "mine", | |
| 436 | ...(show === undefined ? {} : { show }), | |
| 431 | 437 | phase: (name, ms) => notePhase(ctx.request, name, ms), |
| 432 | 438 | ...(before.id === undefined ? {} : { before: before.id }), |
| 433 | 439 | }), |
| @@ -524,7 +530,7 @@ function drawRegion(user: User, ctx: Ctx, read: ReturnType<typeof readRegion>): | ||
| 524 | 530 | data-live-src="/live/feed${liveQuery === "" ? "" : `?${liveQuery}`}" |
| 525 | 531 | > |
| 526 | 532 | ${filterLine(filter)} |
| 527 | ${filter.kind === "app" ? null : mineChip(show)} | |
| 533 | ${filter.kind === "app" ? null : showChips(show)} | |
| 528 | 534 | ${chipsBar(user, ctx, items)} |
| 529 | 535 | ${thoughts.map((t) => thoughtCard(t, user.username, placed.get(t.id)))} |
| 530 | 536 | ${items.length === 0 && thoughts.length === 0 |
test/feed-filters.test.ts added +166
| @@ -0,0 +1,166 @@ | ||
| 1 | /** | |
Missing: tests for app.serving and release.* under Ships, and a human-actor exclusion under Crew. Both would fail if the regex or the agent check were wrong. |
||
| 2 | * `?show=crew|mine|ships` narrows the timeline on the server, marks the one on, and a second tap | |
| 3 | * (a link to the bare feed) clears it; an unknown value is the unfiltered feed. | |
| 4 | */ | |
| 5 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 6 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 7 | import { tmpdir } from "node:os"; | |
| 8 | import { join } from "node:path"; | |
| 9 | import { createApp, type App } from "../src/app.ts"; | |
| 10 | import { createRepo } from "../src/actions/repos.ts"; | |
| 11 | import { createIssue } from "../src/core/issues.ts"; | |
| 12 | import { createSession } from "../src/core/sessions.ts"; | |
| 13 | import type { Repo } from "../src/core/repos.ts"; | |
| 14 | import { createUser, type User } from "../src/core/users.ts"; | |
| 15 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 16 | import { parseShow, SHIPS as SHIPS_KINDS } from "../src/feed/mine.ts"; | |
| 17 | import { readTimeline } from "../src/feed/timeline.ts"; | |
| 18 | import { feedScreen } from "../src/tui/screens/feed.ts"; | |
| 19 | import { Screen as Surface } from "../src/tui/term/screen.ts"; | |
| 20 | import { theme } from "../src/tui/ui/theme.ts"; | |
| 21 | import type { Ctx } from "../src/tui/app/app.ts"; | |
| 22 | import type { Session } from "../src/tui/session.ts"; | |
| 23 | import { promote } from "./helpers/members.ts"; | |
| 24 | import type { KeyEvent } from "../src/tui/term/input.ts"; | |
| 25 | const pressed = (key: string): KeyEvent => ({ type: "key", key, ctrl: false, alt: false, shift: false }); | |
| 26 | ||
| 27 | describe("the feed's three one-tap filters", () => { | |
| 28 | let dataDir: string; | |
| 29 | let app: App; | |
| 30 | let servers: Servers; | |
| 31 | let alice: User; | |
| 32 | let bob: User; | |
| 33 | let repo: Repo; | |
| 34 | let cookie: string; | |
| 35 | const links = (show?: "crew" | "mine" | "ships") => | |
| 36 | readTimeline(app.db, alice, { limit: 50, ...(show === undefined ? {} : { show }) }).items.map((i) => i.link); | |
| 37 | const get = async (q: string) => (await fetch(`${servers.url}/feed${q}`, { headers: { cookie } })).text(); | |
| 38 | ||
| 39 | beforeAll(async () => { | |
| 40 | dataDir = await mkdtemp(join(tmpdir(), "forge-feed-filters-")); | |
| 41 | app = createApp({ dataDir, port: 0 }); | |
| 42 | servers = await serve(app); | |
| 43 | const mk = async (username: string, first = false) => { | |
| 44 | const r = await createUser(app.db, { | |
| 45 | origin: "seed", trusted: true, username, allowReserved: true, | |
| 46 | email: `${username}@forge.local`, password: "a-good-passphrase", adminIfFirst: first, | |
| 47 | }); | |
| 48 | if (!r.ok) throw new Error(r.error); | |
| 49 | promote(app.db, r.value); | |
| 50 | return r.value; | |
| 51 | }; | |
| 52 | await mk("root", true); | |
| 53 | alice = await mk("alice"); | |
| 54 | bob = await mk("bob"); | |
| 55 | cookie = `forge_session=${createSession(app.db, alice.id).token}`; | |
| 56 | app.db.run("INSERT INTO user (id, username, email, password_hash, is_agent) VALUES ('agent-scout', 'scout', '[email protected]', '', 1)"); | |
| 57 | const r = await createRepo(app, bob, { name: "theirs", visibility: "public" }); | |
| 58 | if (!r.ok) throw new Error("repo"); | |
| 59 | repo = r.value; | |
| 60 | const mkIssue = (author: User, title: string) => { | |
| 61 | const i = createIssue(app.db, { repoId: repo.id, authorId: author.id, title }); | |
| 62 | if (!i.ok) throw new Error(i.error); | |
| 63 | app.bus.append({ kind: "issue.opened", repoId: repo.id, actorId: author.id, payload: { number: i.value.number } }); | |
| 64 | return i.value.number; | |
| 65 | }; | |
| 66 | mkIssue(alice, "alice asks"); | |
| 67 | mkIssue(bob, "bob asks"); | |
| 68 | app.bus.append({ kind: "pull.opened", repoId: repo.id, actorId: "agent-scout", payload: { number: 21 } }); | |
| 69 | app.bus.append({ kind: "pull.merged", repoId: repo.id, actorId: bob.id, payload: { number: 22 } }); | |
| 70 | app.bus.append({ kind: "app.serving", repoId: repo.id, payload: { commitOid: "a".repeat(40) } }); | |
| 71 | app.bus.append({ kind: "release.verified_live", repoId: repo.id, payload: {} }); | |
| 72 | // An agent's comment is crew; a person's is not. | |
| 73 | app.bus.append({ kind: "issue.commented", repoId: repo.id, actorId: "agent-scout", payload: { number: 1 } }); | |
| 74 | }, 30_000); | |
| 75 | ||
| 76 | afterAll(async () => { | |
| 77 | servers.stop(); | |
| 78 | app.close(); | |
| 79 | await rm(dataDir, { recursive: true, force: true }); | |
| 80 | }); | |
| 81 | ||
| 82 | test("crew: only what agents did, never a person's post", () => { | |
| 83 | const only = links("crew"); | |
| 84 | expect(only).toContain("/bob/theirs/pulls/21"); | |
| 85 | expect(only).toContain("/bob/theirs/issues/1"); // the agent's comment | |
| 86 | for (const human of ["/bob/theirs/pulls/22", "/bob/theirs/issues/2"]) expect(only).not.toContain(human); | |
| 87 | expect(only.some((l) => l.includes("/commit/"))).toBe(false); // an app.serving has no actor | |
| 88 | expect(only.length).toBeLessThan(links().length); | |
| 89 | }); | |
| 90 | ||
| 91 | test("mine: my posts and replies to them; not another person's, not the crew's elsewhere", () => { | |
| 92 | const only = links("mine"); | |
| 93 | expect(only).toContain("/bob/theirs/issues/1"); // alice's own post (and the agent's reply to it) | |
| 94 | expect(only).not.toContain("/bob/theirs/issues/2"); // bob's | |
| 95 | expect(only).not.toContain("/bob/theirs/pulls/22"); | |
| 96 | expect(only).not.toContain("/bob/theirs/pulls/21"); | |
| 97 | expect(links()).toContain("/bob/theirs/issues/2"); // the filter is what removed it | |
| 98 | }); | |
| 99 | ||
| 100 | test("ships: a merged pull, an app serving and a release step; nothing else", () => { | |
| 101 | const only = links("ships"); | |
| 102 | expect(only).toContain("/bob/theirs/pulls/22"); | |
| 103 | expect(only).toContain("/bob/theirs"); // the app serving: no release note, so the repository's page | |
| 104 | expect(only).not.toContain("/bob/theirs/pulls/21"); | |
| 105 | expect(only.some((l) => l.includes("/issues/"))).toBe(false); | |
| 106 | for (const k of ["app.serving", "release.verified_live"]) expect(SHIPS_KINDS.test(k)).toBe(true); | |
| 107 | for (const k of ["app.gated", "pull.opened", "releases.x", "xrelease.held"]) expect(SHIPS_KINDS.test(k)).toBe(false); | |
| 108 | }); | |
| 109 | ||
| 110 | test("the terminal's c, m and s keys read the same filters; a second press clears", () => { | |
| 111 | const ctx = { theme: theme("dark"), invalidate() {}, toast() {}, push() {}, pop() {}, copy() {}, hit() {}, setCursor() {} } as unknown as Ctx; | |
| 112 | const screen = feedScreen({ app, db: app.db, user: alice } as unknown as Session, ctx); | |
| 113 | const text = () => { | |
| 114 | const s = new Surface(140, 44); | |
| 115 | screen.render({ x: 0, y: 0, w: 140, h: 44 }, s); | |
| 116 | return s.toText(); | |
| 117 | }; | |
| 118 | const press = (key: string) => screen.key!(pressed(key)); | |
| 119 | const helps = () => screen.keys.map((k) => k.help); | |
| 120 | expect(helps()).toEqual(expect.arrayContaining(["only crew", "only mine", "only ships"])); | |
| 121 | press("s"); | |
| 122 | expect(text()).toContain("merged"); | |
| 123 | expect(text()).not.toContain("bob asks"); | |
| 124 | expect(helps()).toContain("everyone's"); | |
| 125 | press("s"); | |
| 126 | expect(text()).toContain("bob asks"); | |
| 127 | press("c"); | |
| 128 | expect(text()).not.toContain("bob asks"); | |
| 129 | expect(text()).toContain("scout replied"); | |
| 130 | expect(text()).not.toContain("alice opened"); | |
| 131 | press("c"); | |
| 132 | press("m"); | |
| 133 | expect(text()).toContain("alice asks"); | |
| 134 | expect(text()).not.toContain("bob asks"); | |
| 135 | }); | |
| 136 | ||
| 137 | test("a guest reads nothing through the terminal's filters", () => { | |
| 138 | const ctx = { theme: theme("dark"), invalidate() {}, toast() {}, push() {}, pop() {}, copy() {}, hit() {}, setCursor() {} } as unknown as Ctx; | |
| 139 | const screen = feedScreen({ app, db: app.db, user: undefined } as unknown as Session, ctx); | |
| 140 | for (const k of ["c", "m", "s"]) expect(() => screen.key!(pressed(k))).not.toThrow(); | |
| 141 | }); | |
| 142 | ||
| 143 | test("the page narrows, marks the one on, and a second tap clears it", async () => { | |
| 144 | for (const v of ["crew", "mine", "ships"] as const) { | |
| 145 | const on = await get(`?show=${v}`); | |
| 146 | expect(on).toContain(`data-show="${v}"`); | |
| 147 | expect(on).toMatch(new RegExp(`data-show-chip="${v}" href="/feed" aria-current="true"`)); | |
| 148 | for (const other of ["crew", "mine", "ships"].filter((o) => o !== v)) | |
| 149 | expect(on).toContain(`data-show-chip="${other}" href="/feed?show=${other}"`); | |
| 150 | } | |
| 151 | const ships = await get("?show=ships"); | |
| 152 | expect(ships).toContain("/bob/theirs/pulls/22"); | |
| 153 | expect(ships).not.toContain("alice asks"); | |
| 154 | expect(ships).toContain("<nav "); | |
| 155 | }); | |
| 156 | ||
| 157 | test("an unknown value is the unfiltered feed, not an error", async () => { | |
| 158 | expect(parseShow("bogus")).toBeUndefined(); | |
| 159 | const res = await fetch(`${servers.url}/feed?show=bogus`, { headers: { cookie } }); | |
| 160 | expect(res.status).toBe(200); | |
| 161 | const text = await res.text(); | |
| 162 | expect(text).toContain('data-show="all"'); | |
| 163 | expect(text).toContain("alice asks"); | |
| 164 | expect(text).toContain("bob asks"); | |
| 165 | }); | |
| 166 | }); |
test/feed-mine.test.ts +1 −1
| @@ -30,7 +30,7 @@ describe("the Mine filter", () => { | ||
| 30 | 30 | let secret: Repo; |
| 31 | 31 | let aliceCookie: string; |
| 32 | 32 | const links = (viewer: User, mine: boolean) => |
| 33 | readTimeline(app.db, viewer, { mine, limit: 50 }).items.map((i) => i.link); | |
| 33 | readTimeline(app.db, viewer, { limit: 50, ...(mine ? { show: "mine" as const } : {}) }).items.map((i) => i.link); | |
| 34 | 34 | |
| 35 | 35 | const issue = (repo: Repo, author: User, title: string) => { |
| 36 | 36 | const r = createIssue(app.db, { repoId: repo.id, authorId: author.id, title }); |
new above
offline
Two options for one idea. Remove
mineand move its callers toshow.