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

CBIIT / bento-icdc-frontend / 26530955228

27 May 2026 06:34PM UTC coverage: 17.321% (-8.4%) from 25.73%
26530955228

Pull #1607

github

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

306 of 2599 branches covered (11.77%)

Branch coverage included in aggregate %.

1 of 4346 new or added lines in 75 files covered. (0.02%)

2 existing lines in 2 files now uncovered.

2197 of 11852 relevant lines covered (18.54%)

0.41 hits per line

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

0.0
/src/components/DataAvailabilityTable/StudiesTable.generated.test.tsx
1
// src/components/DataAvailabilityTable/StudiesTable.generated.test.tsx
2

NEW
3
import React from 'react';
×
NEW
4
import { render } from '@testing-library/react';
×
NEW
5
import StudiesTable from './StudiesTable';
×
NEW
6
import PaginatedTableView from '../PaginatedTable/TableView';
×
NEW
7
import { TableContext } from '../../bento-core';
×
NEW
8
import { themeConfig } from './tableThemeConfig';
×
9
import type {
10
  TableConfig as TableConfigPD,
11
  TableLayoutItem,
12
} from '../../bento/programDetailData';
13
import type { StudyOfProgram } from '../../generated-types/types';
14

NEW
15
jest.mock('../PaginatedTable/TableView', () => ({
×
16
  __esModule: true,
NEW
17
  default: jest.fn(() => null),
×
18
}));
19

NEW
20
jest.mock('./tableThemeConfig', () => ({
×
21
  __esModule: true,
22
  themeConfig: jest.fn(),
23
}));
24

NEW
25
jest.mock('../../bento-core', () => {
×
NEW
26
  const React = jest.requireActual<typeof import('react')>('react');
×
27

28
  type StudiesTableContextValue = {
29
    title: string;
30
    name: string;
31
    api: string;
32
    paginationAPIField: string;
33
    dataKey: string;
34
    columns: unknown[];
35
    tableMsg: {
36
      noMatch: string;
37
    };
38
    defaultSortField: string;
39
    defaultSortDirection: string;
40
    columnGroups: unknown[];
41
    count: number;
42
    dispatch: jest.Mock;
43
    filters: unknown[];
44
    sort: {
45
      field: string;
46
      direction: string;
47
    };
48
    searchText: string;
49
    selectedRows: unknown[];
50
    loading: boolean;
51
    page: number;
52
    pageSize: number;
53
    total: number;
54
    showPagination: boolean;
55
    showSearch: boolean;
56
  };
57

58
  type TableContextValue = {
59
    context: StudiesTableContextValue;
60
  };
61

NEW
62
  return {
×
63
    __esModule: true,
64
    TableContext: React.createContext<TableContextValue>({
65
      context: {
66
        title: '',
67
        name: '',
68
        api: '',
69
        paginationAPIField: '',
70
        dataKey: '',
71
        columns: [],
72
        tableMsg: { noMatch: '' },
73
        defaultSortField: '',
74
        defaultSortDirection: '',
75
        columnGroups: [],
76
        count: 0,
77
        dispatch: jest.fn(),
78
        filters: [],
79
        sort: {
80
          field: '',
81
          direction: '',
82
        },
83
        searchText: '',
84
        selectedRows: [],
85
        loading: false,
86
        page: 0,
87
        pageSize: 0,
88
        total: 0,
89
        showPagination: false,
90
        showSearch: false,
91
      },
92
    }),
93
  };
94
});
95

96
type ThemeConfigResult = Record<string, unknown>;
97

98
interface StudiesTableContextValue {
99
  title: string;
100
  name: string;
101
  api: string;
102
  paginationAPIField: string;
103
  dataKey: string;
104
  columns: unknown[];
105
  tableMsg: {
106
    noMatch: string;
107
  };
108
  defaultSortField: string;
109
  defaultSortDirection: string;
110
  columnGroups: unknown[];
111
  count: number;
112
  dispatch: jest.Mock;
113
  filters: unknown[];
114
  sort: {
115
    field: string;
116
    direction: string;
117
  };
118
  searchText: string;
119
  selectedRows: unknown[];
120
  loading: boolean;
121
  page: number;
122
  pageSize: number;
123
  total: number;
124
  showPagination: boolean;
125
  showSearch: boolean;
126
}
127

128
interface PaginatedTableViewProps {
129
  isServer: boolean;
130
  tblRows: StudyOfProgram[];
131
  config: TableConfigPD;
132
  tableLayOut: TableLayoutItem[];
133
  totalRowCount: number;
134
  customthemeConfig: Record<string, unknown>;
135
  rowsPerPage?: number;
136
}
137

138
type TableContextValue = {
139
  context: StudiesTableContextValue;
140
};
141

NEW
142
const mockedPaginatedTableView = PaginatedTableView as unknown as jest.Mock;
×
NEW
143
const mockedThemeConfig = themeConfig as unknown as jest.Mock;
×
NEW
144
const TypedTableContext = TableContext as React.Context<TableContextValue>;
×
145

