Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions semcore/base-components/__tests__/hint.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,61 @@ describe('Hint', () => {

expect(document.body.querySelector('[data-testid="hint"]')).not.toBeNull();
});

test('Should not show hint when children is false', async () => {
vi.useFakeTimers();
const handleChange = vi.fn();

const TestComponent = () => {
const ref = useRef<HTMLButtonElement>(null);
return (
<>
<button ref={ref} data-testid='trigger'>Hover</button>
<Hint triggerRef={ref} onVisibleChange={handleChange} timeout={[50, 50]}>
{false}
</Hint>
</>
);
};

const { getByTestId } = render(<TestComponent />);

fireEvent.mouseEnter(getByTestId('trigger'));
vi.advanceTimersByTime(60);

await waitFor(() => {
expect(handleChange).not.toHaveBeenCalled();
});

vi.useRealTimers();
});

test('Should not show hint when children is empty string', async () => {
vi.useFakeTimers();
const handleChange = vi.fn();

const emptyString = '';
const TestComponent = () => {
const ref = useRef<HTMLButtonElement>(null);
return (
<>
<button ref={ref} data-testid='trigger'>Hover</button>
<Hint triggerRef={ref} onVisibleChange={handleChange} timeout={[50, 50]}>
{emptyString}
</Hint>
</>
);
};

const { getByTestId } = render(<TestComponent />);

fireEvent.mouseEnter(getByTestId('trigger'));
vi.advanceTimersByTime(60);

await waitFor(() => {
expect(handleChange).not.toHaveBeenCalled();
});

vi.useRealTimers();
});
});
5 changes: 3 additions & 2 deletions semcore/base-components/src/components/hint/Hint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,10 @@ class HintPopperRoot extends Component<SimpleHintPopperProps, typeof enhances, H
}

componentDidMount() {
const trigger = this.asProps.triggerRef.current;
const { triggerRef, children } = this.asProps;
const trigger = triggerRef.current;

if (trigger) {
if (trigger && children) {
this.subscribe(trigger);
}
}
Expand Down
Loading