2020-09-19 15:23:39 +08:00
|
|
|
require("@testing-library/jest-dom");
|
2021-08-28 03:05:10 +08:00
|
|
|
const { queryByTestId } = require("@testing-library/dom");
|
2020-09-19 15:23:39 +08:00
|
|
|
|
2021-08-28 03:05:10 +08:00
|
|
|
const renderWakatimeCard = require("../src/cards/wakatime-card");
|
2020-09-19 15:23:39 +08:00
|
|
|
const { wakaTimeData } = require("./fetchWakatime.test");
|
|
|
|
|
|
|
|
describe("Test Render Wakatime Card", () => {
|
|
|
|
it("should render correctly", () => {
|
2020-11-05 02:21:57 +08:00
|
|
|
const card = renderWakatimeCard(wakaTimeData.data);
|
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-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
|
|
|
|
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,
|
2020-10-04 22:47:13 +08:00
|
|
|
).toBe("本周没有编程活动");
|
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
|
|
|
|
|
|
|
it('should show "no coding activitiy this week" message when there hasn not been activity', () => {
|
|
|
|
document.body.innerHTML = renderWakatimeCard({
|
|
|
|
...wakaTimeData.data,
|
|
|
|
languages: undefined
|
|
|
|
}, {});
|
|
|
|
expect(document.querySelector(".stat").textContent).toBe("No coding activity this week")
|
|
|
|
})
|
2020-09-19 15:23:39 +08:00
|
|
|
});
|