Skip to content

Commit

Permalink
Updated onTooltipHidden test to integration
Browse files Browse the repository at this point in the history
  • Loading branch information
thatblindgeye committed Sep 7, 2023
1 parent b84993d commit ea1243e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import { ClipboardCopyButton } from '../ClipboardCopyButton';
import buttonStyles from '@patternfly/react-styles/css/components/Button/button';

jest.mock('../../Tooltip', () => ({
Tooltip: ({ content, children, exitDelay, entryDelay, maxWidth, position, onTooltipHidden, ...props }) => (
<div data-testid="tooltip-mock" {...props}>
Tooltip: ({ content, children, exitDelay, entryDelay, maxWidth, position }) => (
<div data-testid="tooltip-mock">
<div data-testid="tooltip-mock-content">{content}</div>
<p>{`exitDelay: ${exitDelay}`}</p>
<p>{`entryDelay: ${entryDelay}`}</p>
<p>{`maxWidth: ${maxWidth}`}</p>
<p>{`position: ${position}`}</p>
<p>{`onTooltipHidden: ${onTooltipHidden}`}</p>
{children}
</div>
)
Expand Down Expand Up @@ -121,11 +120,6 @@ test('Passes position to Tooltip', () => {

expect(screen.getByText('position: bottom')).toBeVisible();
});
test('Passes onTooltipHidden to Tooltip', () => {
render(<ClipboardCopyButton onTooltipHidden={() => {}} {...requiredProps} />);

expect(screen.getByText('onTooltipHidden: () => {}')).toBeVisible();
});

test('Matches snapshot', () => {
const { asFragment } = render(<ClipboardCopyButton {...requiredProps} />);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
exports[`Matches snapshot 1`] = `
<DocumentFragment>
<div
aria="none"
aria-live="polite"
data-testid="tooltip-mock"
trigger="mouseenter focus click"
triggerref="[object Object]"
>
<div
data-testid="tooltip-mock-content"
Expand All @@ -28,18 +24,12 @@ exports[`Matches snapshot 1`] = `
<p>
position: top
</p>
<p>
onTooltipHidden: () =&gt; {
/* istanbul ignore next */
cov_274vctcufi().f[1]++;
}
</p>
<button
aria-disabled="false"
aria-label="Copyable input"
aria-labelledby="button-id text-id"
class="pf-v5-c-button pf-m-control"
data-ouia-component-id="OUIA-Generated-Button-control-14"
data-ouia-component-id="OUIA-Generated-Button-control-13"
data-ouia-component-type="PF5/Button"
data-ouia-safe="true"
id="button-id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,20 @@ describe('Clipboard Copy Demo Test', () => {
cy.get('#inline-copy').should('have.class', 'pf-m-block');
});

it('Verify clickTip renders', () => {
it('Verify hoverTip and clickTip render and onTooltipHidden called', () => {
cy.get('#tooltip-test .pf-v5-c-button.pf-m-control').focus();
// Wait for default entryDelay of 300ms
cy.wait(500);
cy.get('.pf-v5-c-tooltip').should('have.text', 'Copy button not clicked');
cy.get('#tooltip-test .pf-v5-c-button.pf-m-control').click();
cy.get('.pf-v5-c-tooltip').should('have.text', 'Copy button clicked');
cy.get('#tooltip-test input').focus();

// By default onTooltipHidden is called to set internal copied state to false, which
// would reset the tooltip content to the hoverTip prop value
cy.wait(500);
cy.get('#tooltip-test .pf-v5-c-button.pf-m-control').focus();
cy.wait(500);
cy.get('.pf-v5-c-tooltip').should('have.text', 'Copy button not clicked');
});
});

0 comments on commit ea1243e

Please sign in to comment.