NEW
146
describe('StudiesTable', () => {
×
NEW
147
  const baseContext: StudiesTableContextValue = {
×
148
    title: 'Studies Table',
149
    name: 'Studies',
150
    api: 'QUERY_STUDIES',
151
    paginationAPIField: 'studies',
152
    dataKey: 'study_id',
153
    columns: [],
154
    tableMsg: { noMatch: 'No records found' },
155
    defaultSortField: 'study_name',
156
    defaultSortDirection: 'asc',
157
    columnGroups: [],
158
    count: 0,
159
    dispatch: jest.fn(),
160
    filters: [],
161
    sort: { field: 'study_name', direction: 'asc' },
162
    searchText: '',
163
    selectedRows: [],
164
    loading: false,
165
    page: 1,
166
    pageSize: 10,
167
    total: 0,
168
    showPagination: true,
169
    showSearch: true,
170
  };
171

NEW
172
  const baseTableConfig = {
×
173
    title: 'Studies Table',
174
    name: 'Studies',
175
    api: 'QUERY_STUDIES',
176
    paginationAPIField: 'studies',
177
    dataKey: 'study_id',
178
    columns: [],
179
    tableMsg: { noMatch: 'No records found' },
180
    defaultSortField: 'study_name',
181
    defaultSortDirection: 'asc',
182
    columnGroups: [],
183
    count: 0,
184
    dispatch: jest.fn(),
185
    filters: [],
186
    sort: { field: 'study_name', direction: 'asc' },
187
    searchText: '',
188
    selectedRows: [],
189
    loading: false,
190
    page: 1,
191
    pageSize: 10,
192
    total: 0,
193
    showPagination: true,
194
    showSearch: true,
195
  } as unknown as TableConfigPD;
196

NEW
197
  const tableLayout = [{ section: 'body' }] as unknown as TableLayoutItem[];
×
198

NEW
199
  const buildStudy = (id: string, name: string): StudyOfProgram =>
×
NEW
200
    ({
×
201
      study_id: id,
202
      study_name: name,
203
    }) as StudyOfProgram;
204

NEW
205
  const renderStudiesTable = (
×
206
    ctxValue: StudiesTableContextValue,
207
    ui: React.ReactElement
208
  ): ReturnType<typeof render> =>
NEW
209
    render(
×
210
      <TypedTableContext.Provider value={{ context: ctxValue }}>
211
        {ui}
212
      </TypedTableContext.Provider>
213
    );
214

NEW
215
  const getRenderedProps = (): PaginatedTableViewProps => {
×
NEW
216
    const firstCall = mockedPaginatedTableView.mock.calls[0] as
×
217
      | [PaginatedTableViewProps]
218
      | undefined;
NEW
219
    if (!firstCall) {
×
NEW
220
      throw new Error('PaginatedTableView was not called');
×
221
    }
222

NEW
223
    return firstCall[0];
×
224
  };
225

NEW
226
  beforeEach(() => {
×
NEW
227
    jest.clearAllMocks();
×
228

NEW
229
    mockedPaginatedTableView.mockImplementation(() => null);
×
230

NEW
231
    mockedThemeConfig.mockImplementation(
×
NEW
232
      (context: StudiesTableContextValue): ThemeConfigResult => ({
×
233
        themeFromTitle: context.title,
234
        themeFromName: context.name,
235
        themeFromApi: context.api,
236
        themeFromPaginationField: context.paginationAPIField,
237
        themeFromDataKey: context.dataKey,
238
        themeFromSortField: context.defaultSortField,
239
        themeFromSortDirection: context.defaultSortDirection,
240
        themeFromPage: context.page,
241
        themeFromPageSize: context.pageSize,
242
        themeFromTotal: context.total,
243
      })
244
    );
245
  });
246

NEW
247
  it('renders PaginatedTableView with derived props from data and context', () => {
×
NEW
248
    const ctx: StudiesTableContextValue = {
×
249
      ...baseContext,
250
    };
251

NEW
252
    const data: StudyOfProgram[] = [
×
253
      buildStudy('S1', 'Study 1'),
254
      buildStudy('S2', 'Study 2'),
255
    ];
256

NEW
257
    renderStudiesTable(
×
258
      ctx,
259
      <StudiesTable
260
        table={baseTableConfig}
261
        tableLayOut={tableLayout}
262
        data={data}
263
        rowsPerPage={25}
264
      />
265
    );
266

NEW
267
    expect(mockedThemeConfig).toHaveBeenCalledTimes(1);
×
NEW
268
    expect(mockedThemeConfig).toHaveBeenCalledWith(ctx);
×
269

NEW
270
    expect(mockedPaginatedTableView).toHaveBeenCalledTimes(1);
×
271

NEW
272
    const props = getRenderedProps();
×
273

NEW
274
    expect(props.isServer).toBe(false);
×
NEW
275
    expect(props.tblRows).toEqual(data);
×
NEW
276
    expect(props.config).toEqual(baseTableConfig);
×
NEW
277
    expect(props.tableLayOut).toEqual(tableLayout);
×
NEW
278
    expect(props.totalRowCount).toBe(2);
×
NEW
279
    expect(props.rowsPerPage).toBe(25);
×
NEW
280
    expect(props.customthemeConfig).toEqual({
×
281
      themeFromTitle: 'Studies Table',
282
      themeFromName: 'Studies',
283
      themeFromApi: 'QUERY_STUDIES',
284
      themeFromPaginationField: 'studies',
285
      themeFromDataKey: 'study_id',
286
      themeFromSortField: 'study_name',
287
      themeFromSortDirection: 'asc',
288
      themeFromPage: 1,
289
      themeFromPageSize: 10,
290
      themeFromTotal: 0,
291
    });
292
  });
293

NEW
294
  it('sets totalRowCount to 0 and passes empty rows when data is empty', () => {
×
NEW
295
    const ctx: StudiesTableContextValue = {
×
296
      ...baseContext,
297
    };
298

NEW
299
    renderStudiesTable(
×
300
      ctx,
301
      <StudiesTable
302
        table={baseTableConfig}
303
        tableLayOut={tableLayout}
304
        data={[]}
305
      />
306
    );
307

NEW
308
    const props = getRenderedProps();
×
309

NEW
310
    expect(props.tblRows).toEqual([]);
×
NEW
311
    expect(props.totalRowCount).toBe(0);
×
NEW
312
    expect(props.rowsPerPage).toBeUndefined();
×
NEW
313
    expect(props.customthemeConfig).toEqual({
×
314
      themeFromTitle: 'Studies Table',
315
      themeFromName: 'Studies',
316
      themeFromApi: 'QUERY_STUDIES',
317
      themeFromPaginationField: 'studies',
318
      themeFromDataKey: 'study_id',
319
      themeFromSortField: 'study_name',
320
      themeFromSortDirection: 'asc',
321
      themeFromPage: 1,
322
      themeFromPageSize: 10,
323
      themeFromTotal: 0,
324
    });
325
  });
326

NEW
327
  it('passes updated context values into themeConfig', () => {
×
NEW
328
    const ctx: StudiesTableContextValue = {
×
329
      ...baseContext,
330
      title: 'Studies Table',
331
      name: 'Studies',
332
      api: 'QUERY_STUDIES',
333
      paginationAPIField: 'studies',
334
      dataKey: 'study_id',
335
      columns: [{ dataField: 'study_name' }],
336
      tableMsg: { noMatch: 'No records found' },
337
      defaultSortField: 'study_name',
338
      defaultSortDirection: 'desc',
339
      columnGroups: ['group-a'],
340
      count: 7,
341
      dispatch: jest.fn(),
342
      filters: ['filter-a'],
343
      sort: { field: 'study_name', direction: 'desc' },
344
      searchText: 'abc',
345
      selectedRows: ['S1'],
346
      loading: true,
347
      page: 3,
348
      pageSize: 20,
349
      total: 100,
350
      showPagination: true,
351
      showSearch: false,
352
    };
353

NEW
354
    mockedThemeConfig.mockImplementation(
×
NEW
355
      (context: StudiesTableContextValue): ThemeConfigResult => ({
×
356
        title: context.title,
357
        name: context.name,
358
        api: context.api,
359
        paginationAPIField: context.paginationAPIField,
360
        dataKey: context.dataKey,
361
        columns: context.columns,
362
        tableMsg: context.tableMsg,
363
        defaultSortField: context.defaultSortField,
364
        defaultSortDirection: context.defaultSortDirection,
365
        columnGroups: context.columnGroups,
366
        count: context.count,
367
        filters: context.filters,
368
        sort: context.sort,
369
        searchText: context.searchText,
370
        selectedRows: context.selectedRows,
371
        loading: context.loading,
372
        page: context.page,
373
        pageSize: context.pageSize,
374
        total: context.total,
375
        showPagination: context.showPagination,
376
        showSearch: context.showSearch,
377
      })
378
    );
379

NEW
380
    renderStudiesTable(
×
381
      ctx,
382
      <StudiesTable
383
        table={baseTableConfig}
384
        tableLayOut={tableLayout}
385
        data={[buildStudy('S1', 'Study 1')]}
386
        rowsPerPage={10}
387
      />
388
    );
389

NEW
390
    const props = getRenderedProps();
×
391

NEW
392
    expect(props.customthemeConfig).toEqual({
×
393
      title: 'Studies Table',
394
      name: 'Studies',
395
      api: 'QUERY_STUDIES',
396
      paginationAPIField: 'studies',
397
      dataKey: 'study_id',
398
      columns: [{ dataField: 'study_name' }],
399
      tableMsg: { noMatch: 'No records found' },
400
      defaultSortField: 'study_name',
401
      defaultSortDirection: 'desc',
402
      columnGroups: ['group-a'],
403
      count: 7,
404
      filters: ['filter-a'],
405
      sort: { field: 'study_name', direction: 'desc' },
406
      searchText: 'abc',
407
      selectedRows: ['S1'],
408
      loading: true,
409
      page: 3,
410
      pageSize: 20,
411
      total: 100,
412
      showPagination: true,
413
      showSearch: false,
414
    });
415
  });
416
});
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