-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Incident Management] Add page attachment modal #231186
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
Merged
dominiqueclarke
merged 41 commits into
elastic:main
from
dominiqueclarke:feat/observability-page-attachment-modal
Aug 19, 2025
Merged
Changes from 14 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
9b0da85
parent 6f8bb908bc1eac2679f8bb0aa063b881de4f86c2
dominiqueclarke 10fd7c5
adjust yarn.lock
dominiqueclarke 4853346
adjust test
dominiqueclarke 64d92f8
adjust bundles
dominiqueclarke a27687a
remove unused hook
dominiqueclarke b64d218
remove unused types
dominiqueclarke 6ace322
fixed bug to prevent error when reopening modal
dominiqueclarke ebeb653
Merge branch 'main' into feat/observability-page-attachment-modal
dominiqueclarke 9ff8f03
[CI] Auto-commit changed files from 'ts-node .buildkite/pipeline-reso…
kibanamachine bc84ba6
adjust test
dominiqueclarke 6a4c663
Merge branch 'feat/observability-page-attachment-modal' of github.com…
dominiqueclarke 89b4e54
[CI] Auto-commit changed files from 'security: 3rd-party dependencies'
kibanamachine 26fca0b
update tests
dominiqueclarke 2dcd67c
Merge branch 'feat/observability-page-attachment-modal' of github.com…
dominiqueclarke 201e83d
Update x-pack/solutions/observability/plugins/observability_shared/pu…
dominiqueclarke ca168f2
Update x-pack/solutions/observability/plugins/observability_shared/pu…
dominiqueclarke 3d0f490
Update x-pack/solutions/observability/plugins/observability_shared/pu…
dominiqueclarke 4761367
[CI] Auto-commit changed files from 'node scripts/eslint_all_files --…
kibanamachine 2bcb725
Update x-pack/solutions/observability/plugins/observability_shared/pu…
dominiqueclarke 570e140
add dynamic import
dominiqueclarke acfd082
return empty page state if monitor.name or redirectUrl is undefined
dominiqueclarke 0253d48
adjust converting to absolute time
dominiqueclarke 925f3b2
[CI] Auto-commit changed files from 'security: 3rd-party dependencies'
kibanamachine dcf387c
Merge branch 'main' into feat/observability-page-attachment-modal
dominiqueclarke aaf721a
adjust conflict
dominiqueclarke 93ddd65
Merge branch 'feat/observability-page-attachment-modal' of github.com…
dominiqueclarke b9a9292
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine 7ad8159
Merge branch 'feat/observability-page-attachment-modal' of github.com…
dominiqueclarke 3b27554
[CI] Auto-commit changed files from 'node scripts/eslint_all_files --…
kibanamachine e1c3a97
adjust types
dominiqueclarke 810a135
adjust onClose
dominiqueclarke 15217db
Merge branch 'feat/observability-page-attachment-modal' of github.com…
dominiqueclarke 9018ff7
adjust test
dominiqueclarke 4b9a7ee
Update x-pack/solutions/observability/plugins/synthetics/kibana.jsonc
dominiqueclarke 3b85c8b
Update x-pack/solutions/observability/plugins/observability_shared/ki…
dominiqueclarke 19f7914
adjust test
dominiqueclarke 5ae4e32
Merge branch 'feat/observability-page-attachment-modal' of github.com…
dominiqueclarke 8694eec
adjust yarn.lock
dominiqueclarke aadf817
merge upstream
dominiqueclarke bf14dbc
adjust yarn.lock
dominiqueclarke df00725
remove notifications
dominiqueclarke 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ | |
| "data", | ||
| "inspector", | ||
| "kibanaReact", | ||
| "kibanaUtils" | ||
| "kibanaUtils", | ||
| ], | ||
| "extraPublicDirs": [ | ||
| "common" | ||
|
|
||
230 changes: 230 additions & 0 deletions
230
...c/components/add_page_attachment_to_case_modal/add_page_attachment_to_case_modal.test.tsx
This file contains hidden or 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,230 @@ | ||
| /* | ||
| * 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 { render, screen, fireEvent } from '@testing-library/react'; | ||
| import { __IntlProvider as IntlProvider } from '@kbn/i18n-react'; | ||
| import { PageAttachmentPersistedState } from '@kbn/page-attachment-schema'; | ||
| import { CasesPublicStart } from '@kbn/cases-plugin/public'; | ||
| import { mockCasesContract } from '@kbn/cases-plugin/public/mocks'; | ||
| import { notificationServiceMock } from '@kbn/core-notifications-browser-mocks'; | ||
| import { AddPageAttachmentToCaseModal } from './add_page_attachment_to_case_modal'; | ||
|
|
||
| const mockCases: Partial<CasesPublicStart> = mockCasesContract(); | ||
|
|
||
| describe('AddPageAttachmentToCaseModal', () => { | ||
| const notifications = notificationServiceMock.createStartContract(); | ||
| const pageAttachmentState: PageAttachmentPersistedState = { | ||
| type: 'example', | ||
| url: { | ||
| pathAndQuery: 'http://example.com', | ||
| actionLabel: 'Go to Example Page', | ||
| label: 'Example Page', | ||
| iconType: 'globe', | ||
| }, | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
|
|
||
| mockCases.helpers = { | ||
| canUseCases: jest.fn().mockReturnValue({ | ||
| read: true, | ||
| update: true, | ||
| push: true, | ||
| all: true, | ||
| create: true, | ||
| delete: true, | ||
| get: true, | ||
| connectors: true, | ||
| reopenCase: true, | ||
| settings: true, | ||
| createComment: true, | ||
| getCaseUserActions: true, | ||
| assign: true, | ||
| }), | ||
| getUICapabilities: jest.fn().mockReturnValue({}), | ||
| getRuleIdFromEvent: jest.fn().mockReturnValue({}), | ||
| groupAlertsByRule: jest.fn().mockReturnValue({}), | ||
| }; | ||
| }); | ||
|
|
||
| it('renders modal when user has permissions', () => { | ||
| mockCases.helpers!.canUseCases = jest.fn().mockImplementationOnce(() => ({ | ||
| read: true, | ||
| update: true, | ||
| push: true, | ||
| })); | ||
|
|
||
| render( | ||
| <IntlProvider locale="en"> | ||
| <AddPageAttachmentToCaseModal | ||
| pageAttachmentState={pageAttachmentState} | ||
| cases={mockCases as CasesPublicStart} | ||
| onCloseModal={jest.fn()} | ||
| notifications={notifications} | ||
| /> | ||
| </IntlProvider> | ||
| ); | ||
|
|
||
| expect(screen.getByText('Add page to case')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('does not render modal when user lacks permissions', () => { | ||
| mockCases.helpers!.canUseCases = jest.fn().mockImplementationOnce(() => ({ | ||
| read: true, | ||
| update: true, | ||
| push: false, | ||
| })); | ||
|
|
||
| render( | ||
| <AddPageAttachmentToCaseModal | ||
| pageAttachmentState={pageAttachmentState} | ||
| cases={mockCases as CasesPublicStart} | ||
| onCloseModal={jest.fn()} | ||
| notifications={notifications} | ||
| /> | ||
| ); | ||
|
|
||
| expect(screen.queryByText('Add page to case')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('calls onCloseModal when cancel button is clicked', () => { | ||
| const onCloseModalMock = jest.fn(); | ||
|
|
||
| render( | ||
| <IntlProvider locale="en"> | ||
| <AddPageAttachmentToCaseModal | ||
| pageAttachmentState={pageAttachmentState} | ||
| cases={mockCases as CasesPublicStart} | ||
| onCloseModal={onCloseModalMock} | ||
| notifications={notifications} | ||
| /> | ||
| </IntlProvider> | ||
| ); | ||
|
|
||
| fireEvent.click(screen.getByText('Cancel')); | ||
| expect(onCloseModalMock).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('opens case modal when confirm button is clicked', () => { | ||
| const mockCasesModal = { | ||
| open: jest.fn(), | ||
| close: jest.fn(), | ||
| }; | ||
| mockCases.hooks!.useCasesAddToExistingCaseModal = jest.fn(() => mockCasesModal); | ||
| render( | ||
| <IntlProvider locale="en"> | ||
| <AddPageAttachmentToCaseModal | ||
| pageAttachmentState={pageAttachmentState} | ||
| cases={mockCases as CasesPublicStart} | ||
| onCloseModal={jest.fn()} | ||
| notifications={notifications} | ||
| /> | ||
| </IntlProvider> | ||
| ); | ||
|
|
||
| fireEvent.click(screen.getByText('Confirm')); | ||
| expect(mockCasesModal.open).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('passes correct getAttachments payload when case modal is opened', () => { | ||
| const mockCasesModal = { | ||
| open: jest.fn(), | ||
| close: jest.fn(), | ||
| }; | ||
| mockCases.hooks!.useCasesAddToExistingCaseModal = jest.fn(() => mockCasesModal); | ||
| const comment = 'Test comment'; | ||
|
|
||
| render( | ||
| <IntlProvider locale="en"> | ||
| <AddPageAttachmentToCaseModal | ||
| pageAttachmentState={pageAttachmentState} | ||
| cases={mockCases as CasesPublicStart} | ||
| onCloseModal={jest.fn()} | ||
| notifications={notifications} | ||
| /> | ||
| </IntlProvider> | ||
| ); | ||
|
|
||
| fireEvent.change(screen.getByRole('textbox'), { target: { value: comment } }); | ||
| fireEvent.click(screen.getByText('Confirm')); | ||
|
|
||
| expect(mockCasesModal!.open).toHaveBeenCalledWith({ | ||
| getAttachments: expect.any(Function), | ||
| }); | ||
|
|
||
| const attachments = mockCasesModal!.open.mock.calls[0][0].getAttachments(); | ||
| expect(attachments).toEqual([ | ||
| { | ||
| persistableStateAttachmentState: { | ||
| ...pageAttachmentState, | ||
| summary: comment, | ||
| }, | ||
| persistableStateAttachmentTypeId: '.page', | ||
| type: 'persistableState', | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('can update the summary comment', () => { | ||
| const mockCasesModal = { | ||
| open: jest.fn(), | ||
| close: jest.fn(), | ||
| }; | ||
| mockCases.hooks!.useCasesAddToExistingCaseModal = jest.fn(() => mockCasesModal); | ||
| const comment = 'Test comment'; | ||
| render( | ||
| <IntlProvider locale="en"> | ||
| <AddPageAttachmentToCaseModal | ||
| pageAttachmentState={pageAttachmentState} | ||
| cases={mockCases as CasesPublicStart} | ||
| onCloseModal={jest.fn()} | ||
| notifications={notifications} | ||
| /> | ||
| </IntlProvider> | ||
| ); | ||
| fireEvent.change(screen.getByRole('textbox'), { target: { value: comment } }); | ||
| fireEvent.click(screen.getByText('Confirm')); | ||
| expect(mockCasesModal!.open).toHaveBeenCalledWith({ | ||
| getAttachments: expect.any(Function), | ||
| }); | ||
| const attachments = mockCasesModal!.open.mock.calls[0][0].getAttachments(); | ||
| expect(attachments).toEqual([ | ||
| { | ||
| persistableStateAttachmentState: { | ||
| ...pageAttachmentState, | ||
| summary: comment, | ||
| }, | ||
| persistableStateAttachmentTypeId: '.page', | ||
| type: 'persistableState', | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('should trigger a warning toast if hasCasesPermissions is false', () => { | ||
| const addWarningMock = jest.spyOn(notifications.toasts, 'addWarning'); | ||
| mockCases.helpers!.canUseCases = jest.fn().mockImplementationOnce(() => ({ | ||
| read: true, | ||
| update: true, | ||
| push: false, | ||
| })); | ||
|
|
||
| render( | ||
| <AddPageAttachmentToCaseModal | ||
| pageAttachmentState={{} as any} | ||
| cases={mockCases as any} | ||
| notifications={notifications} | ||
| onCloseModal={jest.fn()} | ||
| /> | ||
| ); | ||
|
|
||
| expect(addWarningMock).toHaveBeenCalledWith({ | ||
| title: expect.stringContaining('Insufficient privileges to add page to case'), | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.