-
Notifications
You must be signed in to change notification settings - Fork 421
RI-7431: fix key details header layout and rework confirmation popover #4971
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
ArtemHoruzhenko
merged 3 commits into
main
from
fe/feature/RI-7431-fix-key-deatils-header-and-confirmation-popover
Sep 18, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
217 changes: 217 additions & 0 deletions
217
redisinsight/ui/src/components/confirmation-popover/ConfirmationPopover.spec.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,217 @@ | ||
| import React from 'react' | ||
| import { render, screen, fireEvent } from 'uiSrc/utils/test-utils' | ||
| import ConfirmationPopover, { ConfirmationPopoverProps } from './ConfirmationPopover' | ||
|
|
||
| const mockClosePopover = jest.fn() | ||
| const mockButtonClick = jest.fn() | ||
|
|
||
| const defaultProps: ConfirmationPopoverProps = { | ||
| isOpen: true, | ||
| closePopover: mockClosePopover, | ||
| button: <button data-testid="trigger-button">Trigger</button>, | ||
| confirmButton: ( | ||
| <button data-testid="confirm-button" onClick={mockButtonClick}> | ||
| Confirm | ||
| </button> | ||
| ), | ||
| } | ||
|
|
||
| const renderConfirmationPopover = (props: Partial<ConfirmationPopoverProps> = {}) => { | ||
| return render(<ConfirmationPopover {...defaultProps} {...props} />) | ||
| } | ||
|
|
||
| describe('ConfirmationPopover', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks() | ||
| }) | ||
|
|
||
| describe('Basic Rendering', () => { | ||
| it('should render with required props only', () => { | ||
| renderConfirmationPopover() | ||
|
|
||
| expect(screen.getByTestId('trigger-button')).toBeInTheDocument() | ||
| expect(screen.getByTestId('confirm-button')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('should render the confirm button', () => { | ||
| renderConfirmationPopover() | ||
|
|
||
| const confirmButton = screen.getByTestId('confirm-button') | ||
| expect(confirmButton).toBeInTheDocument() | ||
| expect(confirmButton).toHaveTextContent('Confirm') | ||
| }) | ||
|
|
||
| it('should not render title when not provided', () => { | ||
| renderConfirmationPopover() | ||
|
|
||
| expect(screen.queryByRole('heading')).not.toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('should not render message when not provided', () => { | ||
| renderConfirmationPopover() | ||
|
|
||
| expect(screen.queryByText(/message/i)).not.toBeInTheDocument() | ||
| }) | ||
| }) | ||
|
|
||
| describe('Optional Props', () => { | ||
| it('should render title when provided', () => { | ||
| const title = 'Confirmation Required' | ||
| renderConfirmationPopover({ title }) | ||
|
|
||
| expect(screen.getByText(title)).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('should render message when provided', () => { | ||
| const message = 'Are you sure you want to proceed?' | ||
| renderConfirmationPopover({ message }) | ||
|
|
||
| expect(screen.getByText(message)).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('should render both title and message when provided', () => { | ||
| const title = 'Delete Item' | ||
| const message = 'This action cannot be undone.' | ||
| renderConfirmationPopover({ title, message }) | ||
|
|
||
| expect(screen.getByText(title)).toBeInTheDocument() | ||
| expect(screen.getByText(message)).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('should render with custom confirm button', () => { | ||
| const customConfirmButton = ( | ||
| <button data-testid="custom-confirm" className="custom-class"> | ||
| Delete Forever | ||
| </button> | ||
| ) | ||
| renderConfirmationPopover({ confirmButton: customConfirmButton }) | ||
|
|
||
| const customButton = screen.getByTestId('custom-confirm') | ||
| expect(customButton).toBeInTheDocument() | ||
| expect(customButton).toHaveTextContent('Delete Forever') | ||
| expect(customButton).toHaveClass('custom-class') | ||
| }) | ||
| }) | ||
|
|
||
| describe('RiPopover Integration', () => { | ||
| it('should pass through isOpen prop to RiPopover', () => { | ||
| const { rerender } = renderConfirmationPopover({ isOpen: false }) | ||
|
|
||
| expect(screen.queryByTestId('confirm-button')).not.toBeInTheDocument() | ||
| rerender(<ConfirmationPopover {...defaultProps} isOpen={true} />) | ||
| expect(screen.getByTestId('confirm-button')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('should pass through closePopover prop to RiPopover', () => { | ||
| renderConfirmationPopover() | ||
|
|
||
| fireEvent.click(document.body) | ||
| }) | ||
|
|
||
| it('should pass through button prop to RiPopover', () => { | ||
| const customButton = <button data-testid="custom-trigger">Custom Trigger</button> | ||
| renderConfirmationPopover({ button: customButton }) | ||
|
|
||
| expect(screen.getByTestId('custom-trigger')).toBeInTheDocument() | ||
| expect(screen.getByTestId('custom-trigger')).toHaveTextContent('Custom Trigger') | ||
| }) | ||
|
|
||
| it('should pass through additional RiPopover props', () => { | ||
| const additionalProps = { | ||
| anchorPosition: 'rightCenter' as const, | ||
| panelPaddingSize: 'l' as const, | ||
| 'data-testid': 'custom-popover', | ||
| } | ||
|
|
||
| renderConfirmationPopover(additionalProps) | ||
|
|
||
| expect(screen.getByTestId('custom-popover')).toBeInTheDocument() | ||
| }) | ||
| }) | ||
|
|
||
| describe('User Interactions', () => { | ||
| it('should handle confirm button click', () => { | ||
| renderConfirmationPopover() | ||
|
|
||
| const confirmButton = screen.getByTestId('confirm-button') | ||
| fireEvent.click(confirmButton) | ||
|
|
||
| expect(mockButtonClick).toHaveBeenCalledTimes(1) | ||
| }) | ||
|
|
||
| it('should handle trigger button interaction', () => { | ||
| const triggerClickMock = jest.fn() | ||
| const customTrigger = ( | ||
| <button data-testid="trigger-button" onClick={triggerClickMock}> | ||
| Trigger | ||
| </button> | ||
| ) | ||
|
|
||
| renderConfirmationPopover({ button: customTrigger }) | ||
|
|
||
| const triggerButton = screen.getByTestId('trigger-button') | ||
| fireEvent.click(triggerButton) | ||
|
|
||
| expect(triggerClickMock).toHaveBeenCalledTimes(1) | ||
| }) | ||
|
|
||
| it('should not interfere with confirm button when disabled', () => { | ||
| const disabledConfirmButton = ( | ||
| <button data-testid="confirm-button" disabled onClick={mockButtonClick}> | ||
| Confirm | ||
| </button> | ||
| ) | ||
|
|
||
| renderConfirmationPopover({ confirmButton: disabledConfirmButton }) | ||
|
|
||
| const confirmButton = screen.getByTestId('confirm-button') | ||
| expect(confirmButton).toBeDisabled() | ||
|
|
||
| fireEvent.click(confirmButton) | ||
| expect(mockButtonClick).not.toHaveBeenCalled() | ||
| }) | ||
| }) | ||
|
|
||
| describe('Layout and Structure', () => { | ||
| it('should have correct structure with title and message', () => { | ||
| const title = 'Confirm Action' | ||
| const message = 'This is a test message' | ||
| renderConfirmationPopover({ title, message }) | ||
|
|
||
| const titleElement = screen.getByText(title) | ||
| const messageElement = screen.getByText(message) | ||
| const confirmButton = screen.getByTestId('confirm-button') | ||
|
|
||
| expect(titleElement).toBeInTheDocument() | ||
| expect(messageElement).toBeInTheDocument() | ||
| expect(confirmButton).toBeInTheDocument() | ||
|
|
||
| const allElements = screen.getAllByText(/Confirm Action|This is a test message|Confirm/) | ||
| expect(allElements[0]).toBe(titleElement) | ||
| expect(allElements[1]).toBe(messageElement) | ||
| }) | ||
|
|
||
| it('should maintain proper spacing between elements', () => { | ||
| const title = 'Test Title' | ||
| const message = 'Test Message' | ||
| renderConfirmationPopover({ title, message }) | ||
|
|
||
| expect(screen.getByText(title)).toBeInTheDocument() | ||
| expect(screen.getByText(message)).toBeInTheDocument() | ||
| expect(screen.getByTestId('confirm-button')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('should handle long text content gracefully', () => { | ||
| const longTitle = 'This is a very long title that might wrap to multiple lines' | ||
| const longMessage = 'This is a very long message that should break properly with word-break styling' | ||
|
|
||
| renderConfirmationPopover({ | ||
| title: longTitle, | ||
| message: longMessage | ||
| }) | ||
|
|
||
| expect(screen.getByText(longTitle)).toBeInTheDocument() | ||
| expect(screen.getByText(longMessage)).toBeInTheDocument() | ||
| }) | ||
| }) | ||
| }) |
33 changes: 33 additions & 0 deletions
33
redisinsight/ui/src/components/confirmation-popover/ConfirmationPopover.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,33 @@ | ||
| import React from 'react' | ||
| import { RiPopover, RiPopoverProps } from 'uiSrc/components' | ||
| import styled from 'styled-components' | ||
| import { Col, Row } from 'uiSrc/components/base/layout/flex' | ||
| import { Text, Title } from 'uiSrc/components/base/text' | ||
|
|
||
| const PopoverContentWrapper = styled(Col)` | ||
| word-break: break-all; | ||
| max-width: 300px; | ||
| ` | ||
|
|
||
| export interface ConfirmationPopoverProps | ||
| extends Omit<RiPopoverProps, 'children'> { | ||
| title?: string | ||
| message?: string | ||
| confirmButton: React.ReactNode | ||
| } | ||
|
|
||
| const ConfirmationPopover = (props: ConfirmationPopoverProps) => { | ||
| const { title, message, confirmButton, ...rest } = props | ||
|
|
||
| return ( | ||
| <RiPopover {...rest}> | ||
| <PopoverContentWrapper gap="l" data-testid="confirm-popover"> | ||
| {title && <Title size="S">{title}</Title>} | ||
| {message && <Text size="m">{message}</Text>} | ||
| <Row>{confirmButton}</Row> | ||
| </PopoverContentWrapper> | ||
| </RiPopover> | ||
| ) | ||
| } | ||
|
|
||
| export default ConfirmationPopover | ||
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,3 @@ | ||
| import ConfirmationPopover from './ConfirmationPopover' | ||
|
|
||
| export default ConfirmationPopover |
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
Oops, something went wrong.
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.
nit: these should be ordered