Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup Tests and Warnings in them #1205

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
83 changes: 44 additions & 39 deletions tests/renderRepoCard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,35 @@ const data_repo = {
};

describe("Test renderRepoCard", () => {
/**
* Helper function to test colors
* @param {object} stylesObject - The CSS object
* @param {string} headerColor - The header color
* @param {string} descriptionColor - The description color
* @param {string} iconColor - The icon color
* @param {string} cardColor - The card color
* @returns {void}
*/
function expectColors(
stylesObject,
headerColor,
descriptionColor,
iconColor,
cardColor,
) {
const headerClassStyles = stylesObject[":host"][".header "];
const descClassStyles = stylesObject[":host"][".description "];
const iconClassStyles = stylesObject[":host"][".icon "];

expect(headerClassStyles.fill.trim()).toBe(headerColor);
expect(descClassStyles.fill.trim()).toBe(descriptionColor);
expect(iconClassStyles.fill.trim()).toBe(iconColor);
expect(queryByTestId(document.body, "card-bg")).toHaveAttribute(
"fill",
cardColor,
);
}

it("should render correctly", () => {
document.body.innerHTML = renderRepoCard(data_repo.repository);

Expand Down Expand Up @@ -131,17 +160,7 @@ describe("Test renderRepoCard", () => {
const styleTag = document.querySelector("style");
const stylesObject = cssToObject(styleTag.innerHTML);

const headerClassStyles = stylesObject[":host"][".header "];
const descClassStyles = stylesObject[":host"][".description "];
const iconClassStyles = stylesObject[":host"][".icon "];

expect(headerClassStyles.fill.trim()).toBe("#2f80ed");
expect(descClassStyles.fill.trim()).toBe("#434d58");
expect(iconClassStyles.fill.trim()).toBe("#586069");
expect(queryByTestId(document.body, "card-bg")).toHaveAttribute(
"fill",
"#fffefe",
);
expectColors(stylesObject, "#2f80ed", "#434d58", "#586069", "#fffefe");
});

it("should render custom colors properly", () => {
Expand All @@ -159,15 +178,11 @@ describe("Test renderRepoCard", () => {
const styleTag = document.querySelector("style");
const stylesObject = cssToObject(styleTag.innerHTML);

const headerClassStyles = stylesObject[":host"][".header "];
const descClassStyles = stylesObject[":host"][".description "];
const iconClassStyles = stylesObject[":host"][".icon "];

expect(headerClassStyles.fill.trim()).toBe(`#${customColors.title_color}`);
expect(descClassStyles.fill.trim()).toBe(`#${customColors.text_color}`);
expect(iconClassStyles.fill.trim()).toBe(`#${customColors.icon_color}`);
expect(queryByTestId(document.body, "card-bg")).toHaveAttribute(
"fill",
expectColors(
stylesObject,
`#${customColors.title_color}`,
`#${customColors.text_color}`,
`#${customColors.icon_color}`,
"#252525",
);
});
Expand Down Expand Up @@ -207,15 +222,11 @@ describe("Test renderRepoCard", () => {
const styleTag = document.querySelector("style");
const stylesObject = cssToObject(styleTag.innerHTML);

const headerClassStyles = stylesObject[":host"][".header "];
const descClassStyles = stylesObject[":host"][".description "];
const iconClassStyles = stylesObject[":host"][".icon "];

expect(headerClassStyles.fill.trim()).toBe("#5a0");
expect(descClassStyles.fill.trim()).toBe(`#${themes.radical.text_color}`);
expect(iconClassStyles.fill.trim()).toBe(`#${themes.radical.icon_color}`);
expect(queryByTestId(document.body, "card-bg")).toHaveAttribute(
"fill",
expectColors(
stylesObject,
"#5a0",
`#${themes.radical.text_color}`,
`#${themes.radical.icon_color}`,
`#${themes.radical.bg_color}`,
);
});
Expand All @@ -230,17 +241,11 @@ describe("Test renderRepoCard", () => {
const styleTag = document.querySelector("style");
const stylesObject = cssToObject(styleTag.innerHTML);

const headerClassStyles = stylesObject[":host"][".header "];
const descClassStyles = stylesObject[":host"][".description "];
const iconClassStyles = stylesObject[":host"][".icon "];

expect(headerClassStyles.fill.trim()).toBe(
expectColors(
stylesObject,
`#${themes.default.title_color}`,
);
expect(descClassStyles.fill.trim()).toBe(`#${themes.default.text_color}`);
expect(iconClassStyles.fill.trim()).toBe(`#${themes.radical.icon_color}`);
expect(queryByTestId(document.body, "card-bg")).toHaveAttribute(
"fill",
`#${themes.default.text_color}`,
`#${themes.radical.icon_color}`,
`#${themes.radical.bg_color}`,
);
});
Expand Down
83 changes: 44 additions & 39 deletions tests/renderStatsCard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,35 @@ const stats = {
};

describe("Test renderStatsCard", () => {
/**
* Helper function to test colors
* @param {object} stylesObject - The CSS object
* @param {string} headerColor - The header color
* @param {string} statColor - The stat color
* @param {string} iconColor - The icon color
* @param {string} cardColor - The card color
* @returns {void}
*/
function expectColors(
stylesObject,
headerColor,
statColor,
iconColor,
cardColor,
) {
const headerClassStyles = stylesObject[":host"][".header "];
const statClassStyles = stylesObject[":host"][".stat "];
const iconClassStyles = stylesObject[":host"][".icon "];

expect(headerClassStyles.fill.trim()).toBe(headerColor);
expect(statClassStyles.fill.trim()).toBe(statColor);
expect(iconClassStyles.fill.trim()).toBe(iconColor);
expect(queryByTestId(document.body, "card-bg")).toHaveAttribute(
"fill",
cardColor,
);
}

it("should render correctly", () => {
document.body.innerHTML = renderStatsCard(stats);

Expand Down Expand Up @@ -185,17 +214,7 @@ describe("Test renderStatsCard", () => {
const styleTag = document.querySelector("style");
const stylesObject = cssToObject(styleTag.textContent);

const headerClassStyles = stylesObject[":host"][".header "];
const statClassStyles = stylesObject[":host"][".stat "];
const iconClassStyles = stylesObject[":host"][".icon "];

expect(headerClassStyles.fill.trim()).toBe("#2f80ed");
expect(statClassStyles.fill.trim()).toBe("#434d58");
expect(iconClassStyles.fill.trim()).toBe("#4c71f2");
expect(queryByTestId(document.body, "card-bg")).toHaveAttribute(
"fill",
"#fffefe",
);
expectColors(stylesObject, "#2f80ed", "#434d58", "#4c71f2", "#fffefe");
});

it("should render custom colors properly", () => {
Expand All @@ -211,15 +230,11 @@ describe("Test renderStatsCard", () => {
const styleTag = document.querySelector("style");
const stylesObject = cssToObject(styleTag.innerHTML);

const headerClassStyles = stylesObject[":host"][".header "];
const statClassStyles = stylesObject[":host"][".stat "];
const iconClassStyles = stylesObject[":host"][".icon "];

expect(headerClassStyles.fill.trim()).toBe(`#${customColors.title_color}`);
expect(statClassStyles.fill.trim()).toBe(`#${customColors.text_color}`);
expect(iconClassStyles.fill.trim()).toBe(`#${customColors.icon_color}`);
expect(queryByTestId(document.body, "card-bg")).toHaveAttribute(
"fill",
expectColors(
stylesObject,
`#${customColors.title_color}`,
`#${customColors.text_color}`,
`#${customColors.icon_color}`,
"#252525",
);
});
Expand All @@ -233,15 +248,11 @@ describe("Test renderStatsCard", () => {
const styleTag = document.querySelector("style");
const stylesObject = cssToObject(styleTag.innerHTML);

const headerClassStyles = stylesObject[":host"][".header "];
const statClassStyles = stylesObject[":host"][".stat "];
const iconClassStyles = stylesObject[":host"][".icon "];

expect(headerClassStyles.fill.trim()).toBe("#5a0");
expect(statClassStyles.fill.trim()).toBe(`#${themes.radical.text_color}`);
expect(iconClassStyles.fill.trim()).toBe(`#${themes.radical.icon_color}`);
expect(queryByTestId(document.body, "card-bg")).toHaveAttribute(
"fill",
expectColors(
stylesObject,
"#5a0",
`#${themes.radical.text_color}`,
`#${themes.radical.icon_color}`,
`#${themes.radical.bg_color}`,
);
});
Expand Down Expand Up @@ -282,17 +293,11 @@ describe("Test renderStatsCard", () => {
const styleTag = document.querySelector("style");
const stylesObject = cssToObject(styleTag.innerHTML);

const headerClassStyles = stylesObject[":host"][".header "];
const statClassStyles = stylesObject[":host"][".stat "];
const iconClassStyles = stylesObject[":host"][".icon "];

expect(headerClassStyles.fill.trim()).toBe(
expectColors(
stylesObject,
`#${themes.default.title_color}`,
);
expect(statClassStyles.fill.trim()).toBe(`#${themes.default.text_color}`);
expect(iconClassStyles.fill.trim()).toBe(`#${themes.radical.icon_color}`);
expect(queryByTestId(document.body, "card-bg")).toHaveAttribute(
"fill",
`#${themes.default.text_color}`,
`#${themes.radical.icon_color}`,
`#${themes.radical.bg_color}`,
);
});
Expand Down
6 changes: 3 additions & 3 deletions tests/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ describe("Test utils.js", () => {
});

it("should test encodeHTML", () => {
expect(encodeHTML(`<html>hello world<,.#4^&^@%!))`)).toBe(
"&#60;html&#62;hello world&#60;,.#4^&#38;^@%!))",
expect(encodeHTML(`<html lang="">hello world<,.#4^&^@%!))`)).toBe(
'&#60;html lang=""&#62;hello world&#60;,.#4^&#38;^@%!))',
);
});

Expand All @@ -51,7 +51,7 @@ describe("Test utils.js", () => {
).toHaveTextContent(/Something went wrong/gim);
expect(
queryByTestId(document.body, "message").children[1],
).toBeEmptyDOMElement(2);
).toBeEmptyDOMElement();

// Secondary message
document.body.innerHTML = renderError(
Expand Down
Loading