Merge pull request #9406 from nixocio/ui_issue_9323

Do not show tooltip with empty content

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
softwarefactory-project-zuul[bot] 2021-02-24 15:52:56 +00:00 committed by GitHub
commit fe605596b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 5 deletions

View File

@ -53,13 +53,21 @@ export default function StatusLabel({ status, tooltipContent = '' }) {
const color = colors[status] || 'grey';
const Icon = icons[status];
const renderLabel = () => (
<Label variant="outline" color={color} icon={Icon ? <Icon /> : null}>
{label}
</Label>
);
return (
<>
<Tooltip content={tooltipContent} position="top">
<Label variant="outline" color={color} icon={Icon ? <Icon /> : null}>
{label}
</Label>
</Tooltip>
{tooltipContent ? (
<Tooltip content={tooltipContent} position="top">
{renderLabel()}
</Tooltip>
) : (
renderLabel()
)}
</>
);
}

View File

@ -9,6 +9,7 @@ describe('StatusLabel', () => {
expect(wrapper.find('CheckCircleIcon')).toHaveLength(1);
expect(wrapper.find('Label').prop('color')).toEqual('green');
expect(wrapper.text()).toEqual('Success');
expect(wrapper.find('Tooltip')).toHaveLength(0);
});
test('should render failed', () => {
@ -58,4 +59,16 @@ describe('StatusLabel', () => {
expect(wrapper.find('Label').prop('color')).toEqual('orange');
expect(wrapper.text()).toEqual('Canceled');
});
test('should render tooltip', () => {
const wrapper = mount(
<StatusLabel tooltipContent="Foo" status="success" />
);
expect(wrapper).toHaveLength(1);
expect(wrapper.find('CheckCircleIcon')).toHaveLength(1);
expect(wrapper.find('Label').prop('color')).toEqual('green');
expect(wrapper.text()).toEqual('Success');
expect(wrapper.find('Tooltip')).toHaveLength(1);
expect(wrapper.find('Tooltip').prop('content')).toEqual('Foo');
});
});