]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-20295 Fix flaky test in ComponentMeasures-it
authorDavid Cho-Lerat <david.cho-lerat@sonarsource.com>
Thu, 31 Aug 2023 12:10:52 +0000 (14:10 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 31 Aug 2023 20:02:56 +0000 (20:02 +0000)
server/sonar-web/src/main/js/apps/component-measures/__tests__/ComponentMeasures-it.tsx

index c235053b9b96e9197e76fddfc7b5a21a2b58a5c2..8d0baf6d281595a4b289a610dd9e3aa829c24e33 100644 (file)
@@ -34,6 +34,11 @@ import { Feature } from '../../../types/features';
 import { MetricKey } from '../../../types/metrics';
 import routes from '../routes';
 
+jest.mock('lodash', () => ({
+  ...jest.requireActual('lodash'),
+  throttle: (fn: (...args: unknown[]) => unknown) => fn,
+}));
+
 jest.mock('../../../api/metrics', () => {
   const { DEFAULT_METRICS } = jest.requireActual('../../../helpers/mocks/metrics');
   const metrics = Object.values(MetricKey).map(
@@ -340,10 +345,10 @@ describe('navigation', () => {
     await user.click(ui.maintainabilityDomainBtn.get());
     await user.click(ui.measureBtn('Code Smells 8').get());
 
-    // Select "folderA".
-    await ui.arrowDown();
+    await ui.arrowDown(); // Select the 1st element ("folderA")
+
     await act(async () => {
-      await ui.arrowRight();
+      await ui.arrowRight(); // Open "folderA"
     });
 
     expect(
@@ -355,21 +360,21 @@ describe('navigation', () => {
 
     // Move back to project.
     await act(async () => {
-      await ui.arrowLeft();
+      await ui.arrowLeft(); // Close "folderA"
     });
 
     expect(
       within(ui.measuresRow('folderA').get()).getByRole('cell', { name: '3' })
     ).toBeInTheDocument();
 
-    // Go to "folderA/out.tsx".
     await act(async () => {
-      await ui.arrowRight();
+      await ui.arrowRight(); // Open "folderA"
     });
-    await ui.arrowDown();
-    await ui.arrowDown();
+
+    await ui.arrowDown(); // Select the 1st element ("out.tsx")
+
     await act(async () => {
-      await ui.arrowRight();
+      await ui.arrowRight(); // Open "out.tsx"
     });
 
     expect((await ui.sourceCode.findAll()).length).toBeGreaterThan(0);