Skip to content

Commit e774eac

Browse files
author
Eric Olkowski
committed
Added tests
1 parent f221c28 commit e774eac

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

packages/react-core/src/components/Truncate/__tests__/Truncate.test.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@ global.ResizeObserver = jest.fn().mockImplementation(() => ({
1919
disconnect: jest.fn()
2020
}));
2121

22+
test('Renders with span wrapper by default', () => {
23+
render(<Truncate content={''} data-testid="test-id" />);
24+
25+
expect(screen.getByTestId('test-id').tagName).toBe('SPAN');
26+
});
27+
28+
test('Renders with anchor wrapper when href prop is passed', () => {
29+
render(<Truncate content={'Link content'} href="#" />);
30+
31+
expect(screen.getByRole('link')).toHaveTextContent('Link content');
32+
});
33+
34+
test('Passes href to anchor when href prop is passed', () => {
35+
render(<Truncate content={'Link content'} href="#home" />);
36+
37+
expect(screen.getByRole('link')).toHaveAttribute('href', '#home');
38+
});
39+
2240
test(`renders with class ${styles.truncate}`, () => {
2341
render(<Truncate content={''} aria-label="test-id" />);
2442

@@ -145,6 +163,12 @@ test('renders tooltip content', () => {
145163
expect(input).toBeVisible();
146164
});
147165

166+
test('Renders with additional tooltip props spread', () => {
167+
render(<Truncate content={''} tooltipProps={{ distance: 32 }} />);
168+
169+
expect(screen.getByTestId('Tooltip-mock')).toHaveAttribute('distance', '32');
170+
});
171+
148172
test('renders with inherited element props spread to the component', () => {
149173
render(<Truncate content={'Test'} data-testid="test-id" aria-label="labelling-id" />);
150174

packages/react-core/src/components/Truncate/examples/Truncate.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ cssPrefix: pf-v6-c-truncate
55
propComponents: [Truncate]
66
---
77

8-
import { useRef } from 'react';
98
import './TruncateExamples.css';
109

1110
## Examples
@@ -56,6 +55,8 @@ Truncating based on a maximum amount of characters will truncate the content at
5655

5756
### With links
5857

58+
To truncate link text, you can pass the `href` property in.
59+
5960
```ts file="./TruncateLinks.tsx"
6061

6162
```

packages/react-core/src/components/Truncate/examples/TruncateLinks.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
1-
import { useRef } from 'react';
2-
import { Truncate, Button } from '@patternfly/react-core';
1+
import { Truncate } from '@patternfly/react-core';
32

43
export const TruncateLinks: React.FunctionComponent = () => {
5-
const anchorRef = useRef(null);
6-
const btnRef = useRef(null);
74
const content = 'A very lengthy anchor text content to trigger truncation';
85
return (
96
<>
107
<div>With default width-observing truncation:</div>
118
<div className="truncate-example-resize">
12-
<a ref={anchorRef} href="#">
13-
<Truncate tooltipProps={{ triggerRef: anchorRef }} content={content} />
14-
</a>
15-
<Button variant="control" ref={btnRef}>
16-
<Truncate tooltipProps={{ triggerRef: btnRef }} content={content} />
17-
</Button>
9+
<Truncate href="#" content={content} />
1810
<Truncate position="start" href="#" content={content} />
1911
<Truncate position="middle" href="#" content={content} />
2012
</div>

0 commit comments

Comments
 (0)