-
Notifications
You must be signed in to change notification settings - Fork 125
Trim whitespace when splitting security-group annotations #6535
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ import { | |
| import GovernanceOverview from './Overview' | ||
| import userEvent from '@testing-library/user-event' | ||
| import { defaultContext, PluginDataContext } from '../../../lib/PluginDataContext' | ||
| import { Policy, PolicyApiVersion, PolicyKind } from '../../../resources' | ||
|
|
||
| describe('Overview Page', () => { | ||
| beforeEach(async () => nockIgnoreApiPaths()) | ||
|
|
@@ -141,4 +142,76 @@ describe('Overview Page', () => { | |
| userEvent.click(screen.getByText(/show 85 more/i)) | ||
| expect(queryByText(/show 85 more/i)).not.toBeInTheDocument() | ||
| }) | ||
|
|
||
| test('Should aggregate Standards card by trimmed annotation value, not raw comma-split token', async () => { | ||
| // Regression test: a standard listed anywhere but first in a comma-separated | ||
| // policy.open-cluster-management.io/standards annotation must not produce a | ||
| // separate row on the Standards card just because of the leading space left | ||
| // behind by String.split(','). | ||
| const policyWithStandardFirstInList: Policy = { | ||
| apiVersion: PolicyApiVersion, | ||
| kind: PolicyKind, | ||
| metadata: { | ||
| name: 'policy-standards-first', | ||
| namespace: 'test', | ||
| uid: 'standards-test-uid-1', | ||
| annotations: { | ||
| 'policy.open-cluster-management.io/standards': 'NIST SP 800-53, PCI-DSS 4.0', | ||
| }, | ||
| }, | ||
| spec: { | ||
| disabled: false, | ||
| 'policy-templates': [], | ||
| remediationAction: 'inform', | ||
| }, | ||
| status: { | ||
| compliant: 'Compliant', | ||
| }, | ||
| } | ||
| const policyWithStandardLastInList: Policy = { | ||
| apiVersion: PolicyApiVersion, | ||
| kind: PolicyKind, | ||
| metadata: { | ||
| name: 'policy-standards-last', | ||
| namespace: 'test', | ||
| uid: 'standards-test-uid-2', | ||
| annotations: { | ||
| 'policy.open-cluster-management.io/standards': 'CIS OpenShift Benchmark, PCI-DSS 4.0, NIST SP 800-53', | ||
| }, | ||
| }, | ||
| spec: { | ||
| disabled: false, | ||
| 'policy-templates': [], | ||
| remediationAction: 'inform', | ||
| }, | ||
| status: { | ||
| compliant: 'Compliant', | ||
| }, | ||
| } | ||
|
|
||
| const pluginData = { | ||
| ...defaultContext, | ||
| loadStarted: true, | ||
| loadCompleted: true, | ||
| } | ||
| render( | ||
| <PluginDataContext.Provider value={pluginData}> | ||
| <RecoilRoot | ||
| initializeState={(snapshot) => { | ||
| snapshot.set(policiesState, [policyWithStandardFirstInList, policyWithStandardLastInList]) | ||
| snapshot.set(managedClustersState, mockManagedClusters) | ||
| }} | ||
|
Comment on lines
+200
to
+204
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Use shared atom access for the new fixtures. Both tests set
As per coding guidelines, mock Recoil atoms via 📍 Affects 1 file
🤖 Prompt for AI AgentsSource: Coding guidelines |
||
| > | ||
| <MemoryRouter> | ||
| <GovernanceOverview /> | ||
| </MemoryRouter> | ||
| </RecoilRoot> | ||
| </PluginDataContext.Provider> | ||
| ) | ||
|
|
||
| // Before the fix this rendered two separate rows/spans for the same logical | ||
| // standard (one from the untrimmed " NIST SP 800-53" split token). | ||
| expect(screen.getAllByText('NIST SP 800-53').length).toBe(1) | ||
| expect(screen.getAllByText('PCI-DSS 4.0').length).toBe(1) | ||
| }) | ||
| }) | ||
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.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Use aliases and type-only imports.
SecurityGroupViolationsandPolicyare type-only; the newly added internal imports are relative. Split type imports withimport typeand use~/...aliases for the new internal imports.As per coding guidelines, use
~/shorthand andimport typefor type-only imports.🤖 Prompt for AI Agents
Source: Coding guidelines