2022-09-24 16:20:54 +08:00
|
|
|
import { queryByTestId } from "@testing-library/dom";
|
|
|
|
import "@testing-library/jest-dom";
|
2022-09-24 20:10:06 +08:00
|
|
|
import { renderWakatimeCard } from "../src/cards/wakatime-card.js";
|
2022-09-24 19:20:52 +08:00
|
|
|
import { getCardColors } from "../src/common/utils.js";
|
|
|
|
import { wakaTimeData } from "./fetchWakatime.test.js";
|
2023-07-03 14:54:19 +08:00
|
|
|
import { expect, it, describe } from "@jest/globals";
|
2020-09-19 15:23:39 +08:00
|
|
|
|
|
|
|
describe("Test Render Wakatime Card", () => {
|
|
|
|
it("should render correctly", () => {
|
2023-07-03 14:54:19 +08:00
|
|
|
// const card = renderWakatimeCard(wakaTimeData.data);
|
2022-09-24 16:20:54 +08:00
|
|
|
expect(getCardColors).toMatchSnapshot();
|
2020-11-05 02:21:57 +08:00
|
|
|
});
|
2020-09-19 15:23:39 +08:00
|
|
|
|
2020-11-05 02:21:57 +08:00
|
|
|
it("should render correctly with compact layout", () => {
|
|
|
|
const card = renderWakatimeCard(wakaTimeData.data, { layout: "compact" });
|
2020-09-19 15:23:39 +08:00
|
|
|
|
2020-11-05 02:21:57 +08:00
|
|
|
expect(card).toMatchSnapshot();
|
2020-09-19 15:23:39 +08:00
|
|
|
});
|
2020-10-04 16:05:15 +08:00
|
|
|
|
2022-10-29 02:47:09 +08:00
|
|
|
it("should render correctly with compact layout when langs_count is set", () => {
|
|
|
|
const card = renderWakatimeCard(wakaTimeData.data, {
|
|
|
|
layout: "compact",
|
|
|
|
langs_count: 2,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(card).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2021-08-28 03:05:10 +08:00
|
|
|
it("should hide languages when hide is passed", () => {
|
|
|
|
document.body.innerHTML = renderWakatimeCard(wakaTimeData.data, {
|
|
|
|
hide: ["YAML", "Other"],
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(queryByTestId(document.body, /YAML/i)).toBeNull();
|
|
|
|
expect(queryByTestId(document.body, /Other/i)).toBeNull();
|
|
|
|
expect(queryByTestId(document.body, /TypeScript/i)).not.toBeNull();
|
|
|
|
});
|
|
|
|
|
2020-10-04 16:05:15 +08:00
|
|
|
it("should render translations", () => {
|
|
|
|
document.body.innerHTML = renderWakatimeCard({}, { locale: "cn" });
|
|
|
|
expect(document.getElementsByClassName("header")[0].textContent).toBe(
|
2020-10-04 22:47:13 +08:00
|
|
|
"Wakatime 周统计",
|
2020-10-04 16:05:15 +08:00
|
|
|
);
|
|
|
|
expect(
|
|
|
|
document.querySelector('g[transform="translate(0, 0)"]>text.stat.bold')
|
|
|
|
.textContent,
|
2023-06-02 17:07:59 +08:00
|
|
|
).toBe("Wakatime 用户个人资料未公开");
|
2020-10-04 16:05:15 +08:00
|
|
|
});
|
2021-03-08 00:53:32 +08:00
|
|
|
|
|
|
|
it("should render without rounding", () => {
|
2021-08-28 03:05:10 +08:00
|
|
|
document.body.innerHTML = renderWakatimeCard(wakaTimeData.data, {
|
|
|
|
border_radius: "0",
|
|
|
|
});
|
2021-03-08 00:53:32 +08:00
|
|
|
expect(document.querySelector("rect")).toHaveAttribute("rx", "0");
|
2021-08-28 03:05:10 +08:00
|
|
|
document.body.innerHTML = renderWakatimeCard(wakaTimeData.data, {});
|
2021-03-08 00:53:32 +08:00
|
|
|
expect(document.querySelector("rect")).toHaveAttribute("rx", "4.5");
|
|
|
|
});
|
2021-11-05 22:19:51 +08:00
|
|
|
|
2023-04-25 02:24:41 +08:00
|
|
|
it('should show "no coding activity this week" message when there has not been activity', () => {
|
2022-09-06 15:09:45 +08:00
|
|
|
document.body.innerHTML = renderWakatimeCard(
|
|
|
|
{
|
|
|
|
...wakaTimeData.data,
|
|
|
|
languages: undefined,
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
expect(document.querySelector(".stat").textContent).toBe(
|
|
|
|
"No coding activity this week",
|
|
|
|
);
|
|
|
|
});
|
2023-05-06 15:43:37 +08:00
|
|
|
|
|
|
|
it('should show "no coding activity this week" message when using compact layout and there has not been activity', () => {
|
|
|
|
document.body.innerHTML = renderWakatimeCard(
|
|
|
|
{
|
|
|
|
...wakaTimeData.data,
|
|
|
|
languages: undefined,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
layout: "compact",
|
|
|
|
},
|
|
|
|
);
|
|
|
|
expect(document.querySelector(".stat").textContent).toBe(
|
|
|
|
"No coding activity this week",
|
|
|
|
);
|
|
|
|
});
|
2020-09-19 15:23:39 +08:00
|
|
|
});
|