• 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/ReadMeDialog/ReadMe.component.generated.test.jsx
1
// src/components/ReadMeDialog/ReadMe.component.generated.test.jsx
2
import React from 'react';
3
import { fireEvent, render, screen } from '@testing-library/react';
4
import '@testing-library/jest-dom';
5
import html2pdf from 'html2pdf.js';
6
import { marked } from 'marked';
7
import { createFileName } from '../../pages/Cart/utils';
8
import * as ReadMeModule from './ReadMe.component.jsx';
9
import ReadMeDialogComponent from './ReadMe.component.jsx';
10

NEW
11
const mockReact = React;
×
12

NEW
13
jest.mock('./assets/footer_line.png', () => 'mock-footer-line.png');
×
NEW
14
jest.mock('./assets/icdc_nih_logo.png', () => 'mock-nih-logo.png');
×
NEW
15
jest.mock('./assets/Download_PDF.svg', () => 'mock-pdf-icon.svg');
×
16

NEW
17
jest.mock('./ReadMe.theme.config', () => ({
×
18
  __esModule: true,
NEW
19
  default: ({ children }) => <>{children}</>,
×
20
}));
21

NEW
22
jest.mock('react-markdown', () => {
×
NEW
23
  const renderMarkdown = (content, components = {}) => {
×
NEW
24
    const input = String(content ?? '');
×
NEW
25
    const parts = [];
×
NEW
26
    let lastIndex = 0;
×
NEW
27
    let key = 0;
×
28

NEW
29
    const pushText = text => {
×
NEW
30
      if (text) {
×
NEW
31
        parts.push(
×
32
          mockReact.createElement(
33
            mockReact.Fragment,
34
            { key: `text-${(key += 1)}` },
35
            text
36
          )
37
        );
38
      }
39
    };
40

NEW
41
    const pushLink = (label, href) => {
×
NEW
42
      const LinkComponent = components.a || 'a';
×
NEW
43
      parts.push(
×
44
        mockReact.createElement(
45
          LinkComponent,
46
          {
47
            key: `link-${(key += 1)}`,
48
            href,
49
            target: '_blank',
50
            rel: 'noopener noreferrer',
51
          },
52
          label
53
        )
54
      );
55
    };
56

NEW
57
    const linkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
×
58
    let match;
59

NEW
60
    while ((match = linkRegex.exec(input)) !== null) {
×
NEW
61
      pushText(input.slice(lastIndex, match.index));
×
NEW
62
      pushLink(match[1], match[2]);
×
NEW
63
      lastIndex = match.index + match[0].length;
×
64
    }
65

NEW
66
    pushText(input.slice(lastIndex));
×
67

NEW
68
    return mockReact.createElement(
×
69
      'div',
70
      { 'data-testid': 'mock-react-markdown' },
71
      parts
72
    );
73
  };
74

NEW
75
  return {
×
76
    __esModule: true,
NEW
77
    default: ({ children, components }) => renderMarkdown(children, components),
×
78
  };
79
});
80

NEW
81
jest.mock('./ReadMe.styled', () => ({
×
82
  __esModule: true,
83
  TitleContent: ({ children, ...props }) => (
NEW
84
    <div data-testid="title-content" {...props}>
×
85
      {children}
86
    </div>
87
  ),
88
  Title: ({ children, ...props }) => (
NEW
89
    <h2 data-testid="dialog-title" {...props}>
×
90
      {children}
91
    </h2>
92
  ),
93
  DialogActionContent: ({ children, ...props }) => (
NEW
94
    <div data-testid="dialog-actions" {...props}>
×
95
      {children}
96
    </div>
97
  ),
98
  DownloadButton: ({ onClick, children, ...props }) => (
NEW
99
    <button
×
100
      data-testid="download-button"
101
      type="button"
102
      onClick={onClick}
103
      {...props}
104
    >
105
      {children}
106
    </button>
107
  ),
108
  DownloadIcon: ({ alt, ...props }) => (
NEW
109
    <img alt={alt || 'pdf download icon'} {...props} />
×
110
  ),
111
  ClosButton: ({ onClick, children, ...props }) => (
NEW
112
    <button
×
113
      data-testid="close-button"
114
      type="button"
115
      onClick={onClick}
116
      {...props}
117
    >
118
      {children}
119
    </button>
120
  ),
NEW
121
  CloseBtnIcon: props => <span data-testid="close-icon" {...props} />,
×
122
  ReadMeContentContainer: ({ children, ...props }) => (
NEW
123
    <div data-testid="readme-content-container" {...props}>
×
124
      {children}
125
    </div>
126
  ),
127
  DialogBox: ({ children, ...props }) => (
NEW
128
    <div data-testid="dialog-box" {...props}>
×
129
      {children}
130
    </div>
131
  ),
132
}));
133

