-
Notifications
You must be signed in to change notification settings - Fork 122
ACM-37999 Edit Cluster Description via Modal #6527
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
Open
oksanabaza
wants to merge
7
commits into
stolostron:main
Choose a base branch
from
oksanabaza:ACM-37999
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
43ddad6
Display Cluster Description with Markdown Rendering
oksanabaza d559073
Remove mock description
oksanabaza d29f008
Implement cluster description edit modal with markdown formatting
oksanabaza 9d0a371
Align EditDescription patch logic with EditLabels pattern
oksanabaza 938a63d
Add coderabbitai suggestion
oksanabaza 941bf26
Add tests
oksanabaza ffa597c
Add translation
oksanabaza 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
131 changes: 131 additions & 0 deletions
131
...nd/src/routes/Infrastructure/Clusters/ManagedClusters/components/EditDescription.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,131 @@ | ||
| /* Copyright Contributors to the Open Cluster Management project */ | ||
|
|
||
| import { IResource, ManagedClusterApiVersion, ManagedClusterKind } from '../../../../../resources' | ||
| import { render, waitFor } from '@testing-library/react' | ||
| import userEvent from '@testing-library/user-event' | ||
| import { mockBadRequestStatus, nockIgnoreApiPaths, nockPatch } from '../../../../../lib/nock-util' | ||
| import { EditDescription } from './EditDescription' | ||
| import { axe } from 'jest-axe' | ||
|
|
||
| const CLUSTER_DESCRIPTION_ANNOTATION = 'console.open-cluster-management.io/description' | ||
|
|
||
| const resource: IResource = { | ||
| apiVersion: ManagedClusterApiVersion, | ||
| kind: ManagedClusterKind, | ||
| metadata: { | ||
| name: 'test-cluster', | ||
| annotations: { | ||
| [CLUSTER_DESCRIPTION_ANNOTATION]: 'Initial description', | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| describe('EditDescription', () => { | ||
| beforeEach(() => nockIgnoreApiPaths()) | ||
|
|
||
| test('renders with existing description', () => { | ||
| const { getByDisplayValue } = render(<EditDescription resource={resource} close={() => {}} />) | ||
| expect(getByDisplayValue('Initial description')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| test('has zero accessibility defects', async () => { | ||
| const { container } = render(<EditDescription resource={resource} close={() => {}} />) | ||
| expect(await axe(container)).toHaveNoViolations() | ||
| }) | ||
|
|
||
| test('can update description', async () => { | ||
| const { getByLabelText, getByRole } = render(<EditDescription resource={resource} close={() => {}} />) | ||
| const textarea = getByLabelText('Description') | ||
|
|
||
| userEvent.clear(textarea) | ||
| userEvent.type(textarea, 'Updated description text') | ||
|
|
||
| const nockScope = nockPatch( | ||
| { apiVersion: resource.apiVersion, kind: resource.kind, metadata: { name: resource.metadata!.name } }, | ||
| { | ||
| metadata: { | ||
| annotations: { | ||
| [CLUSTER_DESCRIPTION_ANNOTATION]: 'Updated description text', | ||
| }, | ||
| }, | ||
| } | ||
| ) | ||
|
|
||
| getByRole('button', { name: /save/i }).click() | ||
| await waitFor(() => expect(nockScope.isDone()).toBeTruthy()) | ||
| }) | ||
|
|
||
| test('can clear description', async () => { | ||
| const { getByLabelText, getByRole } = render(<EditDescription resource={resource} close={() => {}} />) | ||
| const textarea = getByLabelText('Description') | ||
|
|
||
| userEvent.clear(textarea) | ||
|
|
||
| const nockScope = nockPatch( | ||
| { apiVersion: resource.apiVersion, kind: resource.kind, metadata: { name: resource.metadata!.name } }, | ||
| { | ||
| metadata: { | ||
| annotations: { | ||
| [CLUSTER_DESCRIPTION_ANNOTATION]: null, | ||
| }, | ||
| }, | ||
| } | ||
| ) | ||
|
|
||
| getByRole('button', { name: /save/i }).click() | ||
| await waitFor(() => expect(nockScope.isDone()).toBeTruthy()) | ||
| }) | ||
|
|
||
| test('formatting buttons insert markdown syntax', async () => { | ||
| const { getByLabelText, getByLabelText: getByAriaLabel } = render( | ||
| <EditDescription resource={resource} close={() => {}} /> | ||
| ) | ||
| const textarea = getByLabelText('Description') as HTMLTextAreaElement | ||
|
|
||
| userEvent.clear(textarea) | ||
| userEvent.type(textarea, 'test') | ||
|
|
||
| textarea.setSelectionRange(0, 4) | ||
|
|
||
| const boldButton = getByAriaLabel('Bold') | ||
| userEvent.click(boldButton) | ||
|
|
||
| await waitFor(() => expect(textarea.value).toBe('**test**')) | ||
| }) | ||
|
|
||
| test('shows errors on save failure', async () => { | ||
| const { getByLabelText, getByRole } = render(<EditDescription resource={resource} close={() => {}} />) | ||
| const textarea = getByLabelText('Description') | ||
|
|
||
| userEvent.clear(textarea) | ||
| userEvent.type(textarea, 'New description') | ||
|
|
||
| const nockScope = nockPatch( | ||
| { apiVersion: resource.apiVersion, kind: resource.kind, metadata: { name: resource.metadata!.name } }, | ||
| { | ||
| metadata: { | ||
| annotations: { | ||
| [CLUSTER_DESCRIPTION_ANNOTATION]: 'New description', | ||
| }, | ||
| }, | ||
| }, | ||
| mockBadRequestStatus | ||
| ) | ||
|
|
||
| getByRole('button', { name: /save/i }).click() | ||
| await waitFor(() => expect(nockScope.isDone()).toBeTruthy()) | ||
| }) | ||
|
|
||
| test('works without existing annotations', () => { | ||
| const resourceWithoutAnnotations: IResource = { | ||
| apiVersion: ManagedClusterApiVersion, | ||
| kind: ManagedClusterKind, | ||
| metadata: { | ||
| name: 'test-cluster', | ||
| }, | ||
| } | ||
| const { getByLabelText } = render(<EditDescription resource={resourceWithoutAnnotations} close={() => {}} />) | ||
| const textarea = getByLabelText('Description') as HTMLTextAreaElement | ||
| expect(textarea.value).toBe('') | ||
| }) | ||
| }) | ||
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.
π― Functional Correctness | π‘ Minor | β‘ Quick win
Return an actual failure status and assert the alert.
nockPatchtreatsmockBadRequestStatusas the response body; without a fourth argument, it returns 204. This test currently exercises the success path and never verifies the error UI.Proposed change
π Committable suggestion
π€ Prompt for AI Agents