-
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
Confirmation Modal - show warning message when nothing has been changed in modal. #199523
Merged
+132
−7
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
198011f
label for enable disable on modal changed to match state of risk scor…
CAWilson94 4978729
update confirmation modal to use callout message when nothing is chan…
CAWilson94 a74f683
Merge branch 'elastic:main' into enable-modal
CAWilson94 54e0a9f
conditional render for euiCallout if no options selected
CAWilson94 4b3ff95
translations using correct type, non empty div on conditinal render, …
CAWilson94 bb3cd47
disable button when nothing selected, aria label added
CAWilson94 a1b63d0
testing for enablement modal added
CAWilson94 2a3a429
Merge branch 'main' into enable-modal
CAWilson94 873c3e4
Merge branch 'main' into enable-modal
CAWilson94 af30b19
Merge branch 'main' into enable-modal
CAWilson94 212fd23
Merge branch 'main' into enable-modal
CAWilson94 d7216d9
Merge branch 'main' into enable-modal
CAWilson94 7548c97
Merge branch 'main' into enable-modal
CAWilson94 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
89 changes: 89 additions & 0 deletions
89
...tion/public/entity_analytics/components/entity_store/components/enablement_modal.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,89 @@ | ||
/* | ||
* 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 { fireEvent, render, screen } from '@testing-library/react'; | ||
import { EntityStoreEnablementModal } from './enablement_modal'; | ||
import { useEntityEnginePrivileges } from '../hooks/use_entity_engine_privileges'; | ||
import { TestProviders } from '../../../../common/mock'; | ||
|
||
const mockToggle = jest.fn(); | ||
const mockEnableStore = jest.fn(() => jest.fn()); | ||
jest.mock('../hooks/use_entity_engine_privileges', () => ({ | ||
useEntityEnginePrivileges: jest.fn(), | ||
})); | ||
|
||
const defaultProps = { | ||
visible: true, | ||
toggle: mockToggle, | ||
enableStore: mockEnableStore, | ||
riskScore: { disabled: false, checked: false }, | ||
entityStore: { disabled: false, checked: false }, | ||
}; | ||
|
||
const renderComponent = (props = defaultProps) => { | ||
return render(<EntityStoreEnablementModal {...props} />, { wrapper: TestProviders }); | ||
}; | ||
|
||
describe('EntityStoreEnablementModal', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
(useEntityEnginePrivileges as jest.Mock).mockReturnValue({ | ||
data: { | ||
privileges: { | ||
elasticsearch: { | ||
index: {}, | ||
}, | ||
kibana: {}, | ||
}, | ||
}, | ||
isLoading: false, | ||
}); | ||
}); | ||
|
||
it('should render the modal when visible is true', () => { | ||
renderComponent(); | ||
expect(screen.getByRole('dialog')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should not render the modal when visible is false', () => { | ||
renderComponent({ ...defaultProps, visible: false }); | ||
expect(screen.queryByRole('dialog')).not.toBeInTheDocument(); | ||
}); | ||
|
||
it('should call toggle function when cancel button is clicked', () => { | ||
renderComponent(); | ||
fireEvent.click(screen.getByText('Cancel')); | ||
expect(mockToggle).toHaveBeenCalledWith(false); | ||
}); | ||
|
||
it('should call enableStore function when enable button is clicked', () => { | ||
renderComponent({ | ||
...defaultProps, | ||
riskScore: { ...defaultProps.riskScore, checked: true }, | ||
entityStore: { ...defaultProps.entityStore, checked: true }, | ||
}); | ||
fireEvent.click(screen.getByText('Enable')); | ||
expect(mockEnableStore).toHaveBeenCalledWith({ riskScore: true, entityStore: true }); | ||
}); | ||
|
||
it('should display proceed warning when no enablement options are selected', () => { | ||
renderComponent(); | ||
expect(screen.getByText('Please enable at least one option to proceed.')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should disable the enable button when enablementOptions are false', () => { | ||
renderComponent({ | ||
...defaultProps, | ||
riskScore: { ...defaultProps.riskScore, checked: false }, | ||
entityStore: { ...defaultProps.entityStore, checked: false }, | ||
}); | ||
|
||
const enableButton = screen.getByRole('button', { name: /Enable/i }); | ||
expect(enableButton).toBeDisabled(); | ||
}); | ||
}); |
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
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.
Not completely 100% on the contents of this required for the test