Skip to content

Commit

Permalink
add unit test for persisting that banner has been dismissed
Browse files Browse the repository at this point in the history
  • Loading branch information
gergoabraham committed Oct 9, 2024
1 parent 5f7ca44 commit 7afb218
Showing 1 changed file with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type { PolicyConfig } from '../../../../../../common/endpoint/types';
import { AntivirusRegistrationModes } from '../../../../../../common/endpoint/types';
import userEvent from '@testing-library/user-event';
import { cloneDeep } from 'lodash';
import type { IStorageWrapper } from '@kbn/kibana-utils-plugin/public';

jest.mock('../../../../../common/hooks/use_license');

Expand All @@ -33,11 +34,13 @@ describe('Endpoint Policy Settings Form', () => {
let render: () => ReturnType<AppContextTestRender['render']>;
let renderResult: ReturnType<typeof render>;
let upsellingService: UpsellingService;
let storageMock: IStorageWrapper;

beforeEach(() => {
const mockedContext = createAppRootMockRenderer();

upsellingService = mockedContext.startServices.upselling;
storageMock = mockedContext.startServices.storage;

formProps = {
policy: new FleetPackagePolicyGenerator('seed').generateEndpointPackagePolicy().inputs[0]
Expand All @@ -50,15 +53,43 @@ describe('Endpoint Policy Settings Form', () => {
render = () => (renderResult = mockedContext.render(<PolicySettingsForm {...formProps} />));
});

it('should show the event merging banner for 8.16', () => {
render();
expect(renderResult.getByTestId('eventMergingCallout')).toBeTruthy();
});
describe('event merging banner', () => {
it('should show the event merging banner for 8.16 if it has never been dismissed', () => {
render();

it('should not show the event merging banner after it has been dismissed', () => {
render();
renderResult.getByTestId('euiDismissCalloutButton').click();
expect(renderResult.queryByTestId('eventMergingCallout')).toBeNull();
expect(renderResult.getByTestId('eventMergingCallout')).toBeInTheDocument();
});

it('should show the event merging banner for 8.16 if `securitySolution.showEventMergingBanner` is `true`', () => {
storageMock.set('securitySolution.showEventMergingBanner', true);
render();

expect(renderResult.getByTestId('eventMergingCallout')).toBeInTheDocument();
});

it('should hide the event merging banner when user dismisses it', () => {
render();
expect(renderResult.getByTestId('eventMergingCallout')).toBeInTheDocument();

renderResult.getByTestId('euiDismissCalloutButton').click();

expect(renderResult.queryByTestId('eventMergingCallout')).not.toBeInTheDocument();
});

it('should persist that event merging banner have been dismissed', () => {
render();

renderResult.getByTestId('euiDismissCalloutButton').click();

expect(storageMock.get('securitySolution.showEventMergingBanner')).toBe(false);
});

it('should not show the banner if it was dismissed before', () => {
storageMock.set('securitySolution.showEventMergingBanner', false);
render();

expect(renderResult.queryByTestId('eventMergingCallout')).not.toBeInTheDocument();
});
});

it.each([
Expand Down Expand Up @@ -102,7 +133,7 @@ describe('Endpoint Policy Settings Form', () => {
])('should include %s card', (_, testSubjSelector) => {
render();

expect(renderResult.queryByTestId(testSubjSelector)).toBeNull();
expect(renderResult.queryByTestId(testSubjSelector)).not.toBeInTheDocument();
});

it('should display upselling component', () => {
Expand Down

0 comments on commit 7afb218

Please sign in to comment.