-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Cases] Add Generic Page attachment type for cases #224308
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
Closed
dominiqueclarke
wants to merge
27
commits into
elastic:main
from
dominiqueclarke:feat/cases-page-attachment
Closed
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
77d172f
add link attachment type
dominiqueclarke 3bcb4d4
[CI] Auto-commit changed files from 'node scripts/yarn_deduplicate'
kibanamachine bc5c03d
remove dashboard dependency from triggers actions ui
dominiqueclarke 192116f
Merge branch 'feat/cases-link-attachment' of github.com:dominiqueclar…
dominiqueclarke 8f3782f
Merge branch 'main' of https://github.com/elastic/kibana into feat/ca…
dominiqueclarke 0aeebda
integrate screenshot
benakansara 6037685
merge upstream
dominiqueclarke 5266320
adjust types
dominiqueclarke 14e8f82
[CI] Auto-commit changed files from 'node scripts/styled_components_m…
kibanamachine ac2ef57
quick checks
dominiqueclarke 22cc56a
Merge branch 'feat/cases-link-attachment' of github.com:dominiqueclar…
dominiqueclarke 9d0d253
remove unnecessary dashboard dependency
dominiqueclarke b45cdba
[CI] Auto-commit changed files from 'node scripts/styled_components_m…
kibanamachine 6d1c98b
split and merge screenshot images
benakansara 5bd0383
add actions
dominiqueclarke d28a975
merge upstream
dominiqueclarke e9818ad
remove screenshot functionality
dominiqueclarke b988b67
adjust rendered component
dominiqueclarke 6565e1b
adjust types and linting
dominiqueclarke 711442b
adjust types
dominiqueclarke ad3b528
adjust test
dominiqueclarke beb55d4
Merge branch 'main' of https://github.com/elastic/kibana into feat/ca…
dominiqueclarke f612f90
Merge branch 'main' into feat/cases-page-attachment
dominiqueclarke 072a087
adjust types
dominiqueclarke da1e7a7
Merge branch 'feat/cases-page-attachment' of github.com:dominiqueclar…
dominiqueclarke d81aec3
adjust tests
dominiqueclarke c7166c5
adjust types
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
227 changes: 227 additions & 0 deletions
227
.../shared/dashboard/public/dashboard_app/top_nav/cases/dashboard_add_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,227 @@ | ||
| /* | ||
| * 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
| * Public License v 1"; you may not use this file except in compliance with, at | ||
| * your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
| * License v3.0 only", or the "Server Side Public License, v 1". | ||
| */ | ||
|
|
||
| import React from 'react'; | ||
| import { render } from '@testing-library/react'; | ||
| import { AddToCaseModal } from './dashboard_add_to_case_modal'; | ||
| import { coreServices, cases, shareService } from '../../../services/kibana_services'; | ||
| import { DashboardContext } from '../../../dashboard_api/use_dashboard_api'; | ||
| import { DashboardInternalContext } from '../../../dashboard_api/use_dashboard_internal_api'; | ||
|
|
||
| import { buildMockDashboardApi } from '../../../mocks'; | ||
|
|
||
| jest.mock('../../../services/kibana_services', () => ({ | ||
| cases: { | ||
| ui: { | ||
| getCasesContext: jest.fn(() => ({ children }: any) => <>{children}</>), | ||
| }, | ||
| helpers: { | ||
| canUseCases: jest.fn(() => ({ | ||
| all: true, | ||
| create: true, | ||
| read: true, | ||
| update: true, | ||
| delete: true, | ||
| push: true, | ||
| connectors: true, | ||
| settings: true, | ||
| reopenCase: true, | ||
| createComment: true, | ||
| assign: true, | ||
| })), | ||
| }, | ||
| hooks: { | ||
| useCasesAddToExistingCaseModal: jest.fn(() => ({ | ||
| open: jest.fn(), | ||
| })), | ||
| }, | ||
| }, | ||
| shareService: { | ||
| url: { | ||
| locators: { | ||
| get: jest.fn(() => ({ | ||
| getRedirectUrl: jest.fn().mockImplementation(({ timeRange }) => { | ||
| return `/mock-redirect-url?from=${encodeURIComponent( | ||
| timeRange.from | ||
| )}&to=${encodeURIComponent(timeRange.to)}`; | ||
| }), | ||
| })), | ||
| }, | ||
| }, | ||
| }, | ||
| coreServices: { | ||
| notifications: { | ||
| toasts: { | ||
| addDanger: jest.fn(), | ||
| }, | ||
| }, | ||
| application: { | ||
| capabilities: { | ||
| dashboard_v2: { | ||
| save: true, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| dataService: { | ||
| query: { | ||
| timefilter: { | ||
| timefilter: { | ||
| getTime: jest.fn(() => ({ from: 'now-15m', to: 'now' })), | ||
| getRefreshInterval: jest.fn(() => ({ pause: true, value: 0 })), | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| })); | ||
|
|
||
| describe('AddToCaseModal', () => { | ||
| const { api: mockDashboardApi, internalApi } = buildMockDashboardApi({ | ||
| savedObjectId: 'mockSavedId', | ||
| overrides: { | ||
| timeRange: { from: 'now-15m', to: 'now' }, | ||
| }, | ||
| }); | ||
|
|
||
| const mockDate = new Date('2025-06-17T15:37:53.937Z'); | ||
| beforeAll(() => { | ||
| jest.useFakeTimers().setSystemTime(mockDate); | ||
| }); | ||
|
|
||
| afterAll(() => { | ||
| jest.useRealTimers(); | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| // @ts-ignore next line | ||
| shareService.url.locators.get = jest.fn(() => ({ | ||
| getRedirectUrl: jest.fn().mockImplementation(({ timeRange }) => { | ||
| return `/mock-redirect-url?from=${encodeURIComponent( | ||
| timeRange.from | ||
| )}&to=${encodeURIComponent(timeRange.to)}`; | ||
| }), | ||
| })); | ||
| }); | ||
|
|
||
| it('renders null if cases is not available', () => { | ||
| jest.mock('../../../services/kibana_services', () => ({ cases: null })); | ||
|
|
||
| const { container } = render( | ||
| <DashboardContext.Provider value={mockDashboardApi}> | ||
| <DashboardInternalContext.Provider value={internalApi}> | ||
| <AddToCaseModal isOpen={true} /> | ||
| </DashboardInternalContext.Provider> | ||
| </DashboardContext.Provider> | ||
| ); | ||
|
|
||
| expect(container.firstChild).toBeNull(); | ||
| }); | ||
|
|
||
| it('renders the modal when isOpen is true and required props are provided', () => { | ||
| const open = jest.fn(); | ||
| const casesMock = cases!; | ||
| jest.spyOn(casesMock.hooks, 'useCasesAddToExistingCaseModal').mockReturnValue({ | ||
| close: jest.fn(), | ||
| open, | ||
| }); | ||
| render( | ||
| <DashboardContext.Provider value={mockDashboardApi}> | ||
| <DashboardInternalContext.Provider value={internalApi}> | ||
| <AddToCaseModal isOpen={true} /> | ||
| </DashboardInternalContext.Provider> | ||
| </DashboardContext.Provider> | ||
| ); | ||
|
|
||
| expect(open).toBeCalledWith( | ||
| expect.objectContaining({ | ||
| getAttachments: expect.any(Function), | ||
| }) | ||
| ); | ||
|
|
||
| // Optionally, you can invoke the function and test its return value | ||
| const callArgs = open.mock.calls[0][0]; | ||
| expect(callArgs.getAttachments()).toEqual([ | ||
| { | ||
| persistableStateAttachmentTypeId: '.page', | ||
| type: 'persistableState', | ||
| persistableStateAttachmentState: { | ||
| type: 'dashboard', | ||
| url: { | ||
| iconType: 'dashboardApp', | ||
| pathAndQuery: | ||
| '/mock-redirect-url?from=2025-06-17T15%3A22%3A53.937Z&to=2025-06-17T15%3A37%3A53.937Z', | ||
| label: 'My Dashboard', | ||
| actionLabel: 'Go to dashboard', | ||
| }, | ||
| screenContext: null, | ||
| }, | ||
| }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('does not render the modal when isOpen is false', () => { | ||
| const { container } = render( | ||
| <DashboardContext.Provider value={mockDashboardApi}> | ||
| <DashboardInternalContext.Provider value={internalApi}> | ||
| <AddToCaseModal isOpen={false} /> | ||
| </DashboardInternalContext.Provider> | ||
| </DashboardContext.Provider> | ||
| ); | ||
|
|
||
| expect(container.firstChild).toBeNull(); | ||
| }); | ||
|
|
||
| it('shows a danger toast when the dashboard locator is not defined', () => { | ||
| shareService.url.locators.get = jest.fn(() => undefined); | ||
|
|
||
| render( | ||
| <DashboardContext.Provider value={mockDashboardApi}> | ||
| <DashboardInternalContext.Provider value={internalApi}> | ||
| <AddToCaseModal isOpen={true} /> | ||
| </DashboardInternalContext.Provider> | ||
| </DashboardContext.Provider> | ||
| ); | ||
|
|
||
| expect(coreServices.notifications.toasts.addDanger).toHaveBeenCalledWith({ | ||
| title: expect.any(String), | ||
| 'data-test-subj': 'dashboardAddToCaseError', | ||
| }); | ||
| }); | ||
|
|
||
| it('saves the time range in the URL as absolute time', () => { | ||
| const open = jest.fn(); | ||
| const casesMock = cases!; | ||
| jest.spyOn(casesMock.hooks, 'useCasesAddToExistingCaseModal').mockReturnValue({ | ||
| close: jest.fn(), | ||
| open, | ||
| }); | ||
|
|
||
| render( | ||
| <DashboardContext.Provider value={mockDashboardApi}> | ||
| <DashboardInternalContext.Provider value={internalApi}> | ||
| <AddToCaseModal isOpen={true} /> | ||
| </DashboardInternalContext.Provider> | ||
| </DashboardContext.Provider> | ||
| ); | ||
|
|
||
| expect(open).toBeCalledWith( | ||
| expect.objectContaining({ | ||
| getAttachments: expect.any(Function), | ||
| }) | ||
| ); | ||
|
|
||
| const callArgs = open.mock.calls[0][0]; | ||
| const attachmentState = callArgs.getAttachments()[0].persistableStateAttachmentState; | ||
|
|
||
| expect(attachmentState.url.pathAndQuery).toContain( | ||
| '/mock-redirect-url?from=2025-06-17T15%3A22%3A53.937Z&to=2025-06-17T15%3A37%3A53.937Z' | ||
| ); | ||
| }); | ||
| }); |
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.
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.
Needed to render the Add to Case modal