Skip to content

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.

test: loadable component is added (#2650)

Palash Guptaa8eec1b7abab
diff --git a/frontend/src/components/Loadable/Loadable.test.tsx b/frontend/src/components/Loadable/Loadable.test.tsx
new file mode 100644
index 0000000000..cb1239334f
--- /dev/null
+++ b/frontend/src/components/Loadable/Loadable.test.tsx
@@ -0,0 +1,49 @@
+import {
+ render,
+ screen,
+ waitForElementToBeRemoved,
+} from '@testing-library/react';
+import React from 'react';
+
+import Loadable from './index';
+
+// Sample component to be loaded lazily
+function SampleComponent(): JSX.Element {
+ return <div>Sample Component</div>;
+}
+
+const loadSampleComponent = (): Promise<{
+ default: React.ComponentType;
+}> =>
+ new Promise<{ default: React.ComponentType }>((resolve) => {
+ setTimeout(() => {
+ resolve({ default: SampleComponent });
+ }, 500);
+ });
+
+describe('Loadable', () => {
+ it('should render the lazily loaded component', async () => {
+ const LoadableSampleComponent = Loadable(loadSampleComponent);
+
+ const { container } = render(
+ <React.Suspense fallback={<div>Loading...</div>}>
+ <LoadableSampleComponent />
+ </React.Suspense>,
+ );
+
+ expect(screen.getByText('Loading...')).toBeInTheDocument();
+ await waitForElementToBeRemoved(() => screen.queryByText('Loading...'));
+
+ expect(container.querySelector('div')).toHaveTextContent('Sample Component');
+ });
+
+ it('should call React.lazy with the provided import path', () => {
+ const reactLazySpy = jest.spyOn(React, 'lazy');
+ Loadable(loadSampleComponent);
+
+ expect(reactLazySpy).toHaveBeenCalledTimes(1);
+ expect(reactLazySpy).toHaveBeenCalledWith(expect.any(Function));
+
+ reactLazySpy.mockRestore();
+ });
+});