From 14c4a42e54297912ed40e32b6a14081aa62102d8 Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Mon, 30 May 2022 18:43:36 +0200 Subject: [PATCH] SONAR-14654 Hide indexation banner after completion --- .../app/components/indexation/IndexationNotification.tsx | 7 +++++++ .../indexation/__tests__/IndexationNotification-test.tsx | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) 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(); }); }); -- 2.39.5