Skip to content

Commit

Permalink
Fix Copyable tooltip spec (#2519)
Browse files Browse the repository at this point in the history
* Fix Copyable tooltip spec

* Update test
  • Loading branch information
stephl3 authored Oct 25, 2024
1 parent f5177a4 commit 22b35d3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
20 changes: 6 additions & 14 deletions packages/copyable/src/Copyable/Copyable.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import React from 'react';
import {
act,
fireEvent,
render,
waitFor,
waitForElementToBeRemoved,
} from '@testing-library/react';
import { act, fireEvent, render, waitFor } from '@testing-library/react';
import ClipboardJS from 'clipboard';
import { axe } from 'jest-axe';

Expand Down Expand Up @@ -113,14 +107,12 @@ describe('packages/copyable', () => {
},
);

await waitFor(() => expect(getByText('Copied!')).toBeVisible());
const tooltip = getByText('Copied!');

// Tooltip should remain visible for a while
await new Promise(resolve => setTimeout(resolve, 1000));
expect(getByText('Copied!')).toBeVisible();

// Tooltip should eventually disappear
await waitForElementToBeRemoved(() => queryByText('Copied!'));
await waitFor(() => expect(tooltip).toBeVisible());
await waitFor(() => expect(tooltip).not.toBeVisible(), {
timeout: 2000,
});
},
);
});
Expand Down
3 changes: 2 additions & 1 deletion packages/copyable/src/Copyable/Copyable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
useUpdatedBaseFontSize,
} from '@leafygreen-ui/typography';

import { TOOLTIP_VISIBLE_DURATION } from './constants';
import {
buttonContainerStyle,
buttonStyle,
Expand Down Expand Up @@ -101,7 +102,7 @@ export default function Copyable({
if (copied) {
const timeoutId = setTimeout(() => {
setCopied(false);
}, 1500);
}, TOOLTIP_VISIBLE_DURATION);

return () => clearTimeout(timeoutId);
}
Expand Down
1 change: 1 addition & 0 deletions packages/copyable/src/Copyable/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const TOOLTIP_VISIBLE_DURATION = 1500;

0 comments on commit 22b35d3

Please sign in to comment.