Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/SantaClaas/gigit. git client
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133/** * Building graph rows for tests. * * Typed as the real `GraphRow`, so if the Rust side changes shape and the * bindings are updated, every test that builds a row stops compiling. That is * the point: a fixture that can drift silently is worse than no fixture. */
import type { Edge, GraphRow, RefBadge } from "../../src/lib/bindings";
/** A predictable, obviously-fake object id. */export function fakeId(index: number): string { return index.toString(16).padStart(4, "0").repeat(10);}
export function edge(partial: Partial<Edge> = {}): Edge { return { fromColumn: 0, toColumn: 0, lane: 0, kind: "through", ...partial };}
export function badge(partial: Partial<RefBadge> = {}): RefBadge { return { shorthand: "main", kind: "localBranch", isHead: false, ...partial };}
export function row(index: number, partial: Partial<GraphRow> = {}): GraphRow { return { id: fakeId(index), row: index, column: 0, lane: 0, dot: "normal", edges: [edge({ kind: "fromCommit" })], width: 1, summary: `Commit number ${index}`, author: "Fixture", // Fixed rather than relative to now, so a test asserting on a rendered // date does not change its answer overnight. time: 1_700_000_000 - index * 3600, refs: [], ...partial, };}
/** A straight run of commits. */export function linearHistory(count: number): GraphRow[] { return Array.from({ length: count }, (_, index) => row(index));}
/** * A history with a branch and a merge, so lanes, columns and dots all have * something to say. * * ``` * 0 ◍ merge, column 0, two parents * 1 │ ● side branch, column 1 * 2 ● main, column 0 * 3 ● shared root * ``` */export function branchedHistory(): GraphRow[] { return [ row(0, { dot: "merge", width: 2, refs: [badge({ shorthand: "main", isHead: true })], edges: [ edge({ kind: "fromCommit", fromColumn: 0, toColumn: 0, lane: 0 }), edge({ kind: "fromCommit", fromColumn: 0, toColumn: 1, lane: 1 }), ], }), row(1, { column: 1, lane: 1, width: 2, refs: [badge({ shorthand: "v1.0.0", kind: "tag" })], edges: [ edge({ kind: "through", fromColumn: 0, toColumn: 0, lane: 0 }), edge({ kind: "toCommit", fromColumn: 1, toColumn: 1, lane: 1 }), edge({ kind: "fromCommit", fromColumn: 1, toColumn: 1, lane: 1 }), ], }), row(2, { width: 2, edges: [ edge({ kind: "toCommit", fromColumn: 0, toColumn: 0, lane: 0 }), edge({ kind: "through", fromColumn: 1, toColumn: 1, lane: 1 }), edge({ kind: "fromCommit", fromColumn: 0, toColumn: 0, lane: 0 }), ], }), row(3, { dot: "root", width: 1, edges: [edge({ kind: "toCommit", fromColumn: 0, toColumn: 0, lane: 0 })], }), ];}
/** A remembered repository. */export function recent( name: string, partial: Partial<import("../../src/lib/bindings").RecentRepository> = {},): import("../../src/lib/bindings").RecentRepository { return { id: `/repositories/${name}/.git`, path: `/repositories/${name}`, name, // Fixed rather than relative to now, so an assertion on a rendered date // does not change its answer overnight. lastOpened: 1_700_000_000, exists: true, ...partial, };}
/** A reference, as `list_references` returns one. */export function reference( shorthand: string, kind: import("../../src/lib/bindings").RefKind = "localBranch",): import("../../src/lib/bindings").RefEntry { const namespace = { localBranch: "refs/heads/", remoteBranch: "refs/remotes/", tag: "refs/tags/", other: "refs/", }[kind];
return { name: `${namespace}${shorthand}`, shorthand, kind, target: "0".repeat(40), };}