Browse Source

[ui-metrics-test] Adding an additional test for the metrics Page (#3761)

* [ui-metrics-test] Adding an additional test for the metrics Page

* Changing the names of metrics to actual names of the metrics present in the page

* Adding a metrics to the test that will be present and rendered

* Removing superfluous comments

* Correction for the mock api for the test
Ananya_Agarwal 1 year ago
parent
commit
18b21b71a0

+ 41 - 4
desktop/core/src/desktop/js/reactComponents/MetricsComponent/MetricsComponent.test.tsx

@@ -28,13 +28,13 @@ jest.mock('api/utils', () => ({
         'requests.active': { count: 5 },
         'requests.active': { count: 5 },
         'requests.exceptions': { count: 2 },
         'requests.exceptions': { count: 2 },
         'requests.response-time': {
         'requests.response-time': {
-          '15m_rate': 20,
           '1m_rate': 15,
           '1m_rate': 15,
+          '15m_rate': 20,
           '5m_rate': 18,
           '5m_rate': 18,
           '75_percentile': 50,
           '75_percentile': 50,
           '95_percentile': 60,
           '95_percentile': 60,
-          '999_percentile': 70,
           '99_percentile': 55,
           '99_percentile': 55,
+          '999_percentile': 70,
           avg: 25,
           avg: 25,
           count: 100,
           count: 100,
           max: 30,
           max: 30,
@@ -54,7 +54,6 @@ jest.mock('api/utils', () => ({
 }));
 }));
 
 
 describe('MetricsComponent', () => {
 describe('MetricsComponent', () => {
-  // Test for filtering metrics based on input
   test('Filtering metrics based on name column value', async () => {
   test('Filtering metrics based on name column value', async () => {
     render(<MetricsComponent />);
     render(<MetricsComponent />);
 
 
@@ -74,7 +73,6 @@ describe('MetricsComponent', () => {
     });
     });
   });
   });
 
 
-  // Test for selecting a specific metric from the dropdown
   test('selecting a specific metric from the dropdown filters the data using click events', async () => {
   test('selecting a specific metric from the dropdown filters the data using click events', async () => {
     render(<MetricsComponent />);
     render(<MetricsComponent />);
 
 
@@ -96,4 +94,43 @@ describe('MetricsComponent', () => {
       });
       });
     }
     }
   });
   });
+
+  test('ensuring metrics starting with auth, multiprocessing and python.gc are not displayed', async () => {
+    jest.clearAllMocks();
+    jest.mock('api/utils', () => ({
+      get: jest.fn(() =>
+        Promise.resolve({
+          metric: {
+            'auth.ldap.auth-time': {
+              '1m_rate': 20,
+              '5m_rate': 15,
+              '15m_rate': 30,
+              '75_percentile': 50,
+              '95_percentile': 60,
+              '99_percentile': 55,
+              '999_percentile': 70,
+              avg: 25,
+              count: 100,
+              max: 30,
+              mean_rate: 22,
+              min: 20,
+              std_dev: 5,
+              sum: 2000
+            },
+            'multiprocessing.processes.total': { value: 5 },
+            'python.gc.objects': { value: 2 },
+            users: { value: 50 }
+          }
+        })
+      )
+    }));
+    render(<MetricsComponent />);
+
+    await waitFor(() => {
+      expect(screen.queryByText('auth.ldap.auth-time')).not.toBeInTheDocument();
+      expect(screen.queryByText('multiprocessing.processes.total')).not.toBeInTheDocument();
+      expect(screen.queryByText('python.gc.objects')).not.toBeInTheDocument();
+      expect(screen.queryByText('users')).toBeInTheDocument();
+    });
+  });
 });
 });