import { queryHelpers, screen, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import * as React from 'react';
+import { byRole } from 'testing-library-selector';
import { SourceViewerServiceMock } from '../../../api/mocks/SourceViewerServiceMock';
import { HttpStatus } from '../../../helpers/request';
import { mockIssue } from '../../../helpers/testMocks';
};
});
+const ui = {
+ codeSmellTypeButton: byRole('button', { name: 'issue.type.CODE_SMELL' }),
+ minorSeverityButton: byRole('button', { name: 'severity.MINOR' })
+};
+
const handler = new SourceViewerServiceMock();
beforeEach(() => {
await user.click(
await screen.findByRole('button', { name: 'issue.type.type_x_click_to_change.issue.type.BUG' })
);
- expect(screen.getByRole('link', { name: 'issue.type.CODE_SMELL' })).toBeInTheDocument();
+ expect(ui.codeSmellTypeButton.get()).toBeInTheDocument();
// Open severity
await user.click(
name: 'issue.severity.severity_x_click_to_change.severity.MAJOR'
})
);
- expect(screen.getByRole('link', { name: 'severity.MINOR' })).toBeInTheDocument();
+ expect(ui.minorSeverityButton.get()).toBeInTheDocument();
// Close
await user.keyboard('{Escape}');
- expect(screen.queryByRole('link', { name: 'severity.MINOR' })).not.toBeInTheDocument();
+ expect(ui.minorSeverityButton.query()).not.toBeInTheDocument();
// Change the severity
await user.click(
name: 'issue.severity.severity_x_click_to_change.severity.MAJOR'
})
);
- expect(screen.getByRole('link', { name: 'severity.MINOR' })).toBeInTheDocument();
- await user.click(screen.getByRole('link', { name: 'severity.MINOR' }));
+ expect(ui.minorSeverityButton.get()).toBeInTheDocument();
+ await user.click(ui.minorSeverityButton.get());
expect(
screen.getByRole('button', {
name: 'issue.severity.severity_x_click_to_change.severity.MINOR'
import classNames from 'classnames';
import * as React from 'react';
import Tooltip from '../../components/controls/Tooltip';
+import { ButtonPlain } from '../controls/buttons';
interface Props {
active?: string;
}
export default class SelectListItem extends React.PureComponent<Props> {
- handleSelect = (event: React.MouseEvent<HTMLAnchorElement>) => {
- event.preventDefault();
+ handleSelect = () => {
if (this.props.onSelect) {
this.props.onSelect(this.props.item);
}
const children = this.props.children || this.props.item;
return (
<li>
- <a
+ <ButtonPlain
+ preventDefault={true}
+ aria-selected={this.props.active === this.props.item}
className={classNames(
{
active: this.props.active === this.props.item,
},
this.props.className
)}
- href="#"
onClick={this.handleSelect}
onFocus={this.handleHover}
onMouseOver={this.handleHover}>
{children}
- </a>
+ </ButtonPlain>
</li>
);
}