]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-18600 Remove deprecated and unused function scrollHorizontally
authorAmbroise C <ambroise.christea@sonarsource.com>
Wed, 8 Mar 2023 13:32:19 +0000 (14:32 +0100)
committersonartech <sonartech@sonarsource.com>
Thu, 9 Mar 2023 20:02:59 +0000 (20:02 +0000)
server/sonar-web/src/main/js/helpers/__tests__/scrolling-test.ts
server/sonar-web/src/main/js/helpers/scrolling.ts

index dc1a18d2d1d9e64aad99f2aab4d631c7bea1681a..f9e938f2c13eb09fea7c400aa4c6c8984b0f9ccd 100644 (file)
@@ -17,7 +17,7 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
-import { scrollHorizontally, scrollToElement } from '../scrolling';
+import { scrollToElement } from '../scrolling';
 
 beforeAll(() => {
   jest.useFakeTimers();
@@ -108,112 +108,6 @@ describe('scrollToElement', () => {
   });
 });
 
-describe('scrollHorizontally', () => {
-  it('should scroll parent left to element', () => {
-    const element = document.createElement('a');
-    element.getBoundingClientRect = mockGetBoundingClientRect({ left: 25, right: 42 });
-
-    const parent = document.createElement('div');
-    parent.getBoundingClientRect = mockGetBoundingClientRect({ width: 67, left: 46 });
-    parent.scrollTop = 12;
-    parent.scrollLeft = 38;
-    parent.appendChild(element);
-
-    document.body.appendChild(parent);
-
-    scrollHorizontally(element, { parent, smooth: false });
-
-    expect(parent.scrollTop).toEqual(12);
-    expect(parent.scrollLeft).toEqual(17);
-  });
-
-  it('should scroll parent right to element', () => {
-    const element = document.createElement('a');
-    element.getBoundingClientRect = mockGetBoundingClientRect({ left: 25, right: 99 });
-
-    const parent = document.createElement('div');
-    parent.getBoundingClientRect = mockGetBoundingClientRect({ width: 67, left: 20 });
-    parent.scrollTop = 12;
-    parent.scrollLeft = 20;
-    parent.appendChild(element);
-
-    document.body.appendChild(parent);
-
-    scrollHorizontally(element, { parent, smooth: false });
-
-    expect(parent.scrollTop).toEqual(12);
-    expect(parent.scrollLeft).toEqual(32);
-  });
-
-  it('should scroll window right to element', () => {
-    const element = document.createElement('a');
-    element.getBoundingClientRect = mockGetBoundingClientRect({ left: 840, right: 845 });
-
-    Object.defineProperty(window, 'innerWidth', { value: 400 });
-    window.scrollTo = jest.fn();
-
-    document.body.appendChild(element);
-
-    scrollHorizontally(element, { smooth: false });
-
-    expect(window.scrollTo).toHaveBeenCalledWith(445, 0);
-  });
-
-  it('should scroll window left to element', () => {
-    const element = document.createElement('a');
-    element.getBoundingClientRect = mockGetBoundingClientRect({ left: -10, right: 10 });
-
-    Object.defineProperty(window, 'innerWidth', { value: 50 });
-    window.scrollTo = jest.fn();
-
-    document.body.appendChild(element);
-
-    scrollHorizontally(element, { smooth: false });
-
-    expect(window.scrollTo).toHaveBeenCalledWith(-10, 0);
-  });
-
-  it('should scroll window right to element smoothly', () => {
-    const element = document.createElement('a');
-    element.getBoundingClientRect = mockGetBoundingClientRect({ left: 840, right: 845 });
-
-    Object.defineProperty(window, 'innerWidth', { value: 400 });
-    window.scrollTo = jest.fn();
-
-    document.body.appendChild(element);
-
-    scrollHorizontally(element, {});
-
-    jest.runAllTimers();
-
-    expect(window.scrollTo).toHaveBeenCalledTimes(10);
-  });
-});
-
-it('correctly queues and processes multiple scroll calls', async () => {
-  const element1 = document.createElement('a');
-  const element2 = document.createElement('a');
-  document.body.appendChild(element1);
-  document.body.appendChild(element2);
-  element1.getBoundingClientRect = mockGetBoundingClientRect({ left: 840, right: 845 });
-  element2.getBoundingClientRect = mockGetBoundingClientRect({ top: -10, bottom: 10 });
-
-  window.scrollTo = jest.fn();
-
-  scrollHorizontally(element1, {});
-  scrollToElement(element2, { smooth: false });
-
-  jest.runAllTimers();
-  await Promise.resolve(setImmediate);
-  await Promise.resolve(setImmediate);
-
-  expect(window.scrollTo).toHaveBeenCalledTimes(11);
-
-  scrollHorizontally(element1, {});
-  jest.runAllTimers();
-  expect(window.scrollTo).toHaveBeenCalledTimes(21);
-});
-
 const mockGetBoundingClientRect = (overrides: Partial<ClientRect>) => () =>
   ({
     bottom: 0,
index cd57d1ae13b4a6bb7f0e5a34ba638910c3330929..5edda86d2e06d953ea541408d3d612775f3455e8 100644 (file)
@@ -75,11 +75,6 @@ function smoothScrollTop(parent: Element | Window, position: number) {
   return smoothScroll(position, scroll.y, (position) => scrollElement(parent, scroll.x, position));
 }
 
-function smoothScrollLeft(parent: Element | Window, position: number) {
-  const scroll = getScroll(parent);
-  return smoothScroll(position, scroll.x, (position) => scrollElement(parent, position, scroll.y));
-}
-
 /**
  * @deprecated use scrollIntoView instead
  */
@@ -124,48 +119,6 @@ export function scrollToElement(
   }
 }
 
-/**
- * @deprecated use scrollIntoView instead
- */
-export function scrollHorizontally(
-  element: Element,
-  options: {
-    leftOffset?: number;
-    rightOffset?: number;
-    parent?: Element;
-    smooth?: boolean;
-  }
-): void {
-  const opts = { leftOffset: 0, rightOffset: 0, parent: window, smooth: true, ...options };
-  const { parent } = opts;
-
-  const { left, right } = element.getBoundingClientRect();
-
-  const scroll = getScroll(parent);
-
-  const { left: parentLeft, width } = isWindow(parent)
-    ? { left: 0, width: window.innerWidth }
-    : parent.getBoundingClientRect();
-
-  if (left - parentLeft < opts.leftOffset) {
-    const goal = scroll.x - opts.leftOffset + left - parentLeft;
-    if (opts.smooth) {
-      addToScrollQueue(smoothScrollLeft, parent, goal);
-    } else {
-      addToScrollQueue(scrollElement, parent, goal, scroll.y);
-    }
-  }
-
-  if (right - parentLeft > width - opts.rightOffset) {
-    const goal = scroll.x + right - parentLeft - width + opts.rightOffset;
-    if (opts.smooth) {
-      addToScrollQueue(smoothScrollLeft, parent, goal);
-    } else {
-      addToScrollQueue(scrollElement, parent, goal, scroll.y);
-    }
-  }
-}
-
 type ScrollFunction = (element: Element | Window, x: number, y?: number) => Promise<void>;
 
 interface ScrollQueueItem {