Skip to content

Commit

Permalink
updated tests for <BidirectionalIntegrationsBanner>
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-tavares committed Jan 22, 2025
1 parent 0795c5b commit d7a3a11
Showing 1 changed file with 40 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
*/

import React from 'react';
import { type RenderResult } from '@testing-library/react';
import { type RenderResult, fireEvent, waitFor } from '@testing-library/react';

import type { FleetStartServices } from '../../../../../../..';

import { createFleetTestRendererMock } from '../../../../../../../mock';

Expand All @@ -18,33 +20,61 @@ import {
jest.mock('react-use/lib/useLocalStorage');

describe('BidirectionalIntegrationsBanner', () => {
let formProps: BidirectionalIntegrationsBannerProps;
let componentProps: BidirectionalIntegrationsBannerProps;
let renderResult: RenderResult;
let render: () => RenderResult;
let storageMock: jest.Mocked<FleetStartServices['storage']>;

beforeEach(() => {
formProps = {
onDismiss: jest.fn(),
};
componentProps = { integrationPackageName: 'sentinel_one' };

const testRunner = createFleetTestRendererMock();

const renderer = createFleetTestRendererMock();
storageMock = testRunner.startServices.storage;

renderResult = renderer.render(<BidirectionalIntegrationsBanner {...formProps} />);
render = () => {
renderResult = testRunner.render(<BidirectionalIntegrationsBanner {...componentProps} />);
return renderResult;
};
});

it('should render bidirectional integrations banner', () => {
render();
expect(renderResult.getByTestId('bidirectionalIntegrationsCallout')).toBeInTheDocument();
});

it('should contain a link to documentation', () => {
render();
const docLink = renderResult.getByTestId('bidirectionalIntegrationDocLink');

expect(docLink).toBeInTheDocument();
expect(docLink.getAttribute('href')).toContain('third-party-actions.html');
});

it('should call `onDismiss` callback when user clicks dismiss', () => {
renderResult.getByTestId('euiDismissCalloutButton').click();
it('should remove the callout when the dismiss button is clicked', async () => {
render();
fireEvent.click(renderResult.getByTestId('euiDismissCalloutButton'));

await waitFor(() => {
expect(storageMock.store.setItem).toHaveBeenCalledWith(
'fleet.showSOReponseSupportBanner',
'false'
);
expect(renderResult.queryByTestId('bidirectionalIntegrationsCallout')).toBeFalsy();
});
});

it('should render nothing if integration is not supported', () => {
componentProps.integrationPackageName = 'foo';
render();

expect(renderResult.queryByTestId('bidirectionalIntegrationsCallout')).toBeFalsy();
});

it('should render nothing if user had dismissed the callout in the past', () => {
(storageMock.store.getItem as jest.Mock).mockReturnValue('false');
render();

expect(formProps.onDismiss).toBeCalled();
expect(renderResult.queryByTestId('bidirectionalIntegrationsCallout')).toBeFalsy();
});
});

0 comments on commit d7a3a11

Please sign in to comment.