Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change badge and fix select #4298

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 2 additions & 4 deletions src/web/components/badge/__tests__/badge.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/


import {describe, test, expect} from '@gsa/testing';
import ReportIcon from 'web/components/icon/reporticon';
import {render} from 'web/utils/testing';

import Badge from '../badge';


describe('Badge tests', () => {
test('should render badge', () => {
const {element} = render(
Expand Down Expand Up @@ -46,13 +44,13 @@ describe('Badge tests', () => {
const {getByTestId} = render(<Badge content="1" position="bottom" />);
const icon = getByTestId('badge-icon');

expect(icon).toHaveStyleRule('bottom', '-8px');
expect(icon).toHaveStyleRule('bottom', '0');
});

test('should not be dynamic', () => {
const {getByTestId} = render(<Badge content="1" dynamic={false} />);

const icon = getByTestId('badge-icon');
expect(icon).toHaveStyleRule('right', '-8px');
expect(icon).toHaveStyleRule('right', '0');
});
});
17 changes: 8 additions & 9 deletions src/web/components/badge/badge.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,22 @@ const BadgeContainer = styled.div`
BadgeContainer.displayName = 'BadgeContainer';

const BadgeIcon = styled.span`
display: flex;
flex-direction: row;
flex-wrap: wrap;
display: inline-flex;
justify-content: center;
align-content: center;
align-items: center;
position: absolute;
font-size: 10px;
font-size: 0.75em;
font-weight: bold;
border-radius: 10px;
border-radius: 50%;
min-width: 10px;
padding: 3px 5px;
padding: 0.25em 0.5em;
z-index: ${Theme.Layers.higher};
background-color: ${({$backgroundColor = Theme.green}) => $backgroundColor};
color: ${({$color = Theme.white}) => $color};
${({$position = 'bottom'}) => $position}: ${({radius = 8}) => -radius}px;
right: ${({$margin = 8}) => -$margin}px;
top: ${({$position}) => ($position === 'top' ? '0' : 'auto')};
bottom: ${({$position}) => ($position === 'bottom' ? '0' : 'auto')};
right: 0;
transform: translate(80%, -50%);
`;

BadgeIcon.displayName = 'BadgeIcon';
Expand Down
32 changes: 32 additions & 0 deletions src/web/components/form/__tests__/select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,38 @@ describe('Select component tests', () => {

expect(getSelectItemElements().length).toEqual(1);
});

test('should not call onChange handler when newValue is null or undefined', async () => {
const items = [
{
value: 'bar',
label: 'Bar',
},
{
value: 'foo',
label: 'Foo',
},
];

const onChange = testing.fn();

render(<Select items={items} value="bar" onChange={onChange} />);

const input = getSelectElement();

await openSelectElement(input);

const domItems = getSelectItemElements();

await clickElement(domItems[0]);

expect(onChange).not.toHaveBeenCalled();

await clickElement(domItems[1]);

expect(onChange).toHaveBeenCalledWith('foo', undefined);
});

describe('SelectItemRaw', () => {
test.each([
{
Expand Down
2 changes: 1 addition & 1 deletion src/web/components/form/select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const Select = ({

const handleChange = useCallback(
newValue => {
if (isDefined(onChange)) {
if (isDefined(onChange) && Boolean(newValue)) {
onChange(newValue, name);
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/web/components/structure/footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const GreenboneFooter = () => {
<Footer>
Copyright © 2009-2025 by Greenbone AG,&nbsp;
<Link
href="http://www.greenbone.net"
href="https://www.greenbone.net"
rel="noopener noreferrer"
target="_blank"
>
Expand Down
Loading