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

CBIIT / bento-icdc-frontend / 26531437966

27 May 2026 06:43PM UTC coverage: 17.253% (-8.5%) from 25.73%
26531437966

Pull #1607

github

web-flow
Merge 8713d05ca 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 4403 new or added lines in 76 files covered. (0.02%)

2 existing lines in 2 files now uncovered.

2197 of 11909 relevant lines covered (18.45%)

0.41 hits per line

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

0.0
/src/components/header/HeaderView.generated.test.js
1
import React from 'react';
2
import { render, screen } from '@testing-library/react';
3
import ICDCHeader from './HeaderView';
4
import headerData from '../../bento/globalHeaderData';
5
import { SEARCH_PUBLIC } from '../../bento/search';
6

NEW
7
const mockReact = jest.requireActual('react');
×
NEW
8
const mockUseLocation = jest.fn();
×
NEW
9
const mockClientQuery = jest.fn().mockResolvedValue({
×
10
  data: {
11
    globalSearch: {
12
      programs: [{ program_acronym: 'ABC' }],
13
      studies: [],
14
      cases: [],
15
      samples: [],
16
      files: [],
17
      model: [],
18
    },
19
  },
20
});
21

NEW
22
let lastHeaderProps = null;
×
23
let consoleErrorSpy;
24

NEW
25
const mockSearchBarGenerator = jest.fn(config => {
×
NEW
26
  const SearchBar = () =>
×
NEW
27
    mockReact.createElement('div', { 'data-testid': 'searchbar-stub' });
×
28

NEW
29
  return { SearchBar, config };
×
30
});
31

NEW
32
jest.mock('react-router', () => ({
×
NEW
33
  useLocation: () => mockUseLocation(),
×
34
}));
35

NEW
36
jest.mock('@material-ui/core', () => ({
×
37
  Grid: ({ children, container }) =>
NEW
38
    mockReact.createElement(
×
39
      'div',
40
      { 'data-testid': 'grid', 'data-container': container ? 'true' : 'false' },
×
41
      children
42
    ),
NEW
43
  withStyles: () => arg => arg,
×
44
}));
45

NEW
46
jest.mock('../../bento-core', () => ({
×
47
  Header: props => {
NEW
48
    lastHeaderProps = props;
×
49

NEW
50
    return mockReact.createElement(
×
51
      'div',
52
      { 'data-testid': 'header' },
53
      props.SearchComponent
×
54
        ? mockReact.createElement(props.SearchComponent, {
55
            'data-testid': 'search-component',
56
          })
57
        : null
58
    );
59
  },
60
}));
61

NEW
62
jest.mock('./HeaderTheme', () => ({
×
63
  __esModule: true,
64
  default: ({ children }) =>
NEW
65
    mockReact.createElement(mockReact.Fragment, null, children),
×
66
}));
67

NEW
68
jest.mock('./SearchInput', () => ({
×
69
  __esModule: true,
70
  default: () =>
NEW
71
    mockReact.createElement('input', { 'data-testid': 'search-input' }),
×
72
}));
73

NEW
74
jest.mock('@bento-core/global-search', () => ({
×
NEW
75
  SearchBarGenerator: (...args) => mockSearchBarGenerator(...args),
×
76
}));
77

NEW
78
jest.mock('../../utils/graphqlClient', () => ({
×
79
  __esModule: true,
NEW
80
  default: { query: (...args) => mockClientQuery(...args) },
×
81
}));
82

NEW
83
jest.mock('../../bento/globalHeaderData', () => ({
×
84
  __esModule: true,
85
  default: {
86
    globalHeaderLogo:
87
      'https://raw.githubusercontent.com/CBIIT/datacommons-assets/master/icdc/images/svgs/icdc_nih_logo.svg',
88
    globalHeaderLogoLink: '/',
89
    globalHeaderLogoAltText: 'ICDC Logo',
90
    globalHeaderImage:
91
      'https://raw.githubusercontent.com/CBIIT/datacommons-assets/master/icdc/images/png/header_Canine3000.png',
92
  },
93
}));
94