NEW
134
jest.mock('../../pages/Cart/utils', () => ({
×
135
  createFileName: jest.fn(
NEW
136
    () => 'ICDC-MY-FILES-CART-README 2024-01-01 00-00-00.pdf'
×
137
  ),
138
}));
139

NEW
140
jest.mock('marked', () => ({
×
141
  marked: jest.fn(),
142
}));
143

NEW
144
jest.mock('html2pdf.js', () => {
×
NEW
145
  const mockPdf = {
×
146
    setPage: jest.fn(),
147
    setFont: jest.fn(),
148
    setFontSize: jest.fn(),
149
    setTextColor: jest.fn(),
150
    text: jest.fn(),
151
    addImage: jest.fn(),
152
    internal: {
NEW
153
      getNumberOfPages: jest.fn(() => 2),
×
154
      pageSize: {
NEW
155
        getHeight: jest.fn(() => 11),
×
NEW
156
        getWidth: jest.fn(() => 8.5),
×
157
      },
158
    },
159
  };
160

NEW
161
  const mockChain = {
×
162
    set: jest.fn().mockReturnThis(),
163
    from: jest.fn().mockReturnThis(),
164
    toPdf: jest.fn().mockReturnThis(),
NEW
165
    get: jest.fn(() => ({
×
166
      then: callback => {
NEW
167
        callback(mockPdf);
×
NEW
168
        return mockChain;
×
169
      },
170
    })),
171
    save: jest.fn(),
172
  };
173

NEW
174
  const mockHtml2pdf = jest.fn(() => mockChain);
×
NEW
175
  mockHtml2pdf.__mockPdf = mockPdf;
×
NEW
176
  mockHtml2pdf.__mockChain = mockChain;
×
177

NEW
178
  return {
×
179
    __esModule: true,
180
    default: mockHtml2pdf,
181
  };
182
});
183

NEW
184
describe('ReadMeDialogComponent', () => {
×
185
  let consoleErrorSpy;
186

NEW
187
  beforeAll(() => {
×
NEW
188
    consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
×
189
  });
190

NEW
191
  afterAll(() => {
×
NEW
192
    consoleErrorSpy.mockRestore();
×
193
  });
194

NEW
195
  beforeEach(() => {
×
NEW
196
    jest.clearAllMocks();
×
NEW
197
    marked.mockImplementation(md => {
×
NEW
198
      if (!md) return '';
×
NEW
199
      return `<p>${String(md)}</p><!-- PAGE BREAK --><p>More</p>`;
×
200
    });
201
  });
202

NEW
203
  test('renders nothing when content is falsy', () => {
×
NEW
204
    const { container } = render(
×
205
      <ReadMeDialogComponent
206
        display
207
        displayReadMeDialog={jest.fn()}
208
        content={null}
209
        title="My Title"
210
      />
211
    );
212

NEW
213
    expect(container.firstChild).toBeNull();
×
214
  });
215

NEW
216
  test('renders title and markdown content without PAGE BREAK markers and opens links in a new tab', () => {
×
NEW
217
    render(
×
218
      <ReadMeDialogComponent
219
        display
220
        displayReadMeDialog={jest.fn()}
221
        content="Hello [link](http://example.com) <!-- PAGE BREAK --> world"
222
        title="ReadMe Title"
223
      />
224
    );
225

NEW
226
    expect(screen.getByTestId('dialog-title').textContent).toContain(
×
227
      'ReadMe Title'
228
    );
NEW
229
    expect(screen.getByTestId('readme-content-container')).not.toBeNull();
×
230

NEW
231
    const link = screen.getByRole('link', { name: 'link' });
×
NEW
232
    expect(link.getAttribute('href')).toBe('http://example.com');
×
NEW
233
    expect(link.getAttribute('target')).toBe('_blank');
×
NEW
234
    expect(link.getAttribute('rel')).toBe('noopener noreferrer');
×
235

NEW
236
    expect(screen.queryByText('PAGE BREAK')).toBeNull();
×
NEW
237
    expect(screen.getByText(/Hello/i)).not.toBeNull();
×
NEW
238
    expect(screen.getByText(/world/i)).not.toBeNull();
×
239
  });
240

NEW
241
  test('calls close handler when the close button is clicked', () => {
×
NEW
242
    const closeHandler = jest.fn();
×
243

NEW
244
    render(
×
245
      <ReadMeDialogComponent
246
        display
247
        displayReadMeDialog={closeHandler}
248
        content="Some content"
249
        title="Closable ReadMe"
250
      />
251
    );
252

NEW
253
    fireEvent.click(screen.getByTestId('close-button'));
×
NEW
254
    expect(closeHandler).toHaveBeenCalledTimes(1);
×
255
  });
256

NEW
257
  test('invokes pdf download flow when clicking the download button', () => {
×
NEW
258
    render(
×
259
      <ReadMeDialogComponent
260
        display
261
        displayReadMeDialog={jest.fn()}
262
        content="Some content"
263
        title="Downloadable ReadMe"
264
      />
265
    );
266

NEW
267
    fireEvent.click(screen.getByTestId('download-button'));
×
268

NEW
269
    expect(html2pdf).toHaveBeenCalledTimes(1);
×
NEW
270
    expect(html2pdf.__mockChain.set).toHaveBeenCalledTimes(1);
×
NEW
271
    expect(html2pdf.__mockChain.from).toHaveBeenCalledTimes(1);
×
NEW
272
    expect(html2pdf.__mockChain.toPdf).toHaveBeenCalledTimes(1);
×
NEW
273
    expect(html2pdf.__mockChain.get).toHaveBeenCalledWith('pdf');
×
NEW
274
    expect(html2pdf.__mockChain.save).toHaveBeenCalledTimes(1);
×
275

NEW
276
    expect(createFileName).toHaveBeenCalledWith(
×
277
      'ICDC-MY-FILES-CART-README',
278
      'pdf'
279
    );
280

NEW
281
    const optionsArg = html2pdf.__mockChain.set.mock.calls[0][0];
×
NEW
282
    expect(optionsArg).toMatchObject({
×
283
      filename: 'ICDC-MY-FILES-CART-README 2024-01-01 00-00-00.pdf',
284
      jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' },
285
      pagebreak: { mode: ['avoid-all', 'css', 'legacy'] },
286
    });
287
  });
288
});
289

