Skip to content

Commit b96c249

Browse files
committed
tests: adding new tests for the wrapperProps and cardBodyProps
1 parent 9a0f313 commit b96c249

1 file changed

Lines changed: 154 additions & 0 deletions

File tree

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
import { render, screen } from '@testing-library/react';
2+
import '@testing-library/jest-dom';
3+
import GridTile, { GridTileProps } from '../GridTile';
4+
5+
const defaultProps: GridTileProps = {
6+
widgetType: 'test-widget',
7+
isDragging: false,
8+
setIsDragging: jest.fn(),
9+
setWidgetAttribute: jest.fn(),
10+
widgetConfig: {
11+
i: 'test-widget-1',
12+
x: 0,
13+
y: 0,
14+
w: 2,
15+
h: 3,
16+
colWidth: 100,
17+
},
18+
removeWidget: jest.fn(),
19+
children: <div data-testid="widget-content">Widget Content</div>,
20+
isLoaded: true,
21+
};
22+
23+
describe('GridTile - wrapperProps and cardBodyProps', () => {
24+
describe('wrapperProps', () => {
25+
it('should pass wrapperProps to the Card wrapper component', () => {
26+
const wrapperProps = {
27+
'data-testid': 'custom-card-wrapper',
28+
'aria-label': 'Custom card label',
29+
};
30+
31+
render(
32+
<GridTile
33+
{...defaultProps}
34+
widgetConfig={{
35+
...defaultProps.widgetConfig,
36+
config: {
37+
wrapperProps,
38+
},
39+
}}
40+
/>
41+
);
42+
43+
const cardWrapper = screen.getByTestId('custom-card-wrapper');
44+
expect(cardWrapper).toBeInTheDocument();
45+
expect(cardWrapper).toHaveAttribute('aria-label', 'Custom card label');
46+
});
47+
48+
it('should merge custom className with default className in wrapperProps', () => {
49+
const wrapperProps = {
50+
className: 'custom-wrapper-class',
51+
'data-testid': 'card-with-custom-class',
52+
};
53+
54+
render(
55+
<GridTile
56+
{...defaultProps}
57+
widgetConfig={{
58+
...defaultProps.widgetConfig,
59+
config: {
60+
wrapperProps,
61+
},
62+
}}
63+
/>
64+
);
65+
66+
const cardWrapper = screen.getByTestId('card-with-custom-class');
67+
expect(cardWrapper).toHaveClass('grid-tile');
68+
expect(cardWrapper).toHaveClass('custom-wrapper-class');
69+
});
70+
});
71+
72+
describe('cardBodyProps', () => {
73+
it('should pass cardBodyProps to the CardBody component', () => {
74+
const cardBodyProps = {
75+
'data-testid': 'custom-card-body',
76+
'aria-label': 'Custom card body label',
77+
};
78+
79+
render(
80+
<GridTile
81+
{...defaultProps}
82+
widgetConfig={{
83+
...defaultProps.widgetConfig,
84+
config: {
85+
cardBodyProps,
86+
},
87+
}}
88+
/>
89+
);
90+
91+
const cardBody = screen.getByTestId('custom-card-body');
92+
expect(cardBody).toBeInTheDocument();
93+
expect(cardBody).toHaveAttribute('aria-label', 'Custom card body label');
94+
});
95+
96+
it('should merge custom className with default className in cardBodyProps', () => {
97+
const cardBodyProps = {
98+
className: 'custom-body-class',
99+
'data-testid': 'body-with-custom-class',
100+
};
101+
102+
render(
103+
<GridTile
104+
{...defaultProps}
105+
widgetConfig={{
106+
...defaultProps.widgetConfig,
107+
config: {
108+
cardBodyProps,
109+
},
110+
}}
111+
/>
112+
);
113+
114+
const cardBody = screen.getByTestId('body-with-custom-class');
115+
expect(cardBody).toHaveClass('pf-v6-u-p-0');
116+
expect(cardBody).toHaveClass('custom-body-class');
117+
});
118+
});
119+
120+
describe('both props together', () => {
121+
it('should correctly apply both wrapperProps and cardBodyProps simultaneously', () => {
122+
const wrapperProps = {
123+
className: 'custom-wrapper',
124+
'data-testid': 'combined-wrapper',
125+
};
126+
127+
const cardBodyProps = {
128+
className: 'custom-body',
129+
'data-testid': 'combined-body',
130+
};
131+
132+
render(
133+
<GridTile
134+
{...defaultProps}
135+
widgetConfig={{
136+
...defaultProps.widgetConfig,
137+
config: {
138+
wrapperProps,
139+
cardBodyProps,
140+
},
141+
}}
142+
/>
143+
);
144+
145+
const cardWrapper = screen.getByTestId('combined-wrapper');
146+
expect(cardWrapper).toHaveClass('grid-tile');
147+
expect(cardWrapper).toHaveClass('custom-wrapper');
148+
149+
const cardBody = screen.getByTestId('combined-body');
150+
expect(cardBody).toHaveClass('pf-v6-u-p-0');
151+
expect(cardBody).toHaveClass('custom-body');
152+
});
153+
});
154+
});

0 commit comments

Comments
 (0)