refactor: added FlexLayout for flex layouts

This commit is contained in:
anuraghazra
2020-07-18 22:44:27 +05:30
parent 06f0021660
commit 253eb39b19
6 changed files with 122 additions and 42 deletions

View File

@@ -158,4 +158,32 @@ describe("Test renderRepoCard", () => {
"Archived"
);
});
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 },
});
expect(queryByTestId(document.body, "stargazers")).toBeNull();
expect(queryByTestId(document.body, "forkcount")).toBeDefined();
document.body.innerHTML = renderRepoCard({
...data_repo.repository,
stargazers: { totalCount: 1 },
forkCount: 0,
});
expect(queryByTestId(document.body, "stargazers")).toBeDefined();
expect(queryByTestId(document.body, "forkcount")).toBeNull();
document.body.innerHTML = renderRepoCard({
...data_repo.repository,
stargazers: { totalCount: 0 },
forkCount: 0,
});
expect(queryByTestId(document.body, "stargazers")).toBeNull();
expect(queryByTestId(document.body, "forkcount")).toBeNull();
});
});

View File

@@ -70,7 +70,6 @@ describe("Test renderStatsCard", () => {
document.body.innerHTML = renderStatsCard(stats);
const styleTag = document.querySelector("style");
console.log(styleTag.textContent);
const stylesObject = cssToObject(styleTag.textContent);
const headerClassStyles = stylesObject[".header"];
@@ -157,7 +156,6 @@ describe("Test renderStatsCard", () => {
it("should not have icons if show_icons is false", () => {
document.body.innerHTML = renderStatsCard(stats, { show_icons: false });
console.log(queryAllByTestId(document.body, "icon"));
expect(queryAllByTestId(document.body, "icon")[0]).not.toBeDefined();
expect(queryByTestId(document.body, "stars")).toBeDefined();
expect(

View File

@@ -1,4 +1,9 @@
const { kFormatter, encodeHTML, renderError } = require("../src/utils");
const {
kFormatter,
encodeHTML,
renderError,
FlexLayout,
} = require("../src/utils");
describe("Test utils.js", () => {
it("should test kFormatter", () => {
@@ -23,4 +28,25 @@ describe("Test utils.js", () => {
"Something went wrong"
);
});
it("should test FlexLayout", () => {
const layout = FlexLayout({
items: ["<text>1</text>", "<text>2</text>"],
gap: 60,
}).join("");
expect(layout).toBe(
`<g transform=\"translate(0, 0)\"><text>1</text></g><g transform=\"translate(60, 0)\"><text>2</text></g>`
);
const columns = FlexLayout({
items: ["<text>1</text>", "<text>2</text>"],
gap: 60,
direction: "column",
}).join("");
expect(columns).toBe(
`<g transform=\"translate(0, 0)\"><text>1</text></g><g transform=\"translate(0, 60)\"><text>2</text></g>`
);
});
});