-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
XavierM
merged 25 commits into
elastic:main
from
guskovaue:RAM-add-maintenance-window-banner
Aug 17, 2023
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
347b627
add maintenance banner
guskovaue ea966e5
func tests for rules list
guskovaue d41d601
fix rules list unit tests
guskovaue ee3a555
fix unit tests
guskovaue d762a53
Merge branch 'main' into RAM-add-maintenance-window-banner
guskovaue eb5c988
do unit test instead e2e
guskovaue 9c8b4e4
Merge branch 'RAM-add-maintenance-window-banner' of github.com:guskov…
guskovaue 7a89261
add specific jest test to make sure the window maintenance is showing up
XavierM b6a0131
started to write tests for alerts page in o11y
guskovaue bb65258
Merge branch 'RAM-add-maintenance-window-banner' of github.com:guskov…
guskovaue 9285d5c
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine b0fea1a
add test integration for window maintenance in o11y alerts
XavierM efb947b
fix eui theme
XavierM bc83b9f
Merge branch 'main' of github.com:elastic/kibana into RAM-add-mainten…
XavierM b68efcc
Merge branch 'main' into RAM-add-maintenance-window-banner
XavierM e694439
Merge branch 'main' into RAM-add-maintenance-window-banner
XavierM 8f71d67
Fix tests
JiaweiWu c60361e
Merge branch 'main' into RAM-add-maintenance-window-banner
kibanamachine cfcee29
Fix tests
JiaweiWu ffa44c8
Merge branch 'main' into RAM-add-maintenance-window-banner
kibanamachine 0f1cf7f
Merge branch 'main' into RAM-add-maintenance-window-banner
kibanamachine 74afa4b
Merge branch 'main' into RAM-add-maintenance-window-banner
kibanamachine c7fd4dd
Merge branch 'main' into RAM-add-maintenance-window-banner
XavierM 8412220
Merge branch 'main' into RAM-add-maintenance-window-banner
XavierM 17b8589
Merge branch 'main' into RAM-add-maintenance-window-banner
XavierM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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: { | ||
|
@@ -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 () => { | ||
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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Wouldn't it be better to use |
||
expect(fetchActiveMaintenanceWindowsMock).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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