• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CBIIT / bento-icdc-frontend / 26521483403

27 May 2026 03:36PM UTC coverage: 17.458% (-8.3%) from 25.73%
26521483403

Pull #1607

github

web-flow
Merge 2f30510ff into bc935f39c
Pull Request #1607: Feature/ai test studio - ICDC-4165 & ICDC-4171

306 of 2587 branches covered (11.83%)

Branch coverage included in aggregate %.

1 of 4244 new or added lines in 74 files covered. (0.02%)

2 existing lines in 2 files now uncovered.

2197 of 11750 relevant lines covered (18.7%)

0.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/components/sideBarFilter/BentoFilterUtils.generated.test.js
1
// src/components/sideBarFilter/BentoFilterUtils.test.js
2

3
import {
4
  getFacetValues,
5
  onClearAllAndSelectFacetValue,
6
  setActiveFilterByPathQuery,
7
  getAllIds,
8
  getAllSubjectIds,
9
} from './BentoFilterUtils';
10

11
// Mock store and action creators from bento-core
NEW
12
const mockDispatch = jest.fn();
×
13

NEW
14
jest.mock('../../store', () => ({
×
15
  __esModule: true,
16
  default: {
17
    dispatch: jest.fn(),
18
  },
19
}));
20

NEW
21
jest.mock('../../bento-core', () => ({
×
22
  __esModule: true,
NEW
23
  clearAllAndSelectFacet: jest.fn(payload => ({
×
24
    type: 'CLEAR_ALL_AND_SELECT_FACET',
25
    payload,
26
  })),
NEW
27
  updateAutocompleteData: jest.fn(payload => ({
×
28
    type: 'UPDATE_AUTOCOMPLETE',
29
    payload,
30
  })),
NEW
31
  updateUploadData: jest.fn(payload => ({
×
32
    type: 'UPDATE_UPLOAD',
33
    payload,
34
  })),
NEW
35
  updateUploadMetadata: jest.fn(payload => ({
×
36
    type: 'UPDATE_UPLOAD_METADATA',
37
    payload,
38
  })),
39
}));
40

41
// Mock GraphQL client and queries
NEW
42
jest.mock('../../utils/graphqlClient', () => ({
×
43
  __esModule: true,
44
  default: {
45
    query: jest.fn(),
46
  },
47
}));
48

NEW
49
jest.mock('../../bento/localSearchData', () => ({
×
50
  __esModule: true,
NEW
51
  GET_IDS_BY_TYPE: jest.fn(type => `QUERY_FOR_${type}`),
×
52
  GET_SUBJECT_IDS: 'GET_SUBJECT_IDS_QUERY',
53
}));
54

55
// Bring in the mocks for assertions
56
import store from '../../store';
57
import client from '../../utils/graphqlClient';
58
import {
59
  clearAllAndSelectFacet,
60
  updateAutocompleteData,
61
  updateUploadData,
62
  updateUploadMetadata,
63
} from '../../bento-core';
64
import { GET_IDS_BY_TYPE, GET_SUBJECT_IDS } from '../../bento/localSearchData';
65

