refactor: refactor repo card (#1325)

* refactor: refactored repo-card

* test: fix tests

* test: fixed tests

* fix: unprovided description error
This commit is contained in:
Anurag Hazra
2021-09-26 21:02:27 +05:30
committed by GitHub
parent ec8eb0c893
commit 62d65ab483
7 changed files with 140 additions and 77 deletions
+15 -4
View File
@@ -9,13 +9,13 @@ const data_repo = {
repository: {
nameWithOwner: "anuraghazra/convoychat",
name: "convoychat",
stargazers: { totalCount: 38000 },
description: "Help us take over the world! React + TS + GraphQL Chat App",
primaryLanguage: {
color: "#2b7489",
id: "MDg6TGFuZ3VhZ2UyODc=",
name: "TypeScript",
},
starCount: 38000,
forkCount: 100,
},
};
@@ -231,7 +231,7 @@ describe("Test renderRepoCard", () => {
it("should not render star count or fork count if either of the are zero", () => {
document.body.innerHTML = renderRepoCard({
...data_repo.repository,
stargazers: { totalCount: 0 },
starCount: 0,
});
expect(queryByTestId(document.body, "stargazers")).toBeNull();
@@ -239,7 +239,7 @@ describe("Test renderRepoCard", () => {
document.body.innerHTML = renderRepoCard({
...data_repo.repository,
stargazers: { totalCount: 1 },
starCount: 1,
forkCount: 0,
});
@@ -248,7 +248,7 @@ describe("Test renderRepoCard", () => {
document.body.innerHTML = renderRepoCard({
...data_repo.repository,
stargazers: { totalCount: 0 },
starCount: 0,
forkCount: 0,
});
@@ -311,4 +311,15 @@ describe("Test renderRepoCard", () => {
document.body.innerHTML = renderRepoCard(data_repo.repository, {});
expect(document.querySelector("rect")).toHaveAttribute("rx", "4.5");
});
it("should fallback to default description", () => {
document.body.innerHTML = renderRepoCard({
...data_repo.repository,
description: undefined,
isArchived: true,
});
expect(document.getElementsByClassName("description")[0]).toHaveTextContent(
"No description provided",
);
});
});