Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RAM] add maintenance window banner #163516

Merged
merged 25 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
347b627
add maintenance banner
guskovaue Aug 9, 2023
ea966e5
func tests for rules list
guskovaue Aug 9, 2023
d41d601
fix rules list unit tests
guskovaue Aug 10, 2023
ee3a555
fix unit tests
guskovaue Aug 10, 2023
d762a53
Merge branch 'main' into RAM-add-maintenance-window-banner
guskovaue Aug 10, 2023
eb5c988
do unit test instead e2e
guskovaue Aug 11, 2023
9c8b4e4
Merge branch 'RAM-add-maintenance-window-banner' of github.com:guskov…
guskovaue Aug 11, 2023
7a89261
add specific jest test to make sure the window maintenance is showing up
XavierM Aug 11, 2023
b6a0131
started to write tests for alerts page in o11y
guskovaue Aug 11, 2023
bb65258
Merge branch 'RAM-add-maintenance-window-banner' of github.com:guskov…
guskovaue Aug 11, 2023
9285d5c
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Aug 11, 2023
b0fea1a
add test integration for window maintenance in o11y alerts
XavierM Aug 14, 2023
efb947b
fix eui theme
XavierM Aug 15, 2023
bc83b9f
Merge branch 'main' of github.com:elastic/kibana into RAM-add-mainten…
XavierM Aug 15, 2023
b68efcc
Merge branch 'main' into RAM-add-maintenance-window-banner
XavierM Aug 15, 2023
e694439
Merge branch 'main' into RAM-add-maintenance-window-banner
XavierM Aug 15, 2023
8f71d67
Fix tests
JiaweiWu Aug 15, 2023
c60361e
Merge branch 'main' into RAM-add-maintenance-window-banner
kibanamachine Aug 15, 2023
cfcee29
Fix tests
JiaweiWu Aug 15, 2023
ffa44c8
Merge branch 'main' into RAM-add-maintenance-window-banner
kibanamachine Aug 15, 2023
0f1cf7f
Merge branch 'main' into RAM-add-maintenance-window-banner
kibanamachine Aug 15, 2023
74afa4b
Merge branch 'main' into RAM-add-maintenance-window-banner
kibanamachine Aug 15, 2023
c7fd4dd
Merge branch 'main' into RAM-add-maintenance-window-banner
XavierM Aug 16, 2023
8412220
Merge branch 'main' into RAM-add-maintenance-window-banner
XavierM Aug 16, 2023
17b8589
Merge branch 'main' into RAM-add-maintenance-window-banner
XavierM Aug 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 98 additions & 9 deletions x-pack/plugins/observability/public/pages/alerts/alerts.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,34 @@
*/

import React from 'react';
import { render } from '@testing-library/react';
import { act, render } from '@testing-library/react';
import { CoreStart } from '@kbn/core/public';
import { AppMountParameters } from '@kbn/core/public';
import { TimeBuckets } from '@kbn/data-plugin/common';
import { fetchActiveMaintenanceWindows } from '@kbn/alerts-ui-shared/src/maintenance_window_callout/api';
import { RUNNING_MAINTENANCE_WINDOW_1 } from '@kbn/alerts-ui-shared/src/maintenance_window_callout/mock';
import { KibanaPageTemplate } from '@kbn/shared-ux-page-kibana-template';
import { __IntlProvider as IntlProvider } from '@kbn/i18n-react';
import { MAINTENANCE_WINDOW_FEATURE_ID } from '@kbn/alerting-plugin/common/maintenance_window';

import { ObservabilityPublicPluginsStart } from '../../plugin';
import { AlertsPage } from './alerts';
import { kibanaStartMock } from '../../utils/kibana_react.mock';
import * as pluginContext from '../../hooks/use_plugin_context';
import { KibanaPageTemplate } from '@kbn/shared-ux-page-kibana-template';
import * as dataContext from '../../hooks/use_has_data';
import { createObservabilityRuleTypeRegistryMock } from '../../rules/observability_rule_type_registry_mock';
import { AppMountParameters } from '@kbn/core/public';
import { ThemeProvider } from '@emotion/react';
import { euiDarkVars } from '@kbn/ui-theme';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';

const mockUseKibanaReturnValue = kibanaStartMock.startContract();
mockUseKibanaReturnValue.services.application.capabilities = {
...mockUseKibanaReturnValue.services.application.capabilities,
[MAINTENANCE_WINDOW_FEATURE_ID]: {
save: true,
show: true,
},
};

