forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RAM] Apply maintenance windows privilege to UI (elastic#156191)
## Summary We will have three scenarios with kibana privileges ### NONE Kibana privileges form maintenance window: <img width="680" alt="image" src="https://user-images.githubusercontent.com/189600/235188523-acaff7de-54d4-4991-a014-05c0f449738c.png"> `The expected result is to not see maintenance window at all` <img width="1481" alt="image" src="https://user-images.githubusercontent.com/189600/235188658-6a53b463-4856-42c7-916e-aa8e6d7e326b.png"> ### READ Kibana privileges form maintenance window: <img width="677" alt="image" src="https://user-images.githubusercontent.com/189600/235188908-623d32ac-39a7-484e-bd5c-f858e04d16b2.png"> `The expected result is to only see the table with window maintenance and you can not edit them` <img width="1487" alt="image" src="https://user-images.githubusercontent.com/189600/235189169-f71422bf-6394-4574-87fb-14c653ca1e79.png"> <img width="1484" alt="image" src="https://user-images.githubusercontent.com/189600/235192048-149519ba-0505-46e3-b737-2703560eb3d6.png"> ### ALL Kibana privileges form maintenance window: <img width="668" alt="image" src="https://user-images.githubusercontent.com/189600/235189384-e71d9138-221c-4024-91bb-2ae32da1bd3b.png"> `The expected result is to be able to create/edit/etc on any maintenance windows` <img width="1484" alt="image" src="https://user-images.githubusercontent.com/189600/235189974-e36c1e65-0586-4840-ace5-32caf06455c6.png"> <img width="1481" alt="image" src="https://user-images.githubusercontent.com/189600/235192269-0f8d1922-d48f-494c-9979-2288bf142286.png"> ### Checklist Delete any items that are not applicable to this PR. - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
aeded80
commit 3c9da2c
Showing
14 changed files
with
327 additions
and
42 deletions.
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
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
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
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
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
84 changes: 84 additions & 0 deletions
84
x-pack/plugins/alerting/public/pages/maintenance_windows/index.test.tsx
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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import React from 'react'; | ||
import { licensingMock } from '@kbn/licensing-plugin/public/mocks'; | ||
import type { Capabilities } from '@kbn/core-capabilities-common'; | ||
import { AppMockRenderer, createAppMockRenderer } from '../../lib/test_utils'; | ||
import { useFindMaintenanceWindows } from '../../hooks/use_find_maintenance_windows'; | ||
import { MaintenanceWindowsPage } from '.'; | ||
import { MAINTENANCE_WINDOW_FEATURE_ID } from '../../../common'; | ||
|
||
jest.mock('../../hooks/use_find_maintenance_windows', () => ({ | ||
useFindMaintenanceWindows: jest.fn(), | ||
})); | ||
|
||
describe('Maintenance windows page', () => { | ||
let appMockRenderer: AppMockRenderer; | ||
let license = licensingMock.createLicense({ | ||
license: { type: 'platinum' }, | ||
}); | ||
let capabilities: Capabilities = { | ||
[MAINTENANCE_WINDOW_FEATURE_ID]: { | ||
show: true, | ||
save: true, | ||
}, | ||
navLinks: {}, | ||
management: {}, | ||
catalogue: {}, | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
(useFindMaintenanceWindows as jest.Mock).mockReturnValue({ | ||
isLoading: false, | ||
maintenanceWindows: [], | ||
refetch: jest.fn(), | ||
}); | ||
license = licensingMock.createLicense({ | ||
license: { type: 'platinum' }, | ||
}); | ||
capabilities = { | ||
maintenanceWindow: { | ||
show: true, | ||
save: true, | ||
}, | ||
navLinks: {}, | ||
management: {}, | ||
catalogue: {}, | ||
}; | ||
appMockRenderer = createAppMockRenderer({ capabilities, license }); | ||
}); | ||
|
||
test('show license prompt', () => { | ||
license = licensingMock.createLicense({ | ||
license: { type: 'gold' }, | ||
}); | ||
appMockRenderer = createAppMockRenderer({ capabilities, license }); | ||
const result = appMockRenderer.render(<MaintenanceWindowsPage />); | ||
expect(result.queryByTestId('mw-license-prompt')).toBeInTheDocument(); | ||
}); | ||
|
||
test('show empty prompt', () => { | ||
const result = appMockRenderer.render(<MaintenanceWindowsPage />); | ||
expect(result.queryByTestId('mw-empty-prompt')).toBeInTheDocument(); | ||
expect(appMockRenderer.mocked.setBadge).not.toBeCalled(); | ||
}); | ||
|
||
test('show table in read only', () => { | ||
capabilities = { | ||
...capabilities, | ||
[MAINTENANCE_WINDOW_FEATURE_ID]: { | ||
show: true, | ||
save: false, | ||
}, | ||
}; | ||
appMockRenderer = createAppMockRenderer({ capabilities, license }); | ||
const result = appMockRenderer.render(<MaintenanceWindowsPage />); | ||
expect(result.queryByTestId('mw-table')).toBeInTheDocument(); | ||
expect(appMockRenderer.mocked.setBadge).toBeCalledTimes(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
Oops, something went wrong.