From: Jeremy Davis Date: Mon, 30 May 2022 16:43:36 +0000 (+0200) Subject: SONAR-14654 Hide indexation banner after completion X-Git-Tag: 9.5.0.56709~61 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=14c4a42e54297912ed40e32b6a14081aa62102d8;p=sonarqube.git SONAR-14654 Hide indexation banner after completion --- diff --git a/server/sonar-web/src/main/js/app/components/indexation/IndexationNotification.tsx b/server/sonar-web/src/main/js/app/components/indexation/IndexationNotification.tsx index 52bb015e917..28c9eae4420 100644 --- a/server/sonar-web/src/main/js/app/components/indexation/IndexationNotification.tsx +++ b/server/sonar-web/src/main/js/app/components/indexation/IndexationNotification.tsx @@ -38,6 +38,8 @@ interface State { notificationType?: IndexationNotificationType; } +const COMPLETED_NOTIFICATION_DISPLAY_DURATION = 5000; + export class IndexationNotification extends React.PureComponent { state: State = {}; isSystemAdmin = false; @@ -77,6 +79,11 @@ export class IndexationNotification extends React.PureComponent { notificationType: IndexationNotificationType.Completed }); IndexationNotificationHelper.markCompletedNotificationAsDisplayed(); + + // Hide after some time + setTimeout(() => { + this.refreshNotification(); + }, COMPLETED_NOTIFICATION_DISPLAY_DURATION); } else { this.setState({ notificationType: undefined }); } diff --git a/server/sonar-web/src/main/js/app/components/indexation/__tests__/IndexationNotification-test.tsx b/server/sonar-web/src/main/js/app/components/indexation/__tests__/IndexationNotification-test.tsx index 6367883eaf6..b144dd38fa4 100644 --- a/server/sonar-web/src/main/js/app/components/indexation/__tests__/IndexationNotification-test.tsx +++ b/server/sonar-web/src/main/js/app/components/indexation/__tests__/IndexationNotification-test.tsx @@ -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(); }); });