jest.mock('../../utils/kibana_react', () => ({
__esModule: true,
Expand All @@ -27,9 +44,6 @@ jest.mock('@kbn/kibana-react-plugin/public', () => ({
useKibana: jest.fn(() => mockUseKibanaReturnValue),
}));
jest.mock('@kbn/observability-shared-plugin/public');
jest.mock('@kbn/triggers-actions-ui-plugin/public', () => ({
useLoadRuleTypes: jest.fn(),
}));
jest.spyOn(pluginContext, 'usePluginContext').mockImplementation(() => ({
appMountParameters: {} as AppMountParameters,
config: {
Expand Down Expand Up @@ -59,15 +73,90 @@ jest.spyOn(pluginContext, 'usePluginContext').mockImplementation(() => ({
kibanaFeatures: [],
core: {} as CoreStart,
plugins: {} as ObservabilityPublicPluginsStart,
hasAnyData: true,
isAllRequestsComplete: true,
}));

jest.spyOn(dataContext, 'useHasData').mockImplementation(() => ({
hasDataMap: {},
hasAnyData: true,
isAllRequestsComplete: true,
onRefreshTimeRange: jest.fn(),
forceUpdate: 'false',
}));

jest.mock('@kbn/alerts-ui-shared/src/maintenance_window_callout/api', () => ({
fetchActiveMaintenanceWindows: jest.fn(() => Promise.resolve([])),
}));
const fetchActiveMaintenanceWindowsMock = fetchActiveMaintenanceWindows as jest.Mock;

jest.mock('../../hooks/use_time_buckets', () => ({
useTimeBuckets: jest.fn(),
}));
const { useTimeBuckets } = jest.requireMock('../../hooks/use_time_buckets');

const queryClient = new QueryClient({
defaultOptions: {
queries: {
retry: false,
cacheTime: 0,
},
},
});
function AllTheProviders({ children }: { children: any }) {
return (
<ThemeProvider
theme={() => ({ eui: { ...euiDarkVars, euiColorLightShade: '#ece' }, darkMode: true })}
>
<IntlProvider locale="en">
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
</IntlProvider>
</ThemeProvider>
);
}

describe('AlertsPage with all capabilities', () => {
const timeBuckets = new TimeBuckets({
'histogram:maxBars': 12,
'histogram:barTarget': 10,
dateFormat: 'MMM D, YYYY @ HH:mm:ss.SSS',
'dateFormat:scaled': [
['', 'HH:mm:ss.SSS'],
['PT1S', 'HH:mm:ss'],
['PT1M', 'HH:mm'],
['PT1H', 'YYYY-MM-DD HH:mm'],
['P1DT', 'YYYY-MM-DD'],
['P1YT', 'YYYY'],
],
});

async function setup() {
return render(<AlertsPage />);
return render(<AlertsPage />, { wrapper: AllTheProviders });
}

beforeAll(() => {
fetchActiveMaintenanceWindowsMock.mockResolvedValue([]);
});

beforeEach(() => {
fetchActiveMaintenanceWindowsMock.mockClear();
useTimeBuckets.mockReturnValue(timeBuckets);
});

it('should render an alerts page template', async () => {
const wrapper = await setup();
expect(wrapper.getByTestId('alertsPage')).toBeInTheDocument();
await act(async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's weird you need act here, maybe when can get through why you needed it when I come back

const wrapper = await setup();
expect(wrapper.queryByText('Alerts')).toBeInTheDocument();
});
});

it('renders MaintenanceWindowCallout if one exists', async () => {
fetchActiveMaintenanceWindowsMock.mockResolvedValue([RUNNING_MAINTENANCE_WINDOW_1]);

await act(async () => {
const wrapper = await setup();
expect(await wrapper.findByText('Maintenance window is running')).toBeInTheDocument();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Wouldn't it be better to use data-test-subj instead of finding an element with text?

expect(fetchActiveMaintenanceWindowsMock).toHaveBeenCalledTimes(1);
});
});
});
8 changes: 5 additions & 3 deletions x-pack/plugins/observability/public/plugin.mock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
*/
import React from 'react';
import { mockCasesContract } from '@kbn/cases-plugin/public/mocks';
import { timefilterServiceMock } from '@kbn/data-plugin/public/query/timefilter/timefilter_service.mock';

const triggersActionsUiStartMock = {
createStart() {
return {
getAlertSummaryWidget: jest.fn(() => (
<div data-test-subj="alerts-summary-widget">mocked component</div>
)),
getAlertsSearchBar: jest.fn(() => (
<div data-test-subj="alerts-search-bar">mocked component</div>
)),
Expand Down Expand Up @@ -67,9 +71,7 @@ const data = {
create: jest.fn(),
},
query: {
timefilter: {
timefilter: jest.fn(),
},
timefilter: timefilterServiceMock.createSetupContract(),
},
search: {
searchSource: {
Expand Down