From 5a9689b5abab3a5d85ecf3c0b10b9f14f07b8d05 Mon Sep 17 00:00:00 2001 From: Santiago Palenque Date: Fri, 7 Aug 2026 12:36:10 -0300 Subject: [PATCH 1/2] chore: change useScrollToError to allow switch tab, and apply to edit activity type --- src/hooks/__tests__/useScrollToError.test.js | 131 ++++++++++++++++++ src/hooks/useScrollToError.js | 92 +++++++++--- .../__tests__/event-type-dialog.test.js | 22 +++ .../events/components/event-type-dialog.js | 14 +- 4 files changed, 233 insertions(+), 26 deletions(-) create mode 100644 src/hooks/__tests__/useScrollToError.test.js diff --git a/src/hooks/__tests__/useScrollToError.test.js b/src/hooks/__tests__/useScrollToError.test.js new file mode 100644 index 000000000..c31091779 --- /dev/null +++ b/src/hooks/__tests__/useScrollToError.test.js @@ -0,0 +1,131 @@ +// @testing-library/react 12 (React 16) does not export renderHook; use a +// lightweight component wrapper instead. +import "@testing-library/jest-dom"; +import React, { useState } from "react"; +import { act, render, screen } from "@testing-library/react"; +import { useFormik } from "formik"; +import useScrollToError from "../useScrollToError"; + +window.HTMLElement.prototype.scrollIntoView = jest.fn(); + +// jsdom implements no layout, so offsetParent is always null regardless of +// CSS. Reflect the one hiding mechanism this hook cares about (the `hidden` +// attribute) so tests can simulate real display:none semantics. +beforeAll(() => { + Object.defineProperty(window.HTMLElement.prototype, "offsetParent", { + configurable: true, + get() { + let node = this; + while (node) { + if (node.hidden) return null; + node = node.parentElement; + } + return document.body; + } + }); +}); + +beforeEach(() => { + window.HTMLElement.prototype.scrollIntoView.mockClear(); +}); + +const flushDoubleRaf = () => + act( + () => + new Promise((resolve) => { + requestAnimationFrame(() => requestAnimationFrame(resolve)); + }) + ); + +const TabbedHarness = ({ onActiveTabChange }) => { + const [activeTab, setActiveTab] = useState("b"); + const formik = useFormik({ + initialValues: { name: "" }, + validate: (values) => (values.name ? {} : { name: "required" }), + onSubmit: () => {} + }); + + useScrollToError(formik, true, (value) => { + setActiveTab(value); + onActiveTabChange?.(value); + }); + + return ( +
+ +