Use `vitest` for backend tests: - `bench` script now uses [vitest's `bench`](https://vitest.dev/api/#bench) - e2e test fails with same error happening now with jest:`data-testid` attribute not present. vitest left, jest right <img width="1264" height="603" alt="image" src="https://github.com/user-attachments/assets/56fc43a6-e143-4208-bf14-7e016aae7fa9" />
96 lines
2.9 KiB
JavaScript
96 lines
2.9 KiB
JavaScript
import { queryByTestId } from "@testing-library/dom";
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import { renderWakatimeCard } from "../src/cards/wakatime.js";
|
|
|
|
import { wakaTimeData } from "./fetchWakatime.test.js";
|
|
|
|
import "@testing-library/jest-dom/vitest";
|
|
|
|
describe("Test Render WakaTime Card", () => {
|
|
it("should render correctly", () => {
|
|
const card = renderWakatimeCard(wakaTimeData.data);
|
|
expect(card).toMatchSnapshot();
|
|
});
|
|
|
|
it("should render correctly with compact layout", () => {
|
|
const card = renderWakatimeCard(wakaTimeData.data, { layout: "compact" });
|
|
|
|
expect(card).toMatchSnapshot();
|
|
});
|
|
|
|
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();
|
|
});
|
|
|
|
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();
|
|
});
|
|
|
|
it("should render translations", () => {
|
|
document.body.innerHTML = renderWakatimeCard({}, { locale: "cn" });
|
|
expect(document.getElementsByClassName("header")[0].textContent).toBe(
|
|
"WakaTime 周统计",
|
|
);
|
|
expect(
|
|
document.querySelector('g[transform="translate(0, 0)"]>text.stat.bold')
|
|
.textContent,
|
|
).toBe("WakaTime 用户个人资料未公开");
|
|
});
|
|
|
|
it("should render without rounding", () => {
|
|
document.body.innerHTML = renderWakatimeCard(wakaTimeData.data, {
|
|
border_radius: "0",
|
|
});
|
|
expect(document.querySelector("rect")).toHaveAttribute("rx", "0");
|
|
document.body.innerHTML = renderWakatimeCard(wakaTimeData.data, {});
|
|
expect(document.querySelector("rect")).toHaveAttribute("rx", "4.5");
|
|
});
|
|
|
|
it('should show "no coding activity this week" message when there has not been activity', () => {
|
|
document.body.innerHTML = renderWakatimeCard(
|
|
{
|
|
...wakaTimeData.data,
|
|
languages: undefined,
|
|
},
|
|
{},
|
|
);
|
|
expect(document.querySelector(".stat").textContent).toBe(
|
|
"No coding activity this week",
|
|
);
|
|
});
|
|
|
|
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",
|
|
);
|
|
});
|
|
|
|
it("should render correctly with percent display format", () => {
|
|
const card = renderWakatimeCard(wakaTimeData.data, {
|
|
display_format: "percent",
|
|
});
|
|
expect(card).toMatchSnapshot();
|
|
});
|
|
});
|