Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
angorayc committed Oct 10, 2024
1 parent 34e718b commit 55f82b4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,41 @@ import { render } from '@testing-library/react';
import React from 'react';
import { TestProviders } from '../../../../../../common/mock/test_providers';
import { AgentlessAvailableCallout } from './agentless_available_callout';
import * as consts from '../constants';
import { useKibana } from '../../../../../../common/lib/kibana';

interface MockedConsts {
AGENTLESS_LEARN_MORE_LINK: string | null;
}
jest.mock('../constants');
jest.mock('../../../../../../common/lib/kibana', () => ({
useKibana: jest.fn(),
}));

describe('AgentlessAvailableCallout', () => {
const mockUseKibana = useKibana as jest.Mock;
beforeEach(() => {
jest.clearAllMocks();
jest.mocked<MockedConsts>(consts).AGENTLESS_LEARN_MORE_LINK = 'https://www.elastic.co';
mockUseKibana.mockReturnValue({
services: {
docLinks: {
links: {
fleet: {
agentlessBlog: 'https://www.elastic.co/blog',
},
},
},
},
});
});

it('returns null if AGENTLESS_LEARN_MORE_LINK is null', () => {
jest.mocked<MockedConsts>(consts).AGENTLESS_LEARN_MORE_LINK = null;

it('returns null if agentlessBlog is null', () => {
mockUseKibana.mockReturnValue({
services: {
docLinks: {
links: {
fleet: {
agentlessBlog: null,
},
},
},
},
});
const { container } = render(<AgentlessAvailableCallout />, {
wrapper: TestProviders,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { FormattedMessage } from '@kbn/i18n-react';
import { EuiIcon, useEuiTheme } from '@elastic/eui';
import { css } from '@emotion/react';

import { useKibana } from '../../../../../../common/lib/kibana/kibana_react';
import { useKibana } from '../../../../../../common/lib/kibana';
import { LinkAnchor } from '../../../../../../common/components/links';
import { CardCallOut } from '../../common/card_callout';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { render, waitFor } from '@testing-library/react';
import { of } from 'rxjs';
import { IntegrationCardTopCallout } from './integration_card_top_callout';
import { useOnboardingService } from '../../../../../hooks/use_onboarding_service';
import * as consts from '../constants';
import { IntegrationTabId } from '../types';

jest.mock('../../../../../hooks/use_onboarding_service', () => ({
Expand All @@ -24,12 +23,10 @@ jest.mock('./endpoint_callout');
interface MockedConsts {
AGENTLESS_LEARN_MORE_LINK: string | null;
}
jest.mock('../constants');

describe('IntegrationCardTopCallout', () => {
beforeEach(() => {
jest.clearAllMocks();
jest.mocked<MockedConsts>(consts).AGENTLESS_LEARN_MORE_LINK = 'https://www.elastic.co';
});

test('renders EndpointCallout when endpoint tab selected and no integrations installed', async () => {
Expand Down Expand Up @@ -68,25 +65,6 @@ describe('IntegrationCardTopCallout', () => {
});
});

it('does not render AgentlessAvailableCallout if AGENTLESS_LEARN_MORE_LINK is null', async () => {
(useOnboardingService as jest.Mock).mockReturnValue({
isAgentlessAvailable$: of(true),
});
jest.mocked<MockedConsts>(consts).AGENTLESS_LEARN_MORE_LINK = null;

const { queryByTestId } = render(
<IntegrationCardTopCallout
installedIntegrationsCount={0}
isAgentRequired={false}
selectedTabId={IntegrationTabId.cloud}
/>
);

await waitFor(() => {
expect(queryByTestId('agentlessAvailableCallout')).not.toBeInTheDocument();
});
});

test('renders InstalledIntegrationsCallout when there are installed integrations', async () => {
(useOnboardingService as jest.Mock).mockReturnValue({
isAgentlessAvailable$: of(false),
Expand Down

0 comments on commit 55f82b4

Please sign in to comment.