diff --git a/src/Repo.svelte b/src/Repo.svelte index 4291c05..03759bc 100644 --- a/src/Repo.svelte +++ b/src/Repo.svelte @@ -6,6 +6,7 @@ export let name: string; export let url: string; export let isFork: boolean; + export let homepage: string | undefined = undefined; export let description: string | undefined = undefined; export let sourceUrl: string | undefined = undefined; export let sourceName: string | undefined = undefined; @@ -56,6 +57,12 @@   {forks} {/if} + + {#if homepage} +
+ {homepage} +
+ {/if} @@ -88,6 +95,10 @@ } } + .homepage { + color: var(--svc-text-link, #0366d6); + } + .small { font-size: 0.85em; } diff --git a/src/util/repo.ts b/src/util/repo.ts index b4c9484..63c6e62 100644 --- a/src/util/repo.ts +++ b/src/util/repo.ts @@ -4,6 +4,7 @@ import getColors from "./colors"; export interface RawRepo { name: string; html_url: string; + homepage: string; description?: string; language?: string; fork: boolean; @@ -19,6 +20,7 @@ export interface Repo { name: string; url: string; isFork: boolean; + homepage?: string; description?: string; sourceUrl?: string; sourceName?: string; @@ -39,6 +41,7 @@ async function transform(repo: RawRepo): Promise { forks: repo.forks, }; + if (repo.homepage) out.homepage = repo.homepage; if (repo.description != null) out.description = repo.description; if (repo.source != null) { out.sourceName = repo.source.full_name; diff --git a/test/RepoCard.test.ts b/test/RepoCard.test.ts index 5b83d24..a6f78b7 100644 --- a/test/RepoCard.test.ts +++ b/test/RepoCard.test.ts @@ -83,6 +83,16 @@ it("renders the card correctly", async () => { } else { expect(queryByTestId("forks")).not.toBeInTheDocument(); } + + if (repo.homepage) { + expect(getByTestId("homepage")).toBeInTheDocument(); + const hl = getByTestId("homepage-link"); + expect(hl).toBeInTheDocument(); + expect(hl.getAttribute("href")).toEqual(repo.homepage); + expect(hl.textContent).toEqual(repo.homepage); + } else { + expect(queryByTestId("homepage")).not.toBeInTheDocument(); + } }) ); }); diff --git a/test/helper/repo.ts b/test/helper/repo.ts index 08edcdf..18e121f 100644 --- a/test/helper/repo.ts +++ b/test/helper/repo.ts @@ -4,6 +4,7 @@ import fc from "fast-check"; export function buildRaw( name: string, html_url: string, + homepage: string, desc: string | null, lang: string | null, fork: boolean, @@ -11,7 +12,14 @@ export function buildRaw( stargazers_count: number, forks: number ): RawRepo { - let raw: RawRepo = { name, html_url, fork, stargazers_count, forks }; + let raw: RawRepo = { + name, + html_url, + homepage, + fork, + stargazers_count, + forks, + }; if (desc != null) raw.description = desc; if (lang != null) raw.language = lang; if (src != null) raw.source = src; @@ -22,6 +30,7 @@ export function buildRaw( export function buildRepo( name: string, url: string, + homepage: string | null, desc: string | null, lang: string | null, isFork: boolean, @@ -30,6 +39,7 @@ export function buildRepo( forks: number ): Repo { let repo: Repo = { name, url, isFork, stars, forks }; + if (homepage != null) repo.homepage = homepage; if (desc != null) repo.description = desc; if (lang != null) { repo.language = lang; @@ -48,6 +58,7 @@ function _randRepoOwn(): fc.Arbitrary { { name: fc.string(), url: fc.webUrl(), + homepage: fc.webUrl(), description: fc.string(), language: fc.string(), isFork: fc.constant(false), @@ -63,6 +74,7 @@ function _randRepoFork(): fc.Arbitrary { { name: fc.string(), url: fc.webUrl(), + homepage: fc.webUrl(), description: fc.string(), language: fc.string(), isFork: fc.constant(true), diff --git a/test/util/repo.test.ts b/test/util/repo.test.ts index edfe1fe..f126138 100644 --- a/test/util/repo.test.ts +++ b/test/util/repo.test.ts @@ -26,6 +26,7 @@ describe("getRepo()", () => { fc.asyncProperty( fc.string(), // name fc.string(), // html_url + fc.option(fc.webUrl()), // homepage fc.option(fc.string()), // description? fc.option(fc.string()), // language? fc.boolean(), // fork @@ -38,9 +39,10 @@ describe("getRepo()", () => { ), fc.integer(), // stargazers_count fc.integer(), // forks - async (name, url, desc, lang, fork, src, sg, forks) => { - const raw = buildRaw(name, url, desc, lang, fork, src, sg, forks); - const repo = buildRepo(name, url, desc, lang, fork, src, sg, forks); + async (name, url, hp, desc, lang, frk, src, sg, frks) => { + const hpr = hp ? hp : ""; + const raw = buildRaw(name, url, hpr, desc, lang, frk, src, sg, frks); + const repo = buildRepo(name, url, hp, desc, lang, frk, src, sg, frks); if (lang != null) { fetchColors.mockResolvedValue({