@cccsaurora/howler-ui 2.18.0-dev.710 → 2.18.0-dev.716

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,5 +3,6 @@ declare const _default: import("react").NamedExoticComponent<{
3
3
  id?: string;
4
4
  layout: HitLayout;
5
5
  readOnly?: boolean;
6
+ elevation?: number;
6
7
  }>;
7
8
  export default _default;
@@ -7,7 +7,7 @@ import HowlerCard from '../display/HowlerCard';
7
7
  import HitBanner from './HitBanner';
8
8
  import HitLabels from './HitLabels';
9
9
  import HitOutline from './HitOutline';
10
- const HitCard = ({ id, layout, readOnly = true }) => {
10
+ const HitCard = ({ id, layout, readOnly = true, elevation }) => {
11
11
  const getRecord = useContextSelector(RecordContext, ctx => ctx.getRecord);
12
12
  const hit = useContextSelector(RecordContext, ctx => ctx.records[id]);
13
13
  useEffect(() => {
@@ -19,6 +19,6 @@ const HitCard = ({ id, layout, readOnly = true }) => {
19
19
  if (!hit) {
20
20
  return _jsx(Skeleton, { variant: "rounded", height: "200px" });
21
21
  }
22
- return (_jsx(HowlerCard, { id: hit?.howler.id, tabIndex: 0, sx: { position: 'relative' }, children: _jsxs(CardContent, { children: [_jsx(HitBanner, { hit: hit, layout: layout }), _jsx(HitOutline, { hit: hit, layout: layout }), _jsx(HitLabels, { hit: hit, readOnly: readOnly })] }) }));
22
+ return (_jsx(HowlerCard, { id: hit?.howler.id, tabIndex: 0, sx: { position: 'relative' }, elevation: elevation, children: _jsxs(CardContent, { children: [_jsx(HitBanner, { hit: hit, layout: layout }), _jsx(HitOutline, { hit: hit, layout: layout }), _jsx(HitLabels, { hit: hit, readOnly: readOnly })] }) }));
23
23
  };
24
24
  export default memo(HitCard);
@@ -13,10 +13,10 @@ const CaseViewer = () => {
13
13
  if (missing) {
14
14
  return _jsx(NotFoundPage, {});
15
15
  }
16
- return (_jsxs(Stack, { direction: "row", height: "100%", children: [_jsx(CaseSidebar, { case: _case, update: updatedCase => update(updatedCase, false) }), _jsx(Box, { sx: {
17
- maxHeight: 'calc(100vh - 64px)',
18
- flex: 1,
19
- overflow: 'auto'
20
- }, children: _jsx(ErrorBoundary, { children: _jsx(Outlet, { context: _case }) }) }), _jsx(CaseDetails, { case: _case })] }));
16
+ return (_jsx(ErrorBoundary, { children: _jsxs(Stack, { direction: "row", height: "100%", children: [_jsx(CaseSidebar, { case: _case, update: updatedCase => update(updatedCase, false) }), _jsx(Box, { sx: {
17
+ maxHeight: 'calc(100vh - 64px)',
18
+ flex: 1,
19
+ overflow: 'auto'
20
+ }, children: _jsx(ErrorBoundary, { children: _jsx(Outlet, { context: _case }) }) }), _jsx(CaseDetails, { case: _case })] }) }));
21
21
  };
22
22
  export default memo(CaseViewer);
@@ -2,10 +2,12 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
2
2
  import { Article, BookRounded, CheckCircle, ChevronRight, Folder as FolderIcon, Lightbulb, Link as LinkIcon, TableChart, Visibility } from '@mui/icons-material';
3
3
  import { alpha, Skeleton, Stack, Typography, useTheme } from '@mui/material';
4
4
  import api from '@cccsaurora/howler-ui/api';
5
+ import { RecordContext } from '@cccsaurora/howler-ui/components/app/providers/RecordProvider';
5
6
  import useMyApi from '@cccsaurora/howler-ui/components/hooks/useMyApi';
6
7
  import { omit } from 'lodash-es';
7
8
  import { useCallback, useEffect, useMemo, useState } from 'react';
8
9
  import { Link, useLocation } from 'react-router-dom';
10
+ import { useContextSelector } from 'use-context-selector';
9
11
  import { ESCALATION_COLORS } from '@cccsaurora/howler-ui/utils/constants';
10
12
  import CaseFolderContextMenu from './CaseFolderContextMenu';
11
13
  import { buildTree } from './utils';
@@ -24,7 +26,8 @@ const CaseFolder = ({ case: _case, folder, name, step = -1, rootCaseId, pathPref
24
26
  const { dispatchApi } = useMyApi();
25
27
  const [open, setOpen] = useState(true);
26
28
  const [caseStates, setCaseStates] = useState({});
27
- const [hitMetadata, setHitMetadata] = useState({});
29
+ const loadRecords = useContextSelector(RecordContext, ctx => ctx.loadRecords);
30
+ const records = useContextSelector(RecordContext, ctx => ctx.records);
28
31
  const tree = useMemo(() => folder || buildTree(_case?.items), [folder, _case?.items]);
29
32
  const currentRootCaseId = rootCaseId || _case?.case_id;
30
33
  const hitIds = useMemo(() => _case?.items
@@ -36,15 +39,15 @@ const CaseFolder = ({ case: _case, folder, name, step = -1, rootCaseId, pathPref
36
39
  return;
37
40
  }
38
41
  dispatchApi(api.search.hit.post({ query: `howler.id:(${hitIds.join(' OR ')})` }), { throwError: false }).then(result => {
39
- if ((result?.items?.length ?? 0) < 1)
42
+ if (result?.items?.length < 1) {
40
43
  return;
41
- setHitMetadata(Object.fromEntries(result.items.map(hit => [hit.howler.id, hit.howler])));
44
+ }
42
45
  });
43
- }, [hitIds, dispatchApi]);
46
+ }, [hitIds, dispatchApi, _case.status, loadRecords]);
44
47
  // Returns the MUI colour token for the item's escalation, or undefined if none.
45
48
  const getEscalationColor = (itemType, itemKey, leafId) => {
46
49
  if (itemType === 'hit' && leafId) {
47
- const color = ESCALATION_COLORS[hitMetadata[leafId]?.escalation];
50
+ const color = ESCALATION_COLORS[records[leafId]?.howler?.escalation];
48
51
  if (color)
49
52
  return color;
50
53
  }
@@ -1,19 +1,39 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { OpenInNew } from '@mui/icons-material';
3
- import { Autocomplete, Box, Button, Card, Chip, Divider, IconButton, LinearProgress, Skeleton, Stack, TextField, Typography } from '@mui/material';
2
+ import { KeyboardArrowDown, OpenInNew } from '@mui/icons-material';
3
+ import { Accordion, AccordionDetails, AccordionSummary, Autocomplete, Box, Button, Checkbox, Chip, CircularProgress, Divider, IconButton, LinearProgress, Skeleton, Stack, TextField, Typography } from '@mui/material';
4
4
  import api from '@cccsaurora/howler-ui/api';
5
5
  import { ApiConfigContext } from '@cccsaurora/howler-ui/components/app/providers/ApiConfigProvider';
6
6
  import { ModalContext } from '@cccsaurora/howler-ui/components/app/providers/ModalProvider';
7
+ import { RecordContext } from '@cccsaurora/howler-ui/components/app/providers/RecordProvider';
7
8
  import AnalyticLink from '@cccsaurora/howler-ui/components/elements/hit/elements/AnalyticLink';
8
9
  import EscalationChip from '@cccsaurora/howler-ui/components/elements/hit/elements/EscalationChip';
10
+ import HitCard from '@cccsaurora/howler-ui/components/elements/hit/HitCard';
9
11
  import { HitLayout } from '@cccsaurora/howler-ui/components/elements/hit/HitLayout';
10
12
  import useHitActions from '@cccsaurora/howler-ui/components/hooks/useHitActions';
11
13
  import useMyApi from '@cccsaurora/howler-ui/components/hooks/useMyApi';
12
- import { uniq } from 'lodash-es';
13
- import { useContext, useEffect, useMemo, useState } from 'react';
14
+ import { isNil, uniq } from 'lodash-es';
15
+ import { useCallback, useContext, useEffect, useMemo, useState } from 'react';
14
16
  import { useTranslation } from 'react-i18next';
15
17
  import { Link } from 'react-router-dom';
18
+ import { useContextSelector } from 'use-context-selector';
16
19
  import useCase from '../hooks/useCase';
20
+ const HitEntry = ({ hit, checked, onChange }) => {
21
+ if (!hit) {
22
+ return _jsx(Skeleton, { variant: "rounded", height: "40px", width: "100%" });
23
+ }
24
+ return (_jsxs(Accordion, { sx: { flexShrink: 0, px: 0, py: 0 }, children: [_jsx(AccordionSummary, { expandIcon: _jsx(KeyboardArrowDown, {}), sx: {
25
+ px: 1,
26
+ py: 0,
27
+ minHeight: '48px !important',
28
+ '& > *': {
29
+ margin: '0 !important'
30
+ }
31
+ }, children: _jsxs(Stack, { direction: "row", alignItems: "center", spacing: 1, pr: 1, width: "100%", children: [!isNil(checked) && (_jsx(Checkbox, { size: "small", checked: checked, onClick: e => {
32
+ onChange?.();
33
+ e.preventDefault();
34
+ e.stopPropagation();
35
+ } })), _jsx(AnalyticLink, { hit: hit, compressed: true, alignSelf: "center" }), _jsx(EscalationChip, { hit: hit, layout: HitLayout.DENSE }), _jsx(Chip, { sx: { width: 'fit-content', display: 'inline-flex' }, label: hit.howler.status, size: "small", color: "primary" }), _jsx("div", { style: { flex: 1 } }), _jsx(IconButton, { size: "small", component: Link, to: `/hits/${hit.howler.id}`, children: _jsx(OpenInNew, { fontSize: "small" }) })] }) }), _jsx(AccordionDetails, { children: _jsx(HitCard, { id: hit.howler.id, layout: HitLayout.NORMAL, elevation: 0 }) })] }, hit.howler.id));
36
+ };
17
37
  const ResolveModal = ({ case: _case, onConfirm }) => {
18
38
  const { t } = useTranslation();
19
39
  const { dispatchApi } = useMyApi();
@@ -23,40 +43,73 @@ const ResolveModal = ({ case: _case, onConfirm }) => {
23
43
  const [loading, setLoading] = useState(true);
24
44
  const [rationale, setRationale] = useState('');
25
45
  const [assessment, setAssessment] = useState(null);
26
- const [hits, setHits] = useState([]);
46
+ const [selectedHitIds, setSelectedHitIds] = useState(new Set());
27
47
  const hitIds = useMemo(() => uniq((_case?.items ?? [])
28
48
  .filter(item => item.type === 'hit')
29
49
  .map(item => item.value)
30
50
  .filter(Boolean)), [_case?.items]);
31
- const { assess } = useHitActions(hits);
51
+ const loadRecords = useContextSelector(RecordContext, ctx => ctx.loadRecords);
52
+ const records = useContextSelector(RecordContext, ctx => ctx.records);
53
+ const hits = useMemo(() => hitIds.map(id => records[id]).filter(Boolean), [hitIds, records]);
54
+ const selectedHits = useMemo(() => hits.filter(hit => selectedHitIds.has(hit.howler.id)), [hits, selectedHitIds]);
55
+ const { assess } = useHitActions(selectedHits);
56
+ const unresolvedHits = useMemo(() => hitIds.filter(id => {
57
+ const record = records[id];
58
+ if (!record) {
59
+ // Treat missing records as unresolved until they are loaded
60
+ return true;
61
+ }
62
+ return record.howler.status !== 'resolved';
63
+ }), [hitIds, records]);
64
+ const handleConfirm = async () => {
65
+ setLoading(true);
66
+ try {
67
+ await assess(assessment, true, rationale);
68
+ setSelectedHitIds(new Set());
69
+ }
70
+ finally {
71
+ setLoading(false);
72
+ }
73
+ };
74
+ const handleToggleHit = useCallback((hitId) => {
75
+ setSelectedHitIds(prev => {
76
+ const next = new Set(prev);
77
+ if (next.has(hitId)) {
78
+ next.delete(hitId);
79
+ }
80
+ else {
81
+ next.add(hitId);
82
+ }
83
+ return next;
84
+ });
85
+ }, []);
32
86
  useEffect(() => {
33
87
  (async () => {
34
88
  try {
35
89
  const result = await dispatchApi(api.search.hit.post({
36
- query: `howler.id:(${hitIds.join(' OR ')}) AND -howler.status:resolved`,
90
+ query: `howler.id:(${hitIds.join(' OR ')})`,
37
91
  metadata: ['analytic']
38
92
  }));
39
- setHits(result.items);
93
+ loadRecords(result.items);
40
94
  }
41
95
  finally {
42
96
  setLoading(false);
43
97
  }
44
98
  })();
45
- }, [dispatchApi, hitIds]);
46
- const handleConfirm = async () => {
47
- setLoading(true);
48
- try {
49
- await assess(assessment, true, rationale);
50
- await updateCase({ status: 'resolved' });
99
+ }, [dispatchApi, hitIds, loadRecords]);
100
+ useEffect(() => {
101
+ if (loading || unresolvedHits.length > 0) {
102
+ return;
103
+ }
104
+ updateCase({ status: 'resolved' }).then(() => {
51
105
  onConfirm();
52
106
  close();
53
- }
54
- finally {
55
- setLoading(false);
56
- }
57
- };
58
- return (_jsxs(Stack, { spacing: 2, p: 2, alignItems: "start", sx: { minWidth: 'min(1000px, 60vw)', maxHeight: '100%', height: '100%' }, children: [_jsx(Typography, { variant: "h4", children: t('modal.cases.resolve') }), _jsx(Typography, { children: t('modal.cases.resolve.description') }), _jsxs(Stack, { spacing: 1, overflow: "auto", width: "100%", flex: 1, children: [_jsxs(Stack, { direction: "row", spacing: 1, children: [_jsx(Box, { flex: 1, children: _jsx(TextField, { size: "small", fullWidth: true, placeholder: t('modal.rationale.label'), value: rationale, onChange: ev => setRationale(ev.target.value) }) }), _jsx(Box, { flex: 1, children: _jsx(Autocomplete, { size: "small", value: assessment, onChange: (_ev, _assessment) => setAssessment(_assessment), options: config.lookups['howler.assessment'], disablePortal: true, renderInput: params => (_jsx(TextField, { ...params, placeholder: t('hit.details.actions.assessment'), fullWidth: true })) }) })] }), _jsxs(Stack, { position: "relative", children: [_jsx(Divider, {}), _jsx(LinearProgress, { sx: { opacity: +loading } })] }), loading
59
- ? hitIds.map(id => _jsx(Skeleton, { variant: "rounded", height: "40px", width: "100%" }, id))
60
- : hits.map(hit => (_jsx(Card, { sx: { p: 1, flexShrink: 0 }, children: _jsxs(Stack, { direction: "row", alignItems: "center", spacing: 1, width: "100%", children: [_jsx(AnalyticLink, { hit: hit, compressed: true, alignSelf: "center" }), _jsx(EscalationChip, { hit: hit, layout: HitLayout.DENSE }), _jsx(Chip, { sx: { width: 'fit-content', display: 'inline-flex' }, label: hit.howler.status, size: "small", color: "primary" }), _jsx("div", { style: { flex: 1 } }), _jsx(IconButton, { size: "small", component: Link, to: `/hits/${hit.howler.id}`, children: _jsx(OpenInNew, { fontSize: "small" }) })] }) }, hit.howler.id)))] }), _jsxs(Stack, { direction: "row", spacing: 1, alignSelf: "end", children: [_jsx(Button, { variant: "outlined", color: "error", onClick: close, children: t('cancel') }), _jsx(Button, { variant: "outlined", color: "success", disabled: loading || !assessment || !rationale, onClick: handleConfirm, children: t('confirm') })] })] }));
107
+ });
108
+ }, [close, loading, onConfirm, unresolvedHits.length, updateCase]);
109
+ return (_jsxs(Stack, { spacing: 2, p: 2, alignItems: "start", sx: { minWidth: 'min(1000px, 60vw)', maxHeight: '100%', height: '100%' }, children: [_jsx(Typography, { variant: "h4", children: t('modal.cases.resolve') }), _jsx(Typography, { children: t('modal.cases.resolve.description') }), _jsxs(Stack, { spacing: 1, overflow: "auto", width: "100%", flex: 1, children: [_jsxs(Stack, { direction: "row", spacing: 1, children: [_jsx(Box, { flex: 1, children: _jsx(TextField, { size: "small", fullWidth: true, placeholder: t('modal.rationale.label'), "aria-label": t('modal.rationale.label'), value: rationale, onChange: ev => setRationale(ev.target.value) }) }), _jsx(Box, { flex: 1, children: _jsx(Autocomplete, { size: "small", value: assessment, onChange: (_ev, _assessment) => setAssessment(_assessment), options: config.lookups['howler.assessment'], disablePortal: true, renderInput: params => (_jsx(TextField, { ...params, placeholder: t('hit.details.actions.assessment'), "aria-label": t('hit.details.actions.assessment'), fullWidth: true })) }) })] }), _jsxs(Stack, { position: "relative", children: [_jsx(Divider, {}), _jsx(LinearProgress, { sx: { opacity: +loading } })] }), hits
110
+ .filter(hit => unresolvedHits.includes(hit.howler.id))
111
+ .map(hit => (_jsx(HitEntry, { hit: hit, checked: selectedHitIds.has(hit.howler.id), onChange: () => handleToggleHit(hit.howler.id) }, hit.howler.id))), _jsxs(Accordion, { variant: "outlined", children: [_jsx(AccordionSummary, { expandIcon: _jsx(KeyboardArrowDown, {}), children: t('modal.cases.alerts.resolved') }), _jsx(AccordionDetails, { children: _jsx(Stack, { spacing: 1, children: hits
112
+ .filter(hit => !unresolvedHits.includes(hit.howler.id))
113
+ .map(hit => (_jsx(HitEntry, { hit: hit }, hit.howler.id))) }) })] })] }), _jsxs(Stack, { direction: "row", spacing: 1, alignSelf: "end", children: [_jsx(Button, { variant: "outlined", color: "error", onClick: close, children: t('cancel') }), _jsx(Button, { variant: "outlined", color: "success", disabled: loading || !assessment || !rationale || selectedHitIds.size === 0, startIcon: loading ? _jsx(CircularProgress, { size: 16, color: "inherit" }) : undefined, onClick: handleConfirm, children: t('confirm') })] })] }));
61
114
  };
62
115
  export default ResolveModal;
@@ -0,0 +1,384 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /// <reference types="vitest" />
3
+ import { fireEvent, render, screen, waitFor } from '@testing-library/react';
4
+ import userEvent, {} from '@testing-library/user-event';
5
+ import { ApiConfigContext } from '@cccsaurora/howler-ui/components/app/providers/ApiConfigProvider';
6
+ import { ModalContext } from '@cccsaurora/howler-ui/components/app/providers/ModalProvider';
7
+ import { RecordContext } from '@cccsaurora/howler-ui/components/app/providers/RecordProvider';
8
+ import i18n from '@cccsaurora/howler-ui/i18n';
9
+ import {} from 'react';
10
+ import { I18nextProvider } from 'react-i18next';
11
+ import { MemoryRouter } from 'react-router-dom';
12
+ import { createMockCase, createMockHit } from '@cccsaurora/howler-ui/tests/utils';
13
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
14
+ import ResolveModal from './ResolveModal';
15
+ // ---------------------------------------------------------------------------
16
+ // Hoisted mocks
17
+ // ---------------------------------------------------------------------------
18
+ const mockAssess = vi.hoisted(() => vi.fn().mockResolvedValue(undefined));
19
+ const mockDispatchApi = vi.hoisted(() => vi.fn());
20
+ const mockUpdateCase = vi.hoisted(() => vi.fn().mockResolvedValue(undefined));
21
+ const mockClose = vi.hoisted(() => vi.fn());
22
+ const mockLoadRecords = vi.hoisted(() => vi.fn());
23
+ vi.mock('components/hooks/useMyApi', () => ({
24
+ default: () => ({ dispatchApi: mockDispatchApi })
25
+ }));
26
+ vi.mock('components/hooks/useHitActions', () => ({
27
+ default: () => ({ assess: mockAssess })
28
+ }));
29
+ vi.mock('../hooks/useCase', () => ({
30
+ default: () => ({ update: mockUpdateCase })
31
+ }));
32
+ vi.mock('components/elements/hit/elements/AnalyticLink', () => ({
33
+ default: ({ hit }) => _jsx("span", { "data-testid": `analytic-${hit.howler.id}`, children: hit.howler.analytic })
34
+ }));
35
+ vi.mock('components/elements/hit/elements/EscalationChip', () => ({
36
+ default: () => null
37
+ }));
38
+ vi.mock('components/elements/hit/HitCard', () => ({
39
+ default: ({ id }) => _jsx("div", { children: `HitCard:${id}` })
40
+ }));
41
+ vi.mock('api', () => ({
42
+ default: {
43
+ search: {
44
+ hit: {
45
+ post: (params) => params
46
+ }
47
+ }
48
+ }
49
+ }));
50
+ vi.mock('commons/components/app/hooks/useAppUser', () => ({
51
+ useAppUser: () => ({ user: { username: 'test-user' } })
52
+ }));
53
+ // ---------------------------------------------------------------------------
54
+ // Fixtures
55
+ // ---------------------------------------------------------------------------
56
+ const mockConfig = {
57
+ lookups: {
58
+ 'howler.assessment': ['legitimate', 'false_positive', 'non_issue']
59
+ }
60
+ };
61
+ const makeUnresolvedHit = (id) => createMockHit({ howler: { id, status: 'open', analytic: `analytic-${id}` } });
62
+ const makeResolvedHit = (id) => createMockHit({ howler: { id, status: 'resolved', analytic: `analytic-${id}` } });
63
+ const HIT_1 = makeUnresolvedHit('hit-1');
64
+ const HIT_2 = makeUnresolvedHit('hit-2');
65
+ const HIT_RESOLVED = makeResolvedHit('hit-resolved');
66
+ const caseWithHits = (hitIds) => createMockCase({
67
+ case_id: 'case-1',
68
+ items: hitIds.map(id => ({ type: 'hit', value: id }))
69
+ });
70
+ // ---------------------------------------------------------------------------
71
+ // Wrapper factory
72
+ // ---------------------------------------------------------------------------
73
+ const createWrapper = (records = {}) => {
74
+ const Wrapper = ({ children }) => (_jsx(I18nextProvider, { i18n: i18n, children: _jsx(ModalContext.Provider, { value: { close: mockClose, open: vi.fn(), setContent: vi.fn() }, children: _jsx(ApiConfigContext.Provider, { value: { config: mockConfig, setConfig: vi.fn() }, children: _jsx(RecordContext.Provider, { value: { records, loadRecords: mockLoadRecords }, children: _jsx(MemoryRouter, { children: children }) }) }) }) }));
75
+ return Wrapper;
76
+ };
77
+ // ---------------------------------------------------------------------------
78
+ // Helpers
79
+ // ---------------------------------------------------------------------------
80
+ /**
81
+ * Clicks a MUI Checkbox — operates on the ButtonBase parent of the hidden input
82
+ * so that user-event's special checkbox-input code path is bypassed and the
83
+ * component's own onClick handler fires correctly.
84
+ */
85
+ const clickCheckbox = (checkbox) => {
86
+ fireEvent.click(checkbox.parentElement);
87
+ };
88
+ /** Fills in assessment and rationale so the confirm button becomes enabled. */
89
+ const fillForm = async (user, assessment = 'legitimate', rationale = 'Test rationale') => {
90
+ const rationaleInput = screen.getByPlaceholderText(i18n.t('modal.rationale.label'));
91
+ await user.clear(rationaleInput);
92
+ await user.type(rationaleInput, rationale);
93
+ // Typing into the combobox triggers MUI Autocomplete's onInputChange which
94
+ // opens the listbox — a plain click does not reliably open it in jsdom.
95
+ // The combobox has no accessible label (only a placeholder), so we query by
96
+ // role alone — there is exactly one combobox in the modal.
97
+ const assessmentInput = screen.getByRole('combobox');
98
+ await user.type(assessmentInput, assessment.slice(0, 3));
99
+ const option = await screen.findByRole('option', { name: assessment });
100
+ await user.click(option);
101
+ };
102
+ // ---------------------------------------------------------------------------
103
+ // Tests
104
+ // ---------------------------------------------------------------------------
105
+ describe('ResolveModal', () => {
106
+ let user;
107
+ let mockOnConfirm;
108
+ beforeEach(() => {
109
+ user = userEvent.setup();
110
+ mockOnConfirm = vi.fn();
111
+ vi.clearAllMocks();
112
+ // Default: resolve immediately with an empty items list
113
+ mockDispatchApi.mockResolvedValue({ items: [] });
114
+ });
115
+ // -------------------------------------------------------------------------
116
+ // Initial render
117
+ // -------------------------------------------------------------------------
118
+ describe('initial render', () => {
119
+ it('shows the modal title', () => {
120
+ render(_jsx(ResolveModal, { case: caseWithHits([]), onConfirm: mockOnConfirm }), {
121
+ wrapper: createWrapper()
122
+ });
123
+ expect(screen.getByText(i18n.t('modal.cases.resolve'))).toBeInTheDocument();
124
+ });
125
+ it('shows the modal description', () => {
126
+ render(_jsx(ResolveModal, { case: caseWithHits([]), onConfirm: mockOnConfirm }), {
127
+ wrapper: createWrapper()
128
+ });
129
+ expect(screen.getByText(i18n.t('modal.cases.resolve.description'))).toBeInTheDocument();
130
+ });
131
+ it('renders a cancel button', () => {
132
+ render(_jsx(ResolveModal, { case: caseWithHits([]), onConfirm: mockOnConfirm }), {
133
+ wrapper: createWrapper()
134
+ });
135
+ expect(screen.getByRole('button', { name: i18n.t('cancel') })).toBeInTheDocument();
136
+ });
137
+ it('renders a confirm button', () => {
138
+ render(_jsx(ResolveModal, { case: caseWithHits([]), onConfirm: mockOnConfirm }), {
139
+ wrapper: createWrapper()
140
+ });
141
+ expect(screen.getByRole('button', { name: i18n.t('confirm') })).toBeInTheDocument();
142
+ });
143
+ it('shows the "Resolved Alerts" accordion', () => {
144
+ render(_jsx(ResolveModal, { case: caseWithHits([]), onConfirm: mockOnConfirm }), {
145
+ wrapper: createWrapper()
146
+ });
147
+ expect(screen.getByText(i18n.t('modal.cases.alerts.resolved'))).toBeInTheDocument();
148
+ });
149
+ });
150
+ // -------------------------------------------------------------------------
151
+ // Loading state
152
+ // -------------------------------------------------------------------------
153
+ describe('loading state', () => {
154
+ it('shows a LinearProgress while the API call is pending', () => {
155
+ mockDispatchApi.mockReturnValue(new Promise(() => { })); // never resolves
156
+ const { container } = render(_jsx(ResolveModal, { case: caseWithHits(['hit-1']), onConfirm: mockOnConfirm }), {
157
+ wrapper: createWrapper()
158
+ });
159
+ const progress = container.querySelector('.MuiLinearProgress-root');
160
+ expect(progress).toBeInTheDocument();
161
+ // opacity is 1 while loading
162
+ expect(progress).toHaveStyle({ opacity: '1' });
163
+ });
164
+ it('disables the confirm button while loading', () => {
165
+ mockDispatchApi.mockReturnValue(new Promise(() => { }));
166
+ render(_jsx(ResolveModal, { case: caseWithHits(['hit-1']), onConfirm: mockOnConfirm }), {
167
+ wrapper: createWrapper()
168
+ });
169
+ expect(screen.getByRole('button', { name: i18n.t('confirm') })).toBeDisabled();
170
+ });
171
+ it('shows a CircularProgress inside the confirm button while loading', () => {
172
+ mockDispatchApi.mockReturnValue(new Promise(() => { }));
173
+ const { container } = render(_jsx(ResolveModal, { case: caseWithHits(['hit-1']), onConfirm: mockOnConfirm }), {
174
+ wrapper: createWrapper()
175
+ });
176
+ expect(container.querySelector('.MuiCircularProgress-root')).toBeInTheDocument();
177
+ });
178
+ it('fades out the LinearProgress after loading completes', async () => {
179
+ const { container } = render(_jsx(ResolveModal, { case: caseWithHits([]), onConfirm: mockOnConfirm }), {
180
+ wrapper: createWrapper()
181
+ });
182
+ await waitFor(() => {
183
+ const progress = container.querySelector('.MuiLinearProgress-root');
184
+ expect(progress).toHaveStyle({ opacity: '0' });
185
+ });
186
+ });
187
+ });
188
+ // -------------------------------------------------------------------------
189
+ // Hit rendering
190
+ // -------------------------------------------------------------------------
191
+ describe('hit rendering', () => {
192
+ it('renders unresolved hits with checkboxes after loading', async () => {
193
+ render(_jsx(ResolveModal, { case: caseWithHits(['hit-1', 'hit-2']), onConfirm: mockOnConfirm }), {
194
+ wrapper: createWrapper({ 'hit-1': HIT_1, 'hit-2': HIT_2 })
195
+ });
196
+ await waitFor(() => {
197
+ expect(screen.getAllByRole('checkbox')).toHaveLength(2);
198
+ });
199
+ });
200
+ it('does not show a checkbox for resolved hits', async () => {
201
+ render(_jsx(ResolveModal, { case: caseWithHits(['hit-1', 'hit-resolved']), onConfirm: mockOnConfirm }), {
202
+ wrapper: createWrapper({ 'hit-1': HIT_1, 'hit-resolved': HIT_RESOLVED })
203
+ });
204
+ await waitFor(() => {
205
+ // only the single unresolved hit gets a checkbox
206
+ expect(screen.getAllByRole('checkbox')).toHaveLength(1);
207
+ });
208
+ });
209
+ it('calls loadRecords with the API search results', async () => {
210
+ const items = [HIT_1];
211
+ mockDispatchApi.mockResolvedValueOnce({ items });
212
+ render(_jsx(ResolveModal, { case: caseWithHits(['hit-1']), onConfirm: mockOnConfirm }), {
213
+ wrapper: createWrapper()
214
+ });
215
+ await waitFor(() => {
216
+ expect(mockLoadRecords).toHaveBeenCalledWith(items);
217
+ });
218
+ });
219
+ });
220
+ // -------------------------------------------------------------------------
221
+ // Confirm button disabled states
222
+ // -------------------------------------------------------------------------
223
+ describe('confirm button enablement', () => {
224
+ it('is disabled when no hits are selected', async () => {
225
+ render(_jsx(ResolveModal, { case: caseWithHits(['hit-1']), onConfirm: mockOnConfirm }), {
226
+ wrapper: createWrapper({ 'hit-1': HIT_1 })
227
+ });
228
+ // Wait for the hit to load (checkbox appears) but don't select it
229
+ await screen.findAllByRole('checkbox');
230
+ await fillForm(user);
231
+ // No hit selected → selectedHitIds.size === 0 → button still disabled
232
+ expect(screen.getByRole('button', { name: i18n.t('confirm') })).toBeDisabled();
233
+ });
234
+ it('is disabled when assessment is missing', async () => {
235
+ render(_jsx(ResolveModal, { case: caseWithHits(['hit-1']), onConfirm: mockOnConfirm }), {
236
+ wrapper: createWrapper({ 'hit-1': HIT_1 })
237
+ });
238
+ const [checkbox] = await screen.findAllByRole('checkbox');
239
+ clickCheckbox(checkbox);
240
+ await waitFor(() => expect(checkbox).toBeChecked());
241
+ const rationaleInput = screen.getByPlaceholderText(i18n.t('modal.rationale.label'));
242
+ await user.type(rationaleInput, 'some reason');
243
+ // no assessment chosen → still disabled
244
+ expect(screen.getByRole('button', { name: i18n.t('confirm') })).toBeDisabled();
245
+ });
246
+ it('is disabled when rationale is empty', async () => {
247
+ render(_jsx(ResolveModal, { case: caseWithHits(['hit-1']), onConfirm: mockOnConfirm }), {
248
+ wrapper: createWrapper({ 'hit-1': HIT_1 })
249
+ });
250
+ const [checkbox] = await screen.findAllByRole('checkbox');
251
+ clickCheckbox(checkbox);
252
+ await waitFor(() => expect(checkbox).toBeChecked());
253
+ // fill only assessment, no rationale
254
+ const assessmentInput = screen.getByRole('combobox');
255
+ await user.type(assessmentInput, 'leg');
256
+ const option = await screen.findByRole('option', { name: 'legitimate' });
257
+ await user.click(option);
258
+ expect(screen.getByRole('button', { name: i18n.t('confirm') })).toBeDisabled();
259
+ });
260
+ it('is enabled when a hit is selected + assessment + rationale are provided', async () => {
261
+ render(_jsx(ResolveModal, { case: caseWithHits(['hit-1']), onConfirm: mockOnConfirm }), {
262
+ wrapper: createWrapper({ 'hit-1': HIT_1 })
263
+ });
264
+ const [checkbox] = await screen.findAllByRole('checkbox');
265
+ clickCheckbox(checkbox);
266
+ await waitFor(() => expect(checkbox).toBeChecked());
267
+ await fillForm(user);
268
+ expect(screen.getByRole('button', { name: i18n.t('confirm') })).toBeEnabled();
269
+ });
270
+ });
271
+ // -------------------------------------------------------------------------
272
+ // Checkbox / selection toggling
273
+ // -------------------------------------------------------------------------
274
+ describe('hit selection', () => {
275
+ it('checks a hit when its checkbox is clicked', async () => {
276
+ render(_jsx(ResolveModal, { case: caseWithHits(['hit-1']), onConfirm: mockOnConfirm }), {
277
+ wrapper: createWrapper({ 'hit-1': HIT_1 })
278
+ });
279
+ const [checkbox] = await screen.findAllByRole('checkbox');
280
+ expect(checkbox).not.toBeChecked();
281
+ clickCheckbox(checkbox);
282
+ await waitFor(() => expect(checkbox).toBeChecked());
283
+ });
284
+ it('unchecks a hit when its checkbox is clicked a second time', async () => {
285
+ render(_jsx(ResolveModal, { case: caseWithHits(['hit-1']), onConfirm: mockOnConfirm }), {
286
+ wrapper: createWrapper({ 'hit-1': HIT_1 })
287
+ });
288
+ const [checkbox] = await screen.findAllByRole('checkbox');
289
+ clickCheckbox(checkbox);
290
+ await waitFor(() => expect(checkbox).toBeChecked());
291
+ clickCheckbox(checkbox);
292
+ await waitFor(() => expect(checkbox).not.toBeChecked());
293
+ });
294
+ it('tracks each hit independently when there are multiple', async () => {
295
+ render(_jsx(ResolveModal, { case: caseWithHits(['hit-1', 'hit-2']), onConfirm: mockOnConfirm }), {
296
+ wrapper: createWrapper({ 'hit-1': HIT_1, 'hit-2': HIT_2 })
297
+ });
298
+ const checkboxes = await screen.findAllByRole('checkbox');
299
+ expect(checkboxes).toHaveLength(2);
300
+ clickCheckbox(checkboxes[0]);
301
+ await waitFor(() => {
302
+ expect(checkboxes[0]).toBeChecked();
303
+ expect(checkboxes[1]).not.toBeChecked();
304
+ });
305
+ });
306
+ });
307
+ // -------------------------------------------------------------------------
308
+ // Confirm action
309
+ // -------------------------------------------------------------------------
310
+ describe('confirm action', () => {
311
+ it('calls assess with the chosen assessment, true, and rationale', async () => {
312
+ render(_jsx(ResolveModal, { case: caseWithHits(['hit-1']), onConfirm: mockOnConfirm }), {
313
+ wrapper: createWrapper({ 'hit-1': HIT_1 })
314
+ });
315
+ const [checkbox] = await screen.findAllByRole('checkbox');
316
+ clickCheckbox(checkbox);
317
+ await waitFor(() => expect(checkbox).toBeChecked());
318
+ await fillForm(user, 'legitimate', 'My rationale');
319
+ await user.click(screen.getByRole('button', { name: i18n.t('confirm') }));
320
+ await waitFor(() => {
321
+ expect(mockAssess).toHaveBeenCalledWith('legitimate', true, 'My rationale');
322
+ });
323
+ });
324
+ it('clears the selection after confirm completes', async () => {
325
+ render(_jsx(ResolveModal, { case: caseWithHits(['hit-1']), onConfirm: mockOnConfirm }), {
326
+ wrapper: createWrapper({ 'hit-1': HIT_1 })
327
+ });
328
+ const [checkbox] = await screen.findAllByRole('checkbox');
329
+ clickCheckbox(checkbox);
330
+ await waitFor(() => expect(checkbox).toBeChecked());
331
+ await fillForm(user);
332
+ await user.click(screen.getByRole('button', { name: i18n.t('confirm') }));
333
+ await waitFor(() => {
334
+ expect(checkbox).not.toBeChecked();
335
+ });
336
+ });
337
+ });
338
+ // -------------------------------------------------------------------------
339
+ // Cancel button
340
+ // -------------------------------------------------------------------------
341
+ describe('cancel button', () => {
342
+ it('calls close() when cancel is clicked', async () => {
343
+ // Use a case with an unresolved hit so the auto-resolve effect does not fire
344
+ // and call close() before we even click cancel.
345
+ render(_jsx(ResolveModal, { case: caseWithHits(['hit-1']), onConfirm: mockOnConfirm }), {
346
+ wrapper: createWrapper({ 'hit-1': HIT_1 })
347
+ });
348
+ // Wait for loading to finish so no unexpected state transitions happen mid-click
349
+ await screen.findAllByRole('checkbox');
350
+ await user.click(screen.getByRole('button', { name: i18n.t('cancel') }));
351
+ expect(mockClose).toHaveBeenCalledTimes(1);
352
+ });
353
+ });
354
+ // -------------------------------------------------------------------------
355
+ // Auto-resolve when all hits are already resolved
356
+ // -------------------------------------------------------------------------
357
+ describe('auto-resolve', () => {
358
+ it('calls updateCase, onConfirm, and close when no unresolved hits remain after loading', async () => {
359
+ // All hits in the case are already resolved
360
+ render(_jsx(ResolveModal, { case: caseWithHits(['hit-resolved']), onConfirm: mockOnConfirm }), {
361
+ wrapper: createWrapper({ 'hit-resolved': HIT_RESOLVED })
362
+ });
363
+ // dispatchApi resolves → loading becomes false → unresolvedHits.length === 0 → auto-close
364
+ await waitFor(() => {
365
+ expect(mockUpdateCase).toHaveBeenCalledWith({ status: 'resolved' });
366
+ });
367
+ await waitFor(() => {
368
+ expect(mockOnConfirm).toHaveBeenCalledTimes(1);
369
+ expect(mockClose).toHaveBeenCalledTimes(1);
370
+ });
371
+ });
372
+ it('does NOT auto-resolve while hits are still unresolved', async () => {
373
+ render(_jsx(ResolveModal, { case: caseWithHits(['hit-1']), onConfirm: mockOnConfirm }), {
374
+ wrapper: createWrapper({ 'hit-1': HIT_1 })
375
+ });
376
+ // Wait for loading to complete: the unresolved hit's checkbox appears once the
377
+ // dispatchApi call settles and the LinearProgress opacity drops to 0.
378
+ await screen.findAllByRole('checkbox');
379
+ // Should not have auto-resolved
380
+ expect(mockUpdateCase).not.toHaveBeenCalled();
381
+ expect(mockClose).not.toHaveBeenCalled();
382
+ });
383
+ });
384
+ });
@@ -315,6 +315,7 @@
315
315
  "modal.cases.add_to_case.select_case": "Search Cases",
316
316
  "modal.cases.add_to_case.select_path": "Select Folder Path",
317
317
  "modal.cases.add_to_case.title": "Item Title",
318
+ "modal.cases.alerts.resolved": "Resolved Alerts",
318
319
  "modal.cases.rename_item": "Rename Item",
319
320
  "modal.cases.rename_item.error.empty": "Name cannot be empty",
320
321
  "modal.cases.rename_item.error.slash": "Name cannot contain '/'",
@@ -315,6 +315,7 @@
315
315
  "modal.cases.add_to_case.select_case": "Rechercher des cas",
316
316
  "modal.cases.add_to_case.select_path": "Sélectionner le chemin du dossier",
317
317
  "modal.cases.add_to_case.title": "Titre de l'élément",
318
+ "modal.cases.alerts.resolved": "Alertes résolues",
318
319
  "modal.cases.rename_item": "Renommer l'élément",
319
320
  "modal.cases.rename_item.error.empty": "Le nom ne peut pas être vide",
320
321
  "modal.cases.rename_item.error.slash": "Le nom ne peut pas contenir '/'",
package/package.json CHANGED
@@ -101,7 +101,7 @@
101
101
  "internal-slot": "1.0.7"
102
102
  },
103
103
  "type": "module",
104
- "version": "2.18.0-dev.710",
104
+ "version": "2.18.0-dev.716",
105
105
  "exports": {
106
106
  "./i18n": "./i18n.js",
107
107
  "./index.css": "./index.css",