Skip to content

Commit 0a4df06

Browse files
authored
Merge pull request #2348 from dxc-technology/PelayoFelgueroso/testing-coverage
Improve testing coverage
2 parents 8407d58 + 70d7660 commit 0a4df06

File tree

9 files changed

+288
-41
lines changed

9 files changed

+288
-41
lines changed

package-lock.json

Lines changed: 145 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/lib/jest.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const config: Config = {
55
coveragePathIgnorePatterns: [
66
"utils.ts",
77
"index.ts",
8+
"test/mocks",
89
".*Context\\.tsx$", // Is deprecated and will be removed in the future
910
],
1011
moduleNameMapper: {

packages/lib/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
"playwright": "^1.54.1",
9595
"storybook": "^9.1.10",
9696
"storybook-addon-pseudo-states": "^9.1.10",
97+
"ts-node": "^10.9.2",
9798
"tsup": "^8.1.0",
9899
"typescript": "^5.6.3",
99100
"vitest": "^3.2.4",
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { render } from "@testing-library/react";
2+
import DxcBleed from "./Bleed";
3+
4+
describe("Bleed component tests", () => {
5+
test("Bleed renders correctly with children", () => {
6+
const testContent = "Test content";
7+
const { getByText } = render(
8+
<DxcBleed space="1rem">
9+
<div>{testContent}</div>
10+
</DxcBleed>
11+
);
12+
expect(getByText(testContent)).toBeTruthy();
13+
});
14+
});

packages/lib/src/bleed/Bleed.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ import DxcContainer from "../container/Container";
33

44
const getNegativeValue = (value?: string) => (value ? `calc(${value} * -1)` : null);
55

6-
export default function DxcBleed({ space, horizontal, vertical, top, right, bottom, left, children }: BleedPropsType) {
7-
return (
8-
<DxcContainer
9-
margin={{
10-
top: getNegativeValue(top) ?? getNegativeValue(vertical) ?? getNegativeValue(space) ?? "0rem",
11-
right: getNegativeValue(right) ?? getNegativeValue(horizontal) ?? getNegativeValue(space) ?? "0rem",
12-
bottom: getNegativeValue(bottom) ?? getNegativeValue(vertical) ?? getNegativeValue(space) ?? "0rem",
13-
left: getNegativeValue(left) ?? getNegativeValue(horizontal) ?? getNegativeValue(space) ?? "0rem",
14-
}}
15-
>
16-
{children}
17-
</DxcContainer>
18-
);
19-
}
6+
const DxcBleed = ({ space, horizontal, vertical, top, right, bottom, left, children }: BleedPropsType) => (
7+
<DxcContainer
8+
margin={{
9+
top: getNegativeValue(top) ?? getNegativeValue(vertical) ?? getNegativeValue(space) ?? "0rem",
10+
right: getNegativeValue(right) ?? getNegativeValue(horizontal) ?? getNegativeValue(space) ?? "0rem",
11+
bottom: getNegativeValue(bottom) ?? getNegativeValue(vertical) ?? getNegativeValue(space) ?? "0rem",
12+
left: getNegativeValue(left) ?? getNegativeValue(horizontal) ?? getNegativeValue(space) ?? "0rem",
13+
}}
14+
>
15+
{children}
16+
</DxcContainer>
17+
);
18+
19+
export default DxcBleed;

packages/lib/src/breadcrumbs/Breadcrumbs.test.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,41 @@ describe("Breadcrumbs component tests", () => {
9393
userEvent.click(getByText("Preferences"));
9494
expect(onItemClick).toHaveBeenCalledWith("/");
9595
});
96+
test("handleOnClick prevents default and calls onClick when href is provided", () => {
97+
const onItemClick = jest.fn();
98+
const { getByText } = render(
99+
<DxcBreadcrumbs
100+
onItemClick={onItemClick}
101+
items={[
102+
{ label: "Home", href: "/home" },
103+
{ label: "Current Page", href: "" },
104+
]}
105+
/>
106+
);
107+
const homeLink = getByText("Home");
108+
userEvent.click(homeLink);
109+
expect(onItemClick).toHaveBeenCalledWith("/home");
110+
});
111+
test("handleOnMouseEnter sets title when text overflows", () => {
112+
const { getByText } = render(
113+
<DxcBreadcrumbs
114+
items={[
115+
{ label: "Home", href: "/home" },
116+
{ label: "Very Long Current Page Label That Should Overflow", href: "" },
117+
]}
118+
/>
119+
);
120+
121+
const currentPageElement = getByText("Very Long Current Page Label That Should Overflow");
122+
123+
// Mock element dimensions to simulate overflow
124+
Object.defineProperty(currentPageElement, "scrollWidth", { value: 200, configurable: true });
125+
Object.defineProperty(currentPageElement, "clientWidth", { value: 100, configurable: true });
126+
127+
// Simulate mouse enter
128+
userEvent.hover(currentPageElement);
129+
130+
// Check if title is set when there's overflow
131+
expect(currentPageElement.title).toBe("Very Long Current Page Label That Should Overflow");
132+
});
96133
});

packages/lib/src/footer/Footer.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ReactNode, useContext, useEffect, useMemo, useRef, useState } from "react";
1+
import { useContext, useEffect, useMemo, useRef, useState } from "react";
22
import styled from "@emotion/styled";
33
import DxcIcon from "../icon/Icon";
44
import { Tooltip } from "../tooltip/Tooltip";
@@ -288,9 +288,4 @@ const DxcFooter = ({
288288
);
289289
};
290290

291-
const LeftContent = ({ children }: { children: ReactNode }) => <>{children}</>;
292-
const RightContent = ({ children }: { children: ReactNode }) => <>{children}</>;
293-
294-
DxcFooter.LeftContent = LeftContent;
295-
DxcFooter.RightContent = RightContent;
296291
export default DxcFooter;

0 commit comments

Comments
 (0)