]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-14654 Hide indexation banner after completion
authorJeremy Davis <jeremy.davis@sonarsource.com>
Mon, 30 May 2022 16:43:36 +0000 (18:43 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 1 Jun 2022 20:03:02 +0000 (20:03 +0000)
server/sonar-web/src/main/js/app/components/indexation/IndexationNotification.tsx
server/sonar-web/src/main/js/app/components/indexation/__tests__/IndexationNotification-test.tsx

index 52bb015e9171f25e6c051b597ef818bd5256a179..28c9eae442026dfe8d7ed63e0427906203551ac7 100644 (file)
@@ -38,6 +38,8 @@ interface State {
   notificationType?: IndexationNotificationType;
 }
 
+const COMPLETED_NOTIFICATION_DISPLAY_DURATION = 5000;
+
 export class IndexationNotification extends React.PureComponent<Props, State> {
   state: State = {};
   isSystemAdmin = false;
@@ -77,6 +79,11 @@ export class IndexationNotification extends React.PureComponent<Props, State> {
         notificationType: IndexationNotificationType.Completed
       });
       IndexationNotificationHelper.markCompletedNotificationAsDisplayed();
+
+      // Hide after some time
+      setTimeout(() => {
+        this.refreshNotification();
+      }, COMPLETED_NOTIFICATION_DISPLAY_DURATION);
     } else {
       this.setState({ notificationType: undefined });
     }
index 6367883eaf681eb3fdf8954033ae740cde732c7d..b144dd38fa4af1ae17719f31f604f54aa73c0d57 100644 (file)
@@ -61,7 +61,8 @@ describe('Completed banner', () => {
     expect(wrapper.state().notificationType).toBe(IndexationNotificationType.Completed);
   });
 
-  it('should be hidden on refresh once displayed', () => {
+  it('should be hidden once displayed', () => {
+    jest.useFakeTimers();
     (IndexationNotificationHelper.shouldDisplayCompletedNotification as jest.Mock).mockReturnValueOnce(
       true
     );
@@ -74,6 +75,11 @@ describe('Completed banner', () => {
 
     expect(wrapper.state().notificationType).toBe(IndexationNotificationType.Completed);
     expect(IndexationNotificationHelper.markCompletedNotificationAsDisplayed).toHaveBeenCalled();
+
+    jest.runAllTimers();
+    expect(wrapper.state().notificationType).toBeUndefined();
+
+    jest.useRealTimers();
   });
 });