NEW
95
describe('ICDCHeader', () => {
×
NEW
96
  beforeEach(() => {
×
NEW
97
    consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
×
98
  });
99

NEW
100
  afterEach(() => {
×
NEW
101
    jest.clearAllMocks();
×
NEW
102
    lastHeaderProps = null;
×
103

NEW
104
    if (consoleErrorSpy) {
×
NEW
105
      consoleErrorSpy.mockRestore();
×
NEW
106
      consoleErrorSpy = null;
×
107
    }
108
  });
109

NEW
110
  const renderWithPath = pathname => {
×
NEW
111
    mockUseLocation.mockReturnValue({ pathname });
×
NEW
112
    return render(<ICDCHeader />);
×
113
  };
114

NEW
115
  test('renders themed Header with SearchComponent on non-jBrowse and non-search routes', () => {
×
NEW
116
    renderWithPath('/');
×
117

NEW
118
    expect(screen.getByTestId('grid')).toBeTruthy();
×
NEW
119
    expect(lastHeaderProps).toBeTruthy();
×
NEW
120
    expect(lastHeaderProps.logo).toBe(headerData.globalHeaderLogo);
×
NEW
121
    expect(lastHeaderProps.alt).toBe(headerData.globalHeaderLogoAltText);
×
NEW
122
    expect(lastHeaderProps.homeLink).toBe(headerData.globalHeaderLogoLink);
×
NEW
123
    expect(lastHeaderProps.noLink).toBeUndefined();
×
NEW
124
    expect(lastHeaderProps.customStyle).toBeTruthy();
×
NEW
125
    expect(lastHeaderProps.customStyle.headerBar).toEqual({
×
126
      top: '0px',
127
      zIndex: '600',
128
      position: 'relative',
129
    });
NEW
130
    expect(typeof lastHeaderProps.SearchComponent).toBe('function');
×
131

NEW
132
    expect(screen.getByTestId('searchbar-stub')).toBeTruthy();
×
133

NEW
134
    expect(mockSearchBarGenerator).toHaveBeenCalledTimes(1);
×
NEW
135
    const searchBarConfig = mockSearchBarGenerator.mock.calls[0][0];
×
NEW
136
    expect(searchBarConfig.config.placeholder).toBe('SEARCH THE ICDC');
×
NEW
137
    expect(searchBarConfig.config.searchKeys).toBeDefined();
×
NEW
138
    expect(searchBarConfig.config.searchFields).toBeDefined();
×
NEW
139
    expect(typeof searchBarConfig.config.inputComponent).toBe('function');
×
NEW
140
    expect(typeof searchBarConfig.classes).toBe('function');
×
141
  });
142

NEW
143
  test('does not pass SearchComponent when route matches /search', () => {
×
NEW
144
    renderWithPath('/search');
×
145

NEW
146
    expect(screen.getByTestId('grid')).toBeTruthy();
×
NEW
147
    expect(lastHeaderProps).toBeTruthy();
×
NEW
148
    expect(lastHeaderProps.SearchComponent).toBeUndefined();
×
NEW
149
    expect(screen.queryByTestId('searchbar-stub')).toBeNull();
×
150
  });
151

NEW
152
  test('renders bare Header with noLink on /jBrowse routes', () => {
×
NEW
153
    renderWithPath('/jBrowse/somewhere');
×
154

NEW
155
    expect(screen.queryByTestId('grid')).toBeNull();
×
NEW
156
    expect(lastHeaderProps).toBeTruthy();
×
NEW
157
    expect(lastHeaderProps.noLink).toBe(true);
×
NEW
158
    expect(lastHeaderProps.homeLink).toBeUndefined();
×
NEW
159
    expect(lastHeaderProps.logo).toBe(headerData.globalHeaderLogo);
×
NEW
160
    expect(lastHeaderProps.alt).toBe(headerData.globalHeaderLogoAltText);
×
NEW
161
    expect(lastHeaderProps.SearchComponent).toBeUndefined();
×
NEW
162
    expect(screen.queryByTestId('searchbar-stub')).toBeNull();
×
163
  });
164

NEW
165
  test('SearchBarConfig.query calls GraphQL client with SEARCH_PUBLIC and returns globalSearch', async () => {
×
NEW
166
    renderWithPath('/');
×
167

NEW
168
    const searchBarConfig = mockSearchBarGenerator.mock.calls[0][0];
×
NEW
169
    const input = 'dog';
×
170

NEW
171
    const result = await searchBarConfig.config.query(input);
×
172

NEW
173
    expect(mockClientQuery).toHaveBeenCalledTimes(1);
×
NEW
174
    expect(mockClientQuery.mock.calls[0][0]).toEqual({
×
175
      query: SEARCH_PUBLIC,
176
      variables: {
177
        input,
178
      },
179
    });
NEW
180
    expect(result).toEqual({
×
181
      programs: [{ program_acronym: 'ABC' }],
182
      studies: [],
183
      cases: [],
184
      samples: [],
185
      files: [],
186
      model: [],
187
    });
188
  });
189

NEW
190
  test('SearchBar is created by the generator and can render', () => {
×
NEW
191
    renderWithPath('/');
×
192

NEW
193
    expect(screen.getByTestId('searchbar-stub')).toBeTruthy();
×
194
  });
195

NEW
196
  test('query promise resolves even when called multiple times', async () => {
×
NEW
197
    renderWithPath('/');
×
198

NEW
199
    const searchBarConfig = mockSearchBarGenerator.mock.calls[0][0];
×
200

NEW
201
    const first = await searchBarConfig.config.query('cat');
×
NEW
202
    const second = await searchBarConfig.config.query('mouse');
×
203

NEW
204
    expect(mockClientQuery).toHaveBeenCalledTimes(2);
×
NEW
205
    expect(mockClientQuery.mock.calls[0][0]).toEqual({
×
206
      query: SEARCH_PUBLIC,
207
      variables: {
208
        input: 'cat',
209
      },
210
    });
NEW
211
    expect(mockClientQuery.mock.calls[1][0]).toEqual({
×
212
      query: SEARCH_PUBLIC,
213
      variables: {
214
        input: 'mouse',
215
      },
216
    });
217

NEW
218
    expect(first.programs[0].program_acronym).toBe('ABC');
×
NEW
219
    expect(second.programs[0].program_acronym).toBe('ABC');
×
220
  });
221
});
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