Skip to content

Commit 96cd5bb

Browse files
authored
test(react): add coverage for CSSGrid (#21827)
1 parent d89f985 commit 96cd5bb

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* Copyright IBM Corp. 2026
3+
*
4+
* This source code is licensed under the Apache-2.0 license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import { render } from '@testing-library/react';
9+
import React from 'react';
10+
import { GridSettings } from '../';
11+
import { CSSGrid } from '../CSSGrid';
12+
13+
describe('CSSGrid', () => {
14+
it('should render the non-`subgrid` path with a custom root element', () => {
15+
const { container } = render(
16+
<CSSGrid as="section" className="test" fullWidth id="css-grid">
17+
<span id="child">Test</span>
18+
</CSSGrid>
19+
);
20+
21+
expect(container.firstChild.tagName).toBe('SECTION');
22+
expect(container.firstChild).toHaveClass(
23+
'test',
24+
'cds--css-grid',
25+
'cds--css-grid--full-width',
26+
{ exact: true }
27+
);
28+
expect(container.firstChild).toHaveAttribute('id', 'css-grid');
29+
expect(container.querySelector('#child')).toBeInstanceOf(HTMLElement);
30+
});
31+
32+
it('should render the non-`subgrid` path as a `div` by default', () => {
33+
const { container } = render(<CSSGrid />);
34+
35+
expect(container.firstChild.tagName).toBe('DIV');
36+
expect(container.firstChild).toHaveClass('cds--css-grid', { exact: true });
37+
});
38+
39+
it('should render a `narrow` `subgrid` with a custom root element when `subgrid` is enabled', () => {
40+
const { container } = render(
41+
<GridSettings mode="css-grid" subgrid>
42+
<CSSGrid as="section" className="test" id="css-grid" narrow>
43+
<span id="child">Test</span>
44+
</CSSGrid>
45+
</GridSettings>
46+
);
47+
48+
expect(container.firstChild.tagName).toBe('SECTION');
49+
expect(container.firstChild).toHaveClass(
50+
'test',
51+
'cds--subgrid',
52+
'cds--subgrid--narrow',
53+
{ exact: true }
54+
);
55+
expect(container.firstChild).toHaveAttribute('id', 'css-grid');
56+
expect(container.querySelector('#child')).toBeInstanceOf(HTMLElement);
57+
});
58+
59+
it('should render a `condensed` `subgrid` as a `div` by default when `subgrid` is enabled', () => {
60+
const { container } = render(
61+
<GridSettings mode="css-grid" subgrid>
62+
<CSSGrid condensed />
63+
</GridSettings>
64+
);
65+
66+
expect(container.firstChild.tagName).toBe('DIV');
67+
expect(container.firstChild).toHaveClass(
68+
'cds--subgrid',
69+
'cds--subgrid--condensed',
70+
{ exact: true }
71+
);
72+
});
73+
});

0 commit comments

Comments
 (0)