NEW
66
describe('BentoFilterUtils', () => {
×
NEW
67
  beforeEach(() => {
×
NEW
68
    jest.clearAllMocks();
×
NEW
69
    store.dispatch = mockDispatch;
×
70
  });
71

NEW
72
  describe('getFacetValues', () => {
×
NEW
73
    it('should create a facet value map with true for given facet and value', () => {
×
NEW
74
      const result = getFacetValues('programs', 'P1');
×
NEW
75
      expect(result).toEqual({ programs: { P1: true } });
×
76
    });
77

NEW
78
    it('should handle facet values with special characters', () => {
×
NEW
79
      const result = getFacetValues('study-codes', 'STUDY/001');
×
NEW
80
      expect(result).toEqual({ 'study-codes': { 'STUDY/001': true } });
×
81
    });
82
  });
83

NEW
84
  describe('onClearAllAndSelectFacetValue', () => {
×
NEW
85
    it('should dispatch clearAllAndSelectFacet with computed filterValue', () => {
×
NEW
86
      const expectedFilter = { diagnoses: { Cancer: true } };
×
87

NEW
88
      onClearAllAndSelectFacetValue('diagnoses', 'Cancer');
×
89

NEW
90
      expect(clearAllAndSelectFacet).toHaveBeenCalledTimes(1);
×
NEW
91
      expect(clearAllAndSelectFacet).toHaveBeenCalledWith(expectedFilter);
×
92

NEW
93
      expect(store.dispatch).toHaveBeenCalledTimes(1);
×
NEW
94
      expect(store.dispatch).toHaveBeenCalledWith({
×
95
        type: 'CLEAR_ALL_AND_SELECT_FACET',
96
        payload: expectedFilter,
97
      });
98
    });
99
  });
100

NEW
101
  describe('setActiveFilterByPathQuery', () => {
×
NEW
102
    it('should dispatch actions with active filters, autocomplete, upload and metadata (happy path)', () => {
×
NEW
103
      const filterObject = {
×
104
        programs: ['P1', 'P2'],
105
        autocomplete: ['TermA'],
106
        upload: ['ID_1'],
107
        uploadMetadata: { foo: 'bar' },
108
        searchTerm: 'free text',
109
      };
NEW
110
      const encoded = encodeURIComponent(JSON.stringify(filterObject));
×
NEW
111
      const match = { params: { filterQuery: encoded } };
×
112

NEW
113
      setActiveFilterByPathQuery(match);
×
114

NEW
115
      expect(clearAllAndSelectFacet).toHaveBeenCalledTimes(1);
×
NEW
116
      expect(clearAllAndSelectFacet).toHaveBeenCalledWith({
×
117
        programs: { P1: true, P2: true },
118
        autocomplete: { TermA: true },
119
        upload: { ID_1: true },
120
      });
121

NEW
122
      expect(updateAutocompleteData).toHaveBeenCalledTimes(1);
×
NEW
123
      expect(updateAutocompleteData).toHaveBeenCalledWith(['TermA']);
×
124

NEW
125
      expect(updateUploadData).toHaveBeenCalledTimes(1);
×
NEW
126
      expect(updateUploadData).toHaveBeenCalledWith(['ID_1']);
×
127

NEW
128
      expect(updateUploadMetadata).toHaveBeenCalledTimes(1);
×
NEW
129
      expect(updateUploadMetadata).toHaveBeenCalledWith({ foo: 'bar' });
×
130

NEW
131
      expect(store.dispatch).toHaveBeenCalledTimes(4);
×
NEW
132
      expect(store.dispatch).toHaveBeenNthCalledWith(1, {
×
133
        type: 'CLEAR_ALL_AND_SELECT_FACET',
134
        payload: {
135
          programs: { P1: true, P2: true },
136
          autocomplete: { TermA: true },
137
          upload: { ID_1: true },
138
        },
139
      });
NEW
140
      expect(store.dispatch).toHaveBeenNthCalledWith(2, {
×
141
        type: 'UPDATE_AUTOCOMPLETE',
142
        payload: ['TermA'],
143
      });
NEW
144
      expect(store.dispatch).toHaveBeenNthCalledWith(3, {
×
145
        type: 'UPDATE_UPLOAD',
146
        payload: ['ID_1'],
147
      });
NEW
148
      expect(store.dispatch).toHaveBeenNthCalledWith(4, {
×
149
        type: 'UPDATE_UPLOAD_METADATA',
150
        payload: { foo: 'bar' },
151
      });
152
    });
153

NEW
154
    it('should set defaults for missing arrays and still dispatch (autocomplete/upload default to empty arrays, metadata undefined)', () => {
×
NEW
155
      const filterObject = {
×
156
        programs: ['OnlyP'],
157
      };
NEW
158
      const encoded = encodeURIComponent(JSON.stringify(filterObject));
×
NEW
159
      const match = { params: { filterQuery: encoded } };
×
160

NEW
161
      setActiveFilterByPathQuery(match);
×
162

NEW
163
      expect(clearAllAndSelectFacet).toHaveBeenCalledWith({
×
164
        programs: { OnlyP: true },
165
      });
NEW
166
      expect(updateAutocompleteData).toHaveBeenCalledWith([]);
×
NEW
167
      expect(updateUploadData).toHaveBeenCalledWith([]);
×
NEW
168
      expect(updateUploadMetadata).toHaveBeenCalledWith(undefined);
×
169

NEW
170
      expect(store.dispatch).toHaveBeenCalledTimes(4);
×
171
    });
172

NEW
173
    it('throws error if filterQuery is missing or invalid JSON', () => {
×
NEW
174
      const matchMissing = { params: { filterQuery: undefined } };
×
NEW
175
      expect(() => setActiveFilterByPathQuery(matchMissing)).toThrow(
×
176
        SyntaxError
177
      );
178

NEW
179
      const bad = encodeURIComponent('not-json');
×
NEW
180
      const matchBad = { params: { filterQuery: bad } };
×
NEW
181
      expect(() => setActiveFilterByPathQuery(matchBad)).toThrow(SyntaxError);
×
182
    });
183
  });
184

NEW
185
  describe('getAllIds', () => {
×
NEW
186
    it('should request ids by type and return flattened values (happy path)', async () => {
×
NEW
187
      const type = 'case_id';
×
NEW
188
      const mockData = {
×
189
        data: {
190
          caseOverview: [{ case_id: 'C1' }, { case_id: 'C2' }],
191
        },
192
      };
NEW
193
      client.query.mockResolvedValueOnce(mockData);
×
194

NEW
195
      const result = await getAllIds(type);
×
196

NEW
197
      expect(GET_IDS_BY_TYPE).toHaveBeenCalledWith(type);
×
NEW
198
      expect(client.query).toHaveBeenCalledWith({
×
199
        query: 'QUERY_FOR_case_id',
200
        variables: {},
201
      });
NEW
202
      expect(result).toEqual(['C1', 'C2']);
×
203
    });
204

NEW
205
    it('should return empty array when client.query rejects', async () => {
×
NEW
206
      client.query.mockRejectedValueOnce(new Error('Network error'));
×
207

NEW
208
      const result = await getAllIds('sample_id');
×
209

NEW
210
      expect(result).toEqual([]);
×
211
    });
212

NEW
213
    it('should map to possibly undefined when items do not contain the type key', async () => {
×
NEW
214
      client.query.mockResolvedValueOnce({
×
215
        data: { caseOverview: [{ other: 'x' }] },
216
      });
217

NEW
218
      const result = await getAllIds('missing_key');
×
219

NEW
220
      expect(result).toEqual([undefined]);
×
221
    });
222
  });
223

NEW
224
  describe('getAllSubjectIds', () => {
×
NEW
225
    it('should request subject ids and return caseOverview array (happy path)', async () => {
×
NEW
226
      const inputIds = ['S1', 'S2'];
×
NEW
227
      const mockData = {
×
228
        data: {
229
          caseOverview: [
230
            { case_id: 'S1', study_code: 'A' },
231
            { case_id: 'S2', study_code: 'B' },
232
          ],
233
        },
234
      };
NEW
235
      client.query.mockResolvedValueOnce(mockData);
×
236

NEW
237
      const result = await getAllSubjectIds(inputIds);
×
238

NEW
239
      expect(client.query).toHaveBeenCalledWith({
×
240
        query: GET_SUBJECT_IDS,
241
        variables: { case_ids: inputIds },
242
      });
NEW
243
      expect(result).toEqual(mockData.data.caseOverview);
×
244
    });
245

NEW
246
    it('should return empty array when client.query rejects', async () => {
×
NEW
247
      client.query.mockRejectedValueOnce(new Error('Boom'));
×
248

NEW
249
      const result = await getAllSubjectIds(['X']);
×
250

NEW
251
      expect(result).toEqual([]);
×
252
    });
253

NEW
254
    it('should handle empty input list by still calling with empty array', async () => {
×
NEW
255
      const mockData = { data: { caseOverview: [] } };
×
NEW
256
      client.query.mockResolvedValueOnce(mockData);
×
257

NEW
258
      const result = await getAllSubjectIds([]);
×
259

NEW
260
      expect(client.query).toHaveBeenCalledWith({
×
261
        query: GET_SUBJECT_IDS,
262
        variables: { case_ids: [] },
263
      });
NEW
264
      expect(result).toEqual([]);
×
265
    });
266
  });
267
});
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc