Skip to content

Commit 40885d3

Browse files
committed
move badge property test to Button tests, add tests for Badge maxLength
1 parent 9ac8f1d commit 40885d3

2 files changed

Lines changed: 24 additions & 10 deletions

File tree

src/components/Badge/Badge.test.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ import { render } from "@testing-library/react";
33

44
import "@testing-library/jest-dom";
55

6-
import { IconButton } from "../../../index";
6+
import { Badge } from "../../../index";
77
import { CLASSPREFIX as eccgui } from "../../configuration/constants";
88

99
describe("Badge", () => {
10-
it("should render badge markup with correct content when used on an icon button", () => {
11-
const { container } = render(<IconButton name="item-info" badge={"badge content"} />);
12-
const badge = container.querySelector(`.${eccgui}-badge`);
10+
it("should shorten a number badge exceeding maxLength to a 9+ notation", () => {
11+
const { container } = render(<Badge maxLength={2}>{42}</Badge>);
12+
const badge = container.querySelector(`.${eccgui}-badge__tag`);
1313
expect(badge).not.toBeNull();
14-
expect(badge).toHaveTextContent("badge content");
14+
expect(badge).toHaveTextContent("9+");
1515
});
16-
it("should render badge markup with correct content when batch displays a 0 (zero) number on an icon button", () => {
17-
const { container } = render(<IconButton name="item-info" badge={0} />);
18-
const badge = container.querySelector(`.${eccgui}-badge`);
19-
expect(badge).not.toBeNull();
20-
expect(badge).toHaveTextContent("0");
16+
it("should apply maxWidth style to a string badge when maxLength is set", () => {
17+
const { container } = render(<Badge maxLength={4}>forty two</Badge>);
18+
const tag = container.querySelector(`.${eccgui}-badge__tag`);
19+
expect(tag).not.toBeNull();
20+
expect((tag as HTMLElement).style.maxWidth).toBe("calc((3em + 3ch)/2)");
2121
});
2222
});

src/components/Button/Button.test.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { render, screen } from "@testing-library/react";
33

44
import "@testing-library/jest-dom";
55

6+
import { CLASSPREFIX as eccgui } from "../../configuration/constants";
67
import Icon from "../Icon/Icon";
78

89
import Button from "./Button";
@@ -33,4 +34,17 @@ describe("Button", () => {
3334
expect(screen.getByRole("button").firstChild).toEqual(screen.getByText(/right icon/i));
3435
expect(container.getElementsByClassName("eccgui-icon").length).toBe(1);
3536
});
37+
38+
it("should render badge markup with correct content when used on an icon button", () => {
39+
const { container } = render(<Button name="item-info" badge={"badge content"} text={"Cation label"} />);
40+
const badge = container.querySelector(`.${eccgui}-badge`);
41+
expect(badge).not.toBeNull();
42+
expect(badge).toHaveTextContent("badge content");
43+
});
44+
it("should render badge markup with correct content when batch displays a 0 (zero) number on an icon button", () => {
45+
const { container } = render(<Button name="item-info" badge={0} text={"Cation label"} />);
46+
const badge = container.querySelector(`.${eccgui}-badge`);
47+
expect(badge).not.toBeNull();
48+
expect(badge).toHaveTextContent("0");
49+
});
3650
});

0 commit comments

Comments
 (0)