Переглянути джерело

SONAR-21942 Fixing scroll issue inside issue details page

tags/10.5.0.89998
Revanshu Paliwal 2 місяці тому
джерело
коміт
914c61259b

+ 2
- 8
server/sonar-web/src/main/js/apps/issues/issues-subnavigation/SubnavigationIssue.tsx Переглянути файл

import IssueItemLocationsQuantity from './IssueItemLocationsQuantity'; import IssueItemLocationsQuantity from './IssueItemLocationsQuantity';
import IssueLocationsNavigator from './IssueLocationsNavigator'; import IssueLocationsNavigator from './IssueLocationsNavigator';


const HALF_DIVIDER = 2;

export interface ConciseIssueProps { export interface ConciseIssueProps {
issue: Issue; issue: Issue;
onFlowSelect: (index?: number) => void; onFlowSelect: (index?: number) => void;
const element = React.useRef<HTMLLIElement>(null); const element = React.useRef<HTMLLIElement>(null);


React.useEffect(() => { React.useEffect(() => {
if (selected && element.current) {
const parent = document.querySelector('nav.issues-nav-bar') as HTMLMenuElement;
const rect = parent.getBoundingClientRect();
const offset =
element.current.offsetTop - rect.height / HALF_DIVIDER + rect.top / HALF_DIVIDER;
parent.scrollTo({ top: offset, behavior: 'smooth' });
if (selected) {
element.current?.scrollIntoView({ block: 'nearest' });
} }
}, [selected]); }, [selected]);



+ 6
- 20
server/sonar-web/src/main/js/apps/issues/issues-subnavigation/__tests__/SubnavigationIssues-it.tsx Переглянути файл

}), }),
]; ];


const scrollTo = jest.fn();

beforeAll(() => {
// eslint-disable-next-line testing-library/no-node-access
document.querySelector = jest.fn(() => ({
scrollTo,
getBoundingClientRect: () => ({
height: 10,
}),
}));
});

beforeEach(() => {
scrollTo.mockClear();
});

describe('rendering', () => { describe('rendering', () => {
it('should render concise issues without duplicating component', () => { it('should render concise issues without duplicating component', () => {
renderConciseIssues(issues); renderConciseIssues(issues);
renderConciseIssues(issues, { renderConciseIssues(issues, {
selected: 'issue2', selected: 'issue2',
}); });

expect(scrollTo).toHaveBeenCalledTimes(1);
}); });


it('should show locations and flows when selected', () => { it('should show locations and flows when selected', () => {


describe('interacting', () => { describe('interacting', () => {
it('should scroll selected issue into view', () => { it('should scroll selected issue into view', () => {
const scrollIntoView = jest.fn();
const globalScrollView = window.HTMLElement.prototype.scrollIntoView;
window.HTMLElement.prototype.scrollIntoView = scrollIntoView;
const { override } = renderConciseIssues(issues, { const { override } = renderConciseIssues(issues, {
selected: 'issue2', selected: 'issue2',
}); });


expect(scrollTo).toHaveBeenCalledTimes(1);
expect(scrollIntoView).toHaveBeenCalledTimes(1);


override(issues, { override(issues, {
selected: 'issue4', selected: 'issue4',
}); });
expect(scrollTo).toHaveBeenCalledTimes(2);
expect(scrollIntoView).toHaveBeenCalledTimes(2);
window.HTMLElement.prototype.scrollIntoView = globalScrollView;
}); });


it('expand button should work correctly', async () => { it('expand button should work correctly', async () => {

Завантаження…
Відмінити
Зберегти