Skip to content

Commit

Permalink
[8.8] [Security Solution] Maintenance Window callout: Update tests to…
Browse files Browse the repository at this point in the history
… match the test plan (#156532) (#156727)

# Backport

This will backport the following commits from `main` to `8.8`:
- [[Security Solution] Maintenance Window callout: Update tests to match
the test plan (#156532)](#156532)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Nikita
Indik","email":"nikita.indik@elastic.co"},"sourceCommit":{"committedDate":"2023-05-04T08:07:42Z","message":"[Security
Solution] Maintenance Window callout: Update tests to match the test
plan (#156532)\n\n## Summary\r\n\r\nThis PR updates Maintenance Window
callout tests to match the test plan.\r\n\r\nMaintenance Window callout
is shown on the Rules Management page when\r\nthere's a Maintenance
Window running.\r\n\r\n<img width=\"1260\"
alt=\"233624339-9c9b6e3e-9e5e-424d-9d19-9cd7d4e92259\"\r\nsrc=\"https://user-images.githubusercontent.com/15949146/235923634-53113720-d58a-4a15-b66b-b2008f80f035.png\">\r\n\r\n[**Test
plan**\r\n(internal)](https://docs.google.com/document/d/1NTTbV7FemZR8LVwWBbDW3Jji58Wy2-n-YGycD698RR8/edit?usp=sharing\r\n)\r\n\r\n[**Maintenance
Window
Callout\r\nissue**](#155099)
with more info\r\nabout the
feature","sha":"508ab6521995eb044b16f6be15839d64de8c39e5","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["test","release_note:skip","test-coverage","Team:Detections
and Resp","Team: SecuritySolution","Feature:Rule
Management","Team:Detection
Rules","v8.8.0","v8.9.0"],"number":156532,"url":"https://github.com/elastic/kibana/pull/156532","mergeCommit":{"message":"[Security
Solution] Maintenance Window callout: Update tests to match the test
plan (#156532)\n\n## Summary\r\n\r\nThis PR updates Maintenance Window
callout tests to match the test plan.\r\n\r\nMaintenance Window callout
is shown on the Rules Management page when\r\nthere's a Maintenance
Window running.\r\n\r\n<img width=\"1260\"
alt=\"233624339-9c9b6e3e-9e5e-424d-9d19-9cd7d4e92259\"\r\nsrc=\"https://user-images.githubusercontent.com/15949146/235923634-53113720-d58a-4a15-b66b-b2008f80f035.png\">\r\n\r\n[**Test
plan**\r\n(internal)](https://docs.google.com/document/d/1NTTbV7FemZR8LVwWBbDW3Jji58Wy2-n-YGycD698RR8/edit?usp=sharing\r\n)\r\n\r\n[**Maintenance
Window
Callout\r\nissue**](#155099)
with more info\r\nabout the
feature","sha":"508ab6521995eb044b16f6be15839d64de8c39e5"}},"sourceBranch":"main","suggestedTargetBranches":["8.8"],"targetPullRequestStates":[{"branch":"8.8","label":"v8.8.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/156532","number":156532,"mergeCommit":{"message":"[Security
Solution] Maintenance Window callout: Update tests to match the test
plan (#156532)\n\n## Summary\r\n\r\nThis PR updates Maintenance Window
callout tests to match the test plan.\r\n\r\nMaintenance Window callout
is shown on the Rules Management page when\r\nthere's a Maintenance
Window running.\r\n\r\n<img width=\"1260\"
alt=\"233624339-9c9b6e3e-9e5e-424d-9d19-9cd7d4e92259\"\r\nsrc=\"https://user-images.githubusercontent.com/15949146/235923634-53113720-d58a-4a15-b66b-b2008f80f035.png\">\r\n\r\n[**Test
plan**\r\n(internal)](https://docs.google.com/document/d/1NTTbV7FemZR8LVwWBbDW3Jji58Wy2-n-YGycD698RR8/edit?usp=sharing\r\n)\r\n\r\n[**Maintenance
Window
Callout\r\nissue**](#155099)
with more info\r\nabout the
feature","sha":"508ab6521995eb044b16f6be15839d64de8c39e5"}}]}]
BACKPORT-->
  • Loading branch information
nikitaindik authored May 4, 2023
1 parent b27bcb8 commit f9f91d7
Showing 1 changed file with 41 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
MAINTENANCE_WINDOW_FEATURE_ID,
} from '@kbn/alerting-plugin/common';
import type { MaintenanceWindow } from '@kbn/alerting-plugin/common';
import type { AsApiContract } from '@kbn/alerting-plugin/server/routes/lib';
import { useKibana } from '../../../../common/lib/kibana';
import { useAppToasts } from '../../../../common/hooks/use_app_toasts';
import { useAppToastsMock } from '../../../../common/hooks/use_app_toasts.mock';
Expand All @@ -29,19 +30,38 @@ jest.mock('./api', () => ({
jest.mock('../../../../common/lib/kibana');

const RUNNING_MAINTENANCE_WINDOW_1: Partial<MaintenanceWindow> = {
title: 'Maintenance window 1',
title: 'Running maintenance window 1',
id: '63057284-ac31-42ba-fe22-adfe9732e5ae',
status: MaintenanceWindowStatus.Running,
events: [{ gte: '2023-04-20T16:27:30.753Z', lte: '2023-04-20T16:57:30.753Z' }],
};

const RUNNING_MAINTENANCE_WINDOW_2: Partial<MaintenanceWindow> = {
title: 'Maintenance window 2',
title: 'Running maintenance window 2',
id: '45894340-df98-11ed-ac81-bfcb4982b4fd',
status: MaintenanceWindowStatus.Running,
events: [{ gte: '2023-04-20T16:47:42.871Z', lte: '2023-04-20T17:11:32.192Z' }],
};

const RECURRING_RUNNING_MAINTENANCE_WINDOW: Partial<AsApiContract<MaintenanceWindow>> = {
title: 'Recurring running maintenance window',
id: 'e2228300-e9ad-11ed-ba37-db17c6e6182b',
status: MaintenanceWindowStatus.Running,
events: [
{ gte: '2023-05-03T12:27:18.569Z', lte: '2023-05-03T12:57:18.569Z' },
{ gte: '2023-05-10T12:27:18.569Z', lte: '2023-05-10T12:57:18.569Z' },
],
expiration_date: '2024-05-03T12:27:35.088Z',
r_rule: {
dtstart: '2023-05-03T12:27:18.569Z',
tzid: 'Europe/Amsterdam',
freq: 3,
interval: 1,
count: 2,
byweekday: ['WE'],
},
};

const UPCOMING_MAINTENANCE_WINDOW: Partial<MaintenanceWindow> = {
title: 'Upcoming maintenance window',
id: '5eafe070-e030-11ed-ac81-bfcb4982b4fd',
Expand Down Expand Up @@ -85,9 +105,10 @@ describe('MaintenanceWindowCallout', () => {
it('should be visible if currently there is at least one "running" maintenance window', async () => {
fetchActiveMaintenanceWindowsMock.mockResolvedValue([RUNNING_MAINTENANCE_WINDOW_1]);

const { findByText } = render(<MaintenanceWindowCallout />, { wrapper: TestProviders });
const { findAllByText } = render(<MaintenanceWindowCallout />, { wrapper: TestProviders });

expect(await findByText('A maintenance window is currently running')).toBeInTheDocument();
expect(await findAllByText('A maintenance window is currently running')).toHaveLength(1);
expect(fetchActiveMaintenanceWindowsMock).toHaveBeenCalledTimes(1);
});

it('should be visible if currently there are multiple "running" maintenance windows', async () => {
Expand All @@ -99,22 +120,36 @@ describe('MaintenanceWindowCallout', () => {
const { findAllByText } = render(<MaintenanceWindowCallout />, { wrapper: TestProviders });

expect(await findAllByText('A maintenance window is currently running')).toHaveLength(1);
expect(fetchActiveMaintenanceWindowsMock).toHaveBeenCalledTimes(1);
});

it('should be visible if currently there is a recurring "running" maintenance window', async () => {
fetchActiveMaintenanceWindowsMock.mockResolvedValue([RECURRING_RUNNING_MAINTENANCE_WINDOW]);

const { findByText } = render(<MaintenanceWindowCallout />, { wrapper: TestProviders });

expect(await findByText('A maintenance window is currently running')).toBeInTheDocument();
expect(fetchActiveMaintenanceWindowsMock).toHaveBeenCalledTimes(1);
});

it('should NOT be visible if currently there are no active (running or upcoming) maintenance windows', async () => {
fetchActiveMaintenanceWindowsMock.mockResolvedValue([]);
fetchActiveMaintenanceWindowsMock.mockResolvedValue(
[] // API returns an empty array if there are no active maintenance windows
);

const { container } = render(<MaintenanceWindowCallout />, { wrapper: TestProviders });

expect(container).toBeEmptyDOMElement();
expect(fetchActiveMaintenanceWindowsMock).toHaveBeenCalledTimes(1);
});

it('should NOT be visible if currently there are no "running" maintenance windows', async () => {
it('should NOT be visible if currently there are only "upcoming" maintenance windows', async () => {
fetchActiveMaintenanceWindowsMock.mockResolvedValue([UPCOMING_MAINTENANCE_WINDOW]);

const { container } = render(<MaintenanceWindowCallout />, { wrapper: TestProviders });

expect(container).toBeEmptyDOMElement();
expect(fetchActiveMaintenanceWindowsMock).toHaveBeenCalledTimes(1);
});

it('should see an error toast if there was an error while fetching maintenance windows', async () => {
Expand Down

0 comments on commit f9f91d7

Please sign in to comment.