Skip to content

Commit f77143a

Browse files
committed
fix truncate mock for snapshot, add basic integration test for tabindex
1 parent 207fc8b commit f77143a

File tree

6 files changed

+43
-3
lines changed

6 files changed

+43
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import styles from '@patternfly/react-styles/css/components/Truncate/truncate';
44
import '@testing-library/jest-dom';
55

66
jest.mock('../../Tooltip', () => ({
7-
Tooltip: ({ content, position, children, ...props }) => (
7+
Tooltip: ({ content, position, children, triggerRef, ...props }) => (
88
<div data-testid="Tooltip-mock" {...props}>
99
<div data-testid="Tooltip-mock-content-container">Test {content}</div>
1010
<p>{`position: ${position}`}</p>

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ exports[`renders default truncation 1`] = `
4141
<DocumentFragment>
4242
<div
4343
data-testid="Tooltip-mock"
44-
triggerref="[object Object]"
4544
>
4645
<div
4746
data-testid="Tooltip-mock-content-container"
@@ -69,7 +68,6 @@ exports[`renders start truncation with &lrm; at end 1`] = `
6968
<DocumentFragment>
7069
<div
7170
data-testid="Tooltip-mock"
72-
triggerref="[object Object]"
7371
>
7472
<div
7573
data-testid="Tooltip-mock-content-container"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
describe('Truncate Demo Test', () => {
2+
it('Navigate to demo section', () => {
3+
cy.visit('http://localhost:3000/truncate-demo-nav-link');
4+
});
5+
6+
it('Verify no tooltip renders by default', () => {
7+
cy.get('.pf-v6-c-tooltip').should('not.exist');
8+
});
9+
10+
it('Verify non-truncated content in wide container does not have tabindex', () => {
11+
cy.get('#no-truncate').should('not.have.attr', 'tabindex');
12+
});
13+
14+
it('Verify truncated content in small container does have tabindex', () => {
15+
cy.get('#basic-truncate').should('have.attr', 'tabindex');
16+
});
17+
18+
it('Verify tooltip renders when truncate is focused', () => {
19+
cy.get('#basic-truncate').should('have.attr', 'tabindex');
20+
cy.get('#basic-truncate').focus();
21+
cy.get('.pf-v6-c-tooltip').should('exist');
22+
});
23+
});

packages/react-integration/demo-app-ts/src/Demos.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,11 @@ export const Demos: DemoInterface[] = [
462462
name: 'Tree View Demo',
463463
componentType: Examples.TreeViewDemo
464464
},
465+
{
466+
id: 'truncate-demo',
467+
name: 'Truncate Demo',
468+
componentType: Examples.TruncateDemo
469+
},
465470
{
466471
id: 'wizard-demo',
467472
name: 'Wizard Demo',
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Truncate } from '@patternfly/react-core';
2+
3+
export const TruncateDemo: React.FunctionComponent = () => (
4+
<>
5+
<div style={{ width: '100px' }}>
6+
<Truncate id="basic-truncate" content={'basic truncated content'} />
7+
</div>
8+
<div style={{ width: '800px' }}>
9+
<Truncate id="no-truncate" content={'no truncation in wide container'} />
10+
</div>
11+
</>
12+
);
13+
TruncateDemo.displayName = 'TruncateDemo';

packages/react-integration/demo-app-ts/src/components/demos/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,6 @@ export * from './ToolbarDemo/ToolbarDemo';
8888
export * from './ToolbarDemo/ToolbarVisibilityDemo';
8989
export * from './TooltipDemo/TooltipDemo';
9090
export * from './TreeViewDemo/TreeViewDemo';
91+
export * from './TruncateDemo/TruncateDemo';
9192
export * from './WizardDemo/WizardDemo';
9293
export * from './WizardDeprecatedDemo/WizardDeprecatedDemo';

0 commit comments

Comments
 (0)