SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
test(service-account): mock motion lib & change drawer open/close detection (#12077)
Vinicius Lourençod1a06a91bfd5
diff --git a/frontend/__mocks__/motionMock.tsx b/frontend/__mocks__/motionMock.tsxnew file mode 100644index 0000000000..d7807ac699--- /dev/null+++ b/frontend/__mocks__/motionMock.tsx@@ -0,0 +1,88 @@+// oxlint-disable-next-line no-restricted-imports+import * as React from 'react';++// In jsdom, AnimatePresence from motion/react keeps children in DOM during exit+// animations (awaiting rAF-driven completion that never fully runs in jsdom).+// This mock makes AnimatePresence render children immediately and makes motion.*+// elements render as their plain HTML equivalents without animation side-effects.+//+// IMPORTANT: motion component references are cached so React sees a stable+// component identity across re-renders and does not enter an infinite remount loop.++const MOTION_PROPS_TO_STRIP = new Set([+ 'initial',+ 'animate',+ 'exit',+ 'variants',+ 'transition',+ 'whileHover',+ 'whileTap',+ 'whileFocus',+ 'whileInView',+ 'layout',+ 'layoutId',+ 'onAnimationStart',+ 'onAnimationComplete',+]);++const cache = new Map<string, React.ComponentType>();++function getMotionComponent(tag: string): React.ComponentType {+ if (!cache.has(tag)) {+ const Component = React.forwardRef<HTMLElement, Record<string, unknown>>(+ (props, ref) => {+ const domProps: Record<string, unknown> = {};+ for (const [k, v] of Object.entries(props)) {+ if (!MOTION_PROPS_TO_STRIP.has(k)) {+ domProps[k] = v;+ }+ }+ return React.createElement(tag, { ...domProps, ref });+ },+ );+ Component.displayName = `motion.${tag}`;+ cache.set(tag, Component as unknown as React.ComponentType);+ }+ return cache.get(tag) as React.ComponentType;+}++const motionHandler: ProxyHandler<Record<string, React.ComponentType>> = {+ get(_target, prop: string) {+ return getMotionComponent(prop);+ },+};++export const AnimatePresence: React.FC<{+ children?: React.ReactNode;+ mode?: string;+}> = ({ children }) => React.createElement(React.Fragment, null, children);++export const motion = new Proxy(+ {} as Record<string, React.ComponentType>,+ motionHandler,+);++export const useAnimation = (): Record<string, unknown> => ({+ start: (): unknown => Promise.resolve(),+ stop: (): unknown => undefined,+ set: (): unknown => undefined,+});++export const useMotionValue = (+ initial: unknown,+): { get: () => unknown; set: () => void } => ({+ get: (): unknown => initial,+ set: (): unknown => undefined,+});++export const useTransform = (): { get: () => number } => ({+ get: (): number => 0,+});++export const useSpring = (v: unknown): unknown => v;++export const useScroll = (): { scrollY: { get: () => number } } => ({+ scrollY: { get: (): number => 0 },+});++export default { motion, AnimatePresence };diff --git a/frontend/jest.config.ts b/frontend/jest.config.tsindex c60f315d9e..7a0c66109d 100644--- a/frontend/jest.config.ts+++ b/frontend/jest.config.ts@@ -20,6 +20,7 @@ const config: Config.InitialOptions = {'\\.module\\.mjs$': '<rootDir>/__mocks__/cssMock.ts','\\.md$': '<rootDir>/__mocks__/cssMock.ts','^uplot$': '<rootDir>/__mocks__/uplotMock.ts',+ '^motion/react$': '<rootDir>/__mocks__/motionMock.tsx','^@signozhq/resizable$': '<rootDir>/__mocks__/resizableMock.tsx','^hooks/useSafeNavigate$': USE_SAFE_NAVIGATE_MOCK_PATH,'^src/hooks/useSafeNavigate$': USE_SAFE_NAVIGATE_MOCK_PATH,diff --git a/frontend/src/components/CreateServiceAccountModal/CreateServiceAccountModal.tsx b/frontend/src/components/CreateServiceAccountModal/CreateServiceAccountModal.tsxindex db64a3a060..bf6ea463d1 100644--- a/frontend/src/components/CreateServiceAccountModal/CreateServiceAccountModal.tsx+++ b/frontend/src/components/CreateServiceAccountModal/CreateServiceAccountModal.tsx@@ -92,6 +92,7 @@ function CreateServiceAccountModal(): JSX.Element {width="narrow"className="create-sa-modal"disableOutsideClick={isErrorModalVisible}+ testId="create-service-account-modal"><div className="create-sa-modal__content"><formdiff --git a/frontend/src/components/CreateServiceAccountModal/__tests__/CreateServiceAccountModal.test.tsx b/frontend/src/components/CreateServiceAccountModal/__tests__/CreateServiceAccountModal.test.tsxindex c05200ef80..8643cf4c89 100644--- a/frontend/src/components/CreateServiceAccountModal/__tests__/CreateServiceAccountModal.test.tsx+++ b/frontend/src/components/CreateServiceAccountModal/__tests__/CreateServiceAccountModal.test.tsx@@ -1,13 +1,7 @@import { toast } from '@signozhq/ui/sonner';import { rest, server } from 'mocks-server/server';import { NuqsTestingAdapter } from 'nuqs/adapters/testing';-import {- render,- screen,- userEvent,- waitFor,- waitForElementToBeRemoved,-} from 'tests/test-utils';+import { render, screen, userEvent, waitFor } from 'tests/test-utils';import CreateServiceAccountModal from '../CreateServiceAccountModal';@@ -89,7 +83,7 @@ describe('CreateServiceAccountModal', () => {await waitFor(() => {expect(- screen.queryByRole('dialog', { name: /New Service Account/i }),+ screen.queryByTestId('create-service-account-modal'),).not.toBeInTheDocument();});});@@ -129,7 +123,7 @@ describe('CreateServiceAccountModal', () => {});expect(- screen.getByRole('dialog', { name: /New Service Account/i }),+ screen.getByTestId('create-service-account-modal'),).toBeInTheDocument();});@@ -137,15 +131,14 @@ describe('CreateServiceAccountModal', () => {const user = userEvent.setup({ pointerEventsCheck: 0 });renderModal();- const dialog = await screen.findByRole('dialog', {- name: /New Service Account/i,- });+ await screen.findByTestId('create-service-account-modal');await user.click(screen.getByRole('button', { name: /Cancel/i }));- await waitForElementToBeRemoved(dialog);- expect(- screen.queryByRole('dialog', { name: /New Service Account/i }),- ).not.toBeInTheDocument();+ await waitFor(() => {+ expect(+ screen.queryByTestId('create-service-account-modal'),+ ).not.toBeInTheDocument();+ });});it('shows "Name is required" after clearing the name field', async () => {diff --git a/frontend/src/components/ServiceAccountDrawer/AddKeyModal/index.tsx b/frontend/src/components/ServiceAccountDrawer/AddKeyModal/index.tsxindex 19ce64f887..59291f3187 100644--- a/frontend/src/components/ServiceAccountDrawer/AddKeyModal/index.tsx+++ b/frontend/src/components/ServiceAccountDrawer/AddKeyModal/index.tsx@@ -151,6 +151,7 @@ function AddKeyModal(): JSX.Element {className="add-key-modal"showCloseButtondisableOutsideClick={isErrorModalVisible}+ testId="add-key-modal">{phase === Phase.FORM && (<KeyFormPhasediff --git a/frontend/src/components/ServiceAccountDrawer/DeleteAccountModal.tsx b/frontend/src/components/ServiceAccountDrawer/DeleteAccountModal.tsxindex a8c6b8c443..049c846efb 100644--- a/frontend/src/components/ServiceAccountDrawer/DeleteAccountModal.tsx+++ b/frontend/src/components/ServiceAccountDrawer/DeleteAccountModal.tsx@@ -91,6 +91,7 @@ function DeleteAccountModal(): JSX.Element {color="destructive"loading={isDeleting}onClick={handleConfirm}+ data-testid="confirm-delete-btn"><Trash2 size={12} />Delete@@ -111,6 +112,7 @@ function DeleteAccountModal(): JSX.Element {className="alert-dialog sa-delete-dialog"showCloseButton={false}disableOutsideClick={isErrorModalVisible}+ testId="delete-service-account-modal"footer={footer}>{content}diff --git a/frontend/src/components/ServiceAccountDrawer/EditKeyModal/index.tsx b/frontend/src/components/ServiceAccountDrawer/EditKeyModal/index.tsxindex b8acd22855..c840ffdf47 100644--- a/frontend/src/components/ServiceAccountDrawer/EditKeyModal/index.tsx+++ b/frontend/src/components/ServiceAccountDrawer/EditKeyModal/index.tsx@@ -175,6 +175,7 @@ function EditKeyModal({ keyItem }: EditKeyModalProps): JSX.Element {}showCloseButton={!isRevokeConfirmOpen}disableOutsideClick={isErrorModalVisible}+ testId="edit-key-modal"footer={isRevokeConfirmOpen ? (<RevokeKeyFooterdiff --git a/frontend/src/components/ServiceAccountDrawer/__tests__/AddKeyModal.test.tsx b/frontend/src/components/ServiceAccountDrawer/__tests__/AddKeyModal.test.tsxindex 92641fd481..0431d30d79 100644--- a/frontend/src/components/ServiceAccountDrawer/__tests__/AddKeyModal.test.tsx+++ b/frontend/src/components/ServiceAccountDrawer/__tests__/AddKeyModal.test.tsx@@ -2,13 +2,7 @@ import { toast } from '@signozhq/ui/sonner';import { setupAuthzAdmin } from 'lib/authz/utils/authz-test-utils';import { rest, server } from 'mocks-server/server';import { NuqsTestingAdapter } from 'nuqs/adapters/testing';-import {- render,- screen,- userEvent,- waitFor,- waitForElementToBeRemoved,-} from 'tests/test-utils';+import { render, screen, userEvent, waitFor } from 'tests/test-utils';import AddKeyModal from '../AddKeyModal';@@ -97,7 +91,7 @@ describe('AddKeyModal', () => {await screen.findByText('snz_abc123xyz456secret');expect(screen.getByText(/Store the key securely/i)).toBeInTheDocument();- await screen.findByRole('dialog', { name: /Key Created Successfully/i });+ expect(screen.getByTestId('add-key-modal')).toBeInTheDocument();});it('copy button writes key to clipboard and shows toast.success', async () => {@@ -133,9 +127,11 @@ describe('AddKeyModal', () => {const user = userEvent.setup({ pointerEventsCheck: 0 });renderModal();- const dialog = await screen.findByRole('dialog', { name: /Add a New Key/i });+ await screen.findByTestId('add-key-modal');await user.click(screen.getByRole('button', { name: /Cancel/i }));- await waitForElementToBeRemoved(dialog);+ await waitFor(() => {+ expect(screen.queryByTestId('add-key-modal')).not.toBeInTheDocument();+ });});});diff --git a/frontend/src/components/ServiceAccountDrawer/__tests__/EditKeyModal.test.tsx b/frontend/src/components/ServiceAccountDrawer/__tests__/EditKeyModal.test.tsxindex 5e0cc7bd96..bcbe46c57d 100644--- a/frontend/src/components/ServiceAccountDrawer/__tests__/EditKeyModal.test.tsx+++ b/frontend/src/components/ServiceAccountDrawer/__tests__/EditKeyModal.test.tsx@@ -73,9 +73,7 @@ describe('EditKeyModal (URL-controlled)', () => {it('renders nothing when edit-key param is absent', () => {renderModal(null, { account: 'sa-1' });- expect(- screen.queryByRole('dialog', { name: /Edit Key Details/i }),- ).not.toBeInTheDocument();+ expect(screen.queryByTestId('edit-key-modal')).not.toBeInTheDocument();});it('renders key data from prop when edit-key param is set', async () => {@@ -102,9 +100,7 @@ describe('EditKeyModal (URL-controlled)', () => {});await waitFor(() => {- expect(- screen.queryByRole('dialog', { name: /Edit Key Details/i }),- ).not.toBeInTheDocument();+ expect(screen.queryByTestId('edit-key-modal')).not.toBeInTheDocument();});});@@ -131,9 +127,7 @@ describe('EditKeyModal (URL-controlled)', () => {expect(latestUrlUpdate.queryString).not.toContain('edit-key=');await waitFor(() => {- expect(- screen.queryByRole('dialog', { name: /Edit Key Details/i }),- ).not.toBeInTheDocument();+ expect(screen.queryByTestId('edit-key-modal')).not.toBeInTheDocument();});});@@ -145,9 +139,7 @@ describe('EditKeyModal (URL-controlled)', () => {await user.click(screen.getByRole('button', { name: /Revoke Key/i }));// Same dialog, now showing revoke confirmation- await expect(- screen.findByRole('dialog', { name: /Revoke Original Key Name/i }),- ).resolves.toBeInTheDocument();+ expect(screen.getByTestId('edit-key-modal')).toBeInTheDocument();expect(screen.getByText(/Revoking this key will permanently invalidate it/i),).toBeInTheDocument();@@ -170,9 +162,7 @@ describe('EditKeyModal (URL-controlled)', () => {});await waitFor(() => {- expect(- screen.queryByRole('dialog', { name: /Edit Key Details/i }),- ).not.toBeInTheDocument();+ expect(screen.queryByTestId('edit-key-modal')).not.toBeInTheDocument();});});});diff --git a/frontend/src/components/ServiceAccountDrawer/__tests__/ServiceAccountDrawer.test.tsx b/frontend/src/components/ServiceAccountDrawer/__tests__/ServiceAccountDrawer.test.tsxindex ad24f7ea60..08fb632bda 100644--- a/frontend/src/components/ServiceAccountDrawer/__tests__/ServiceAccountDrawer.test.tsx+++ b/frontend/src/components/ServiceAccountDrawer/__tests__/ServiceAccountDrawer.test.tsx@@ -222,21 +222,20 @@ describe('ServiceAccountDrawer', () => {screen.getByRole('button', { name: /Delete Service Account/i }),);- const dialog = await screen.findByRole('dialog', {- name: /Delete service account CI Bot/i,- });- expect(dialog).toBeInTheDocument();-- const confirmBtns = screen.getAllByRole('button', { name: /^Delete$/i });- await user.click(confirmBtns[confirmBtns.length - 1]);+ await screen.findByTestId('delete-service-account-modal');+ expect(+ screen.getByTestId('delete-service-account-modal'),+ ).toBeInTheDocument();- await waitFor(() => {- expect(deleteSpy).toHaveBeenCalled();- });+ await user.click(screen.getByTestId('confirm-delete-btn'));- await waitFor(() => {- expect(screen.queryByDisplayValue('CI Bot')).not.toBeInTheDocument();- });+ await waitFor(+ () => {+ expect(deleteSpy).toHaveBeenCalled();+ expect(screen.queryByDisplayValue('CI Bot')).not.toBeInTheDocument();+ },+ { timeout: 3000 },+ );});it('deleted account shows read-only name, no Save button, no Delete button', async () => {diff --git a/frontend/src/container/ServiceAccountsSettings/__tests__/ServiceAccountsSettings.authz.integration.test.tsx b/frontend/src/container/ServiceAccountsSettings/__tests__/ServiceAccountsSettings.authz.integration.test.tsxindex 3946ee1e7b..88323441f3 100644--- a/frontend/src/container/ServiceAccountsSettings/__tests__/ServiceAccountsSettings.authz.integration.test.tsx+++ b/frontend/src/container/ServiceAccountsSettings/__tests__/ServiceAccountsSettings.authz.integration.test.tsx@@ -208,7 +208,7 @@ describe('ServiceAccountsSettings (integration)', () => {fireEvent.click(screen.getByRole('button', { name: /New Service Account/i }));- await screen.findByRole('dialog', { name: /New Service Account/i });+ await screen.findByTestId('create-service-account-modal');expect(screen.getByPlaceholderText('Enter a name')).toBeInTheDocument();});