NEW
290
describe('downloadMarkdownPdf', () => {
×
NEW
291
  beforeEach(() => {
×
NEW
292
    jest.clearAllMocks();
×
NEW
293
    marked.mockImplementation(md => {
×
NEW
294
      if (!md) return '';
×
NEW
295
      return `<h1>Header</h1><!-- PAGE BREAK --><p>${String(md)}</p>`;
×
296
    });
297
  });
298

NEW
299
  test('generates pdf with replaced page breaks, header logo, title, and footer content', async () => {
×
NEW
300
    const { downloadMarkdownPdf } = ReadMeModule;
×
301

NEW
302
    await downloadMarkdownPdf('My README', 'body text');
×
303

NEW
304
    expect(html2pdf).toHaveBeenCalledTimes(1);
×
NEW
305
    expect(html2pdf.__mockChain.set).toHaveBeenCalledTimes(1);
×
NEW
306
    expect(html2pdf.__mockChain.from).toHaveBeenCalledTimes(1);
×
307

NEW
308
    const containerElement = html2pdf.__mockChain.from.mock.calls[0][0];
×
NEW
309
    expect(containerElement).toBeInstanceOf(HTMLElement);
×
310

NEW
311
    const htmlString = containerElement.innerHTML;
×
NEW
312
    expect(htmlString).toContain('My README');
×
NEW
313
    expect(htmlString).toContain('class="page-break"');
×
NEW
314
    expect(htmlString).toMatch(/<img[^>]+alt="logo"/);
×
NEW
315
    expect(marked).toHaveBeenCalledWith('body text');
×
316

NEW
317
    expect(html2pdf.__mockPdf.internal.getNumberOfPages).toHaveBeenCalledTimes(
×
318
      1
319
    );
NEW
320
    expect(html2pdf.__mockPdf.setPage).toHaveBeenCalledTimes(2);
×
NEW
321
    expect(html2pdf.__mockPdf.setFont).toHaveBeenCalledTimes(2);
×
NEW
322
    expect(html2pdf.__mockPdf.setFontSize).toHaveBeenCalledTimes(2);
×
NEW
323
    expect(html2pdf.__mockPdf.setTextColor).toHaveBeenCalledTimes(2);
×
NEW
324
    expect(html2pdf.__mockPdf.text).toHaveBeenCalledTimes(4);
×
NEW
325
    expect(html2pdf.__mockPdf.addImage).toHaveBeenCalledTimes(2);
×
NEW
326
    expect(html2pdf.__mockChain.save).toHaveBeenCalledTimes(1);
×
327
  });
328

NEW
329
  test('handles empty or undefined content without throwing and still saves the pdf', async () => {
×
NEW
330
    const { downloadMarkdownPdf } = ReadMeModule;
×
331

NEW
332
    await expect(
×
333
      downloadMarkdownPdf('Empty Title', '')
334
    ).resolves.toBeUndefined();
NEW
335
    expect(html2pdf.__mockChain.save).toHaveBeenCalledTimes(1);
×
336

NEW
337
    jest.clearAllMocks();
×
NEW
338
    marked.mockImplementation(md => (!md ? '' : `<p>${String(md)}</p>`));
×
339

NEW
340
    await expect(
×
341
      downloadMarkdownPdf('No Content Title', undefined)
342
    ).resolves.toBeUndefined();
NEW
343
    expect(html2pdf.__mockChain.save).toHaveBeenCalledTimes(1);
×
344
  });
345
});
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