[Security Solution][AVC banner] Hide AVC banner on January 1, 2025 (#187929)

## Summary

- [x] Hides the avc banner when the local system time is 1/1/2025
- [x] Updates the blog link 
- [x] Unit tests

---------

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Candace Park 2024-08-01 16:08:32 -04:00 committed by GitHub
parent 305f2d7916
commit f4b2b449f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 35 additions and 8 deletions

View file

@ -6,7 +6,7 @@
* Side Public License, v 1.
*/
import React from 'react';
import React, { useMemo } from 'react';
import { css } from '@emotion/css';
import { i18n } from '@kbn/i18n';
import { EuiButton, EuiCallOut, EuiSpacer, useEuiTheme } from '@elastic/eui';
@ -14,6 +14,13 @@ import { FormattedMessage } from '@kbn/i18n-react';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import avcBannerBackground from './avc_banner_background.svg';
// Logic to hide banner at EOY 2024
export const useIsStillYear2024: () => boolean = () => {
return useMemo(() => {
return new Date().getFullYear() === 2024;
}, []);
};
export const AVCResultsBanner2024: React.FC<{ onDismiss: () => void }> = ({ onDismiss }) => {
const { docLinks } = useKibana().services;
const { euiTheme } = useEuiTheme();

View file

@ -466,7 +466,7 @@ export const getDocLinks = ({ kibanaBranch, buildFlavor }: GetDocLinkOptions): D
},
securitySolution: {
artifactControl: `${SECURITY_SOLUTION_DOCS}artifact-control.html`,
avcResults: `${ELASTIC_WEBSITE_URL}blog/elastic-security-malware-protection-test-av-comparatives`,
avcResults: `${ELASTIC_WEBSITE_URL}blog/elastic-av-comparatives-business-security-test`,
trustedApps: `${SECURITY_SOLUTION_DOCS}trusted-apps-ov.html`,
eventFilters: `${SECURITY_SOLUTION_DOCS}event-filters.html`,
blocklist: `${SECURITY_SOLUTION_DOCS}blocklist.html`,

View file

@ -22,7 +22,7 @@ import { FormattedMessage } from '@kbn/i18n-react';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { AVCResultsBanner2024 } from '@kbn/avc-banner';
import { AVCResultsBanner2024, useIsStillYear2024 } from '@kbn/avc-banner';
import {
isIntegrationPolicyTemplate,
@ -313,7 +313,7 @@ export const OverviewPage: React.FC<Props> = memo(
</SideBar>
<EuiFlexItem grow={9} className="eui-textBreakWord">
{isUnverified && <UnverifiedCallout />}
{isElasticDefend && showAVCBanner && (
{useIsStillYear2024() && isElasticDefend && showAVCBanner && (
<>
<AVCResultsBanner2024 onDismiss={onBannerDismiss} />
<EuiSpacer size="s" />

View file

@ -88,6 +88,13 @@ describe('OnboardingComponent', () => {
});
describe('AVC 2024 Results banner', () => {
beforeEach(() => {
(useKibana().services.storage.get as jest.Mock).mockReturnValue(true);
});
afterEach(() => {
jest.clearAllMocks();
jest.useRealTimers();
});
it('should render on the page', () => {
render();
expect(renderResult.getByTestId('avcResultsBanner')).toBeTruthy();
@ -97,7 +104,7 @@ describe('OnboardingComponent', () => {
render();
expect(renderResult.getByTestId('avcReadTheBlog')).toHaveAttribute(
'href',
'https://www.elastic.co/blog/elastic-security-malware-protection-test-av-comparatives'
'https://www.elastic.co/blog/elastic-av-comparatives-business-security-test'
);
});
@ -110,10 +117,23 @@ describe('OnboardingComponent', () => {
false
);
});
it('should stay dismissed if it has been closed once', () => {
(useKibana().services.storage.get as jest.Mock).mockReturnValue(false);
(useKibana().services.storage.get as jest.Mock).mockReturnValueOnce(false);
render();
expect(renderResult.queryByTestId('avcResultsBanner')).toBeNull();
});
it('should not be shown if the current date is January 1, 2025', () => {
jest.useFakeTimers().setSystemTime(new Date('2025-01-01T05:00:00.000Z'));
render();
expect(renderResult.queryByTestId('avcResultsBanner')).toBeNull();
jest.useRealTimers();
});
it('should be shown if the current date is before January 1, 2025', () => {
jest.useFakeTimers().setSystemTime(new Date('2024-12-31T05:00:00.000Z'));
render();
expect(renderResult.queryByTestId('avcResultsBanner')).toBeTruthy();
});
});
});

View file

@ -6,7 +6,7 @@
*/
import React, { useCallback, useMemo, useState } from 'react';
import { AVCResultsBanner2024 } from '@kbn/avc-banner';
import { AVCResultsBanner2024, useIsStillYear2024 } from '@kbn/avc-banner';
import { KibanaPageTemplate } from '@kbn/shared-ux-page-kibana-template';
import { TogglePanel } from './toggle_panel';
@ -91,7 +91,7 @@ export const OnboardingComponent: React.FC<OnboardingProps> = ({
return (
<div className={wrapperStyles}>
{showAVCBanner && (
{useIsStillYear2024() && showAVCBanner && (
<KibanaPageTemplate.Section paddingSize="none" className={bannerStyles}>
<AVCResultsBanner2024 onDismiss={onBannerDismiss} />
</KibanaPageTemplate.Section>