Skip to content

Commit 84ddb7e

Browse files
authored
Merge pull request #2543 from trycompai/cs-241-framework-dropdown
CS-241: Add all frameworks to finding type dropdown
2 parents c84480e + e31be9b commit 84ddb7e

3 files changed

Lines changed: 66 additions & 3 deletions

File tree

apps/app/src/app/(app)/[orgId]/tasks/[taskId]/components/findings/CreateFindingSheet.test.tsx

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ vi.mock('@/hooks/use-findings-api', () => ({
3232
},
3333
],
3434
FINDING_CATEGORY_LABELS: { general: 'General' },
35+
FINDING_TYPE_FRAMEWORK_OPTIONS: [
36+
{ value: 'soc2', label: 'SOC 2' },
37+
{ value: 'iso27001', label: 'ISO 27001' },
38+
{ value: 'pci_dss', label: 'PCI DSS' },
39+
{ value: 'hipaa', label: 'HIPAA' },
40+
{ value: 'gdpr', label: 'GDPR' },
41+
{ value: 'iso9001', label: 'ISO 9001' },
42+
{ value: 'iso42001', label: 'ISO 42001' },
43+
],
3544
FINDING_TYPE_LABELS: { soc2: 'SOC 2', iso27001: 'ISO 27001' },
3645
useFindingActions: () => ({
3746
createFinding: vi.fn(),
@@ -99,7 +108,14 @@ vi.mock('@trycompai/design-system', () => ({
99108
Select: ({ children }: any) => <div>{children}</div>,
100109
SelectContent: ({ children }: any) => <div>{children}</div>,
101110
SelectGroup: ({ children }: any) => <div>{children}</div>,
102-
SelectItem: ({ children }: any) => <div>{children}</div>,
111+
SelectItem: ({ children, value, disabled }: any) => (
112+
<div
113+
data-testid={`select-item-${value}`}
114+
data-disabled={disabled ? 'true' : 'false'}
115+
>
116+
{children}
117+
</div>
118+
),
103119
SelectLabel: ({ children }: any) => <div>{children}</div>,
104120
SelectTrigger: ({ children }: any) => <button>{children}</button>,
105121
Sheet: ({ children, open }: any) => (open ? <div data-testid="sheet">{children}</div> : null),
@@ -189,4 +205,32 @@ describe('CreateFindingSheet permission gating', () => {
189205

190206
expect(screen.queryByTestId('sheet')).not.toBeInTheDocument();
191207
});
208+
209+
it('shows all required frameworks in finding type dropdown options', () => {
210+
setMockPermissions(ADMIN_PERMISSIONS);
211+
212+
render(<CreateFindingSheet {...defaultProps} />);
213+
214+
expect(screen.getByText('SOC 2')).toBeInTheDocument();
215+
expect(screen.getByText('ISO 27001')).toBeInTheDocument();
216+
expect(screen.getByText('PCI DSS')).toBeInTheDocument();
217+
expect(screen.getByText('HIPAA')).toBeInTheDocument();
218+
expect(screen.getByText('GDPR')).toBeInTheDocument();
219+
expect(screen.getByText('ISO 9001')).toBeInTheDocument();
220+
expect(screen.getByText('ISO 42001')).toBeInTheDocument();
221+
});
222+
223+
it('only enables framework options currently supported by FindingType enum', () => {
224+
setMockPermissions(ADMIN_PERMISSIONS);
225+
226+
render(<CreateFindingSheet {...defaultProps} />);
227+
228+
expect(screen.getByTestId('select-item-soc2')).toHaveAttribute('data-disabled', 'false');
229+
expect(screen.getByTestId('select-item-iso27001')).toHaveAttribute('data-disabled', 'false');
230+
expect(screen.getByTestId('select-item-pci_dss')).toHaveAttribute('data-disabled', 'true');
231+
expect(screen.getByTestId('select-item-hipaa')).toHaveAttribute('data-disabled', 'true');
232+
expect(screen.getByTestId('select-item-gdpr')).toHaveAttribute('data-disabled', 'true');
233+
expect(screen.getByTestId('select-item-iso9001')).toHaveAttribute('data-disabled', 'true');
234+
expect(screen.getByTestId('select-item-iso42001')).toHaveAttribute('data-disabled', 'true');
235+
});
192236
});

apps/app/src/app/(app)/[orgId]/tasks/[taskId]/components/findings/CreateFindingSheet.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import {
44
DEFAULT_FINDING_TEMPLATES,
55
FINDING_CATEGORY_LABELS,
6+
FINDING_TYPE_FRAMEWORK_OPTIONS,
67
FINDING_TYPE_LABELS,
78
useFindingActions,
89
useFindingTemplates,
@@ -68,6 +69,7 @@ export function CreateFindingSheet({
6869
const [isSubmitting, setIsSubmitting] = useState(false);
6970
const { hasPermission } = usePermissions();
7071
const canCreateFinding = hasPermission('finding', 'create');
72+
const supportedFindingTypes = new Set(Object.values(FindingType));
7173

7274
const { data: templatesData } = useFindingTemplates();
7375
const { createFinding } = useFindingActions();
@@ -165,8 +167,12 @@ export function CreateFindingSheet({
165167
<Select value={field.value} onValueChange={field.onChange}>
166168
<SelectTrigger>{FINDING_TYPE_LABELS[field.value as FindingType]}</SelectTrigger>
167169
<SelectContent>
168-
{Object.entries(FINDING_TYPE_LABELS).map(([value, label]) => (
169-
<SelectItem key={value} value={value}>
170+
{FINDING_TYPE_FRAMEWORK_OPTIONS.map(({ value, label }) => (
171+
<SelectItem
172+
key={value}
173+
value={value}
174+
disabled={!supportedFindingTypes.has(value as FindingType)}
175+
>
170176
{label}
171177
</SelectItem>
172178
))}

apps/app/src/hooks/use-findings-api.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,19 @@ export const FINDING_STATUS_CONFIG: Record<
395395
},
396396
};
397397

398+
/**
399+
* Framework options shown in finding type selectors
400+
*/
401+
export const FINDING_TYPE_FRAMEWORK_OPTIONS = [
402+
{ value: 'soc2', label: 'SOC 2' },
403+
{ value: 'iso27001', label: 'ISO 27001' },
404+
{ value: 'pci_dss', label: 'PCI DSS' },
405+
{ value: 'hipaa', label: 'HIPAA' },
406+
{ value: 'gdpr', label: 'GDPR' },
407+
{ value: 'iso9001', label: 'ISO 9001' },
408+
{ value: 'iso42001', label: 'ISO 42001' },
409+
] as const;
410+
398411
/**
399412
* Finding type labels
400413
*/

0 commit comments

Comments
 (0)