• 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/PaginatedTable/utils.generated.test.js
1
// src/components/PaginatedTable/utils.generated.test.js
2
import * as utils from './utils';
3
import { formatBytes } from '../../bento-core';
4

NEW
5
jest.mock('../../bento-core', () => ({
×
NEW
6
  formatBytes: jest.fn(bytes => `formatted-${bytes}`),
×
7
}));
8

NEW
9
describe('utils - createFileName', () => {
×
NEW
10
  beforeEach(() => {
×
NEW
11
    jest.useFakeTimers();
×
12
  });
13

NEW
14
  afterEach(() => {
×
NEW
15
    jest.useRealTimers();
×
NEW
16
    jest.clearAllMocks();
×
17
  });
18

NEW
19
  it('creates a filename with zero-padded date and time parts', () => {
×
NEW
20
    jest.setSystemTime(new Date(2023, 3, 5, 6, 7, 8));
×
21

NEW
22
    const result = utils.createFileName('report');
×
23

NEW
24
    expect(result).toBe('report 2023-04-05 06-07-08.csv');
×
25
  });
26

NEW
27
  it('creates a filename with already two-digit date and time parts unchanged', () => {
×
NEW
28
    jest.setSystemTime(new Date(2023, 11, 31, 23, 59, 59));
×
29

NEW
30
    const result = utils.createFileName('export');
×
31

NEW
32
    expect(result).toBe('export 2023-12-31 23-59-59.csv');
×
33
  });
34

NEW
35
  it('allows an empty file name prefix', () => {
×
NEW
36
    jest.setSystemTime(new Date(2024, 0, 2, 3, 4, 5));
×
37

NEW
38
    const result = utils.createFileName('');
×
39

NEW
40
    expect(result).toBe(' 2024-01-02 03-04-05.csv');
×
41
  });
42
});
43

NEW
44
describe('utils - convertToCSV', () => {
×
NEW
45
  beforeEach(() => {
×
NEW
46
    jest.clearAllMocks();
×
47
  });
48

NEW
49
  it('converts a JSON string to CSV with headers and formatted file_size values', () => {
×
NEW
50
    const header = ['name', 'file_size', 'type'];
×
NEW
51
    const keys = ['name', 'file_size', 'type'];
×
NEW
52
    const data = [
×
53
      { name: 'file1', file_size: 10240, type: 'csv' },
54
      { name: 'file2', file_size: null, type: null },
55
    ];
NEW
56
    const jsonStr = JSON.stringify(data);
×
57

NEW
58
    formatBytes.mockImplementation(bytes => {
×
NEW
59
      if (bytes === 10240) return '10 KB';
×
NEW
60
      return `formatted-${bytes}`;
×
61
    });
62

NEW
63
    const csv = utils.convertToCSV(jsonStr, keys, header);
×
64

NEW
65
    expect(csv).toBe(
×
66
      'name,file_size,type\r\n' +
67
        '"file1","10 KB","csv"\r\n' +
68
        '"file2", , \r\n'
69
    );
NEW
70
    expect(formatBytes).toHaveBeenCalledTimes(1);
×
NEW
71
    expect(formatBytes).toHaveBeenCalledWith(10240);
×
72
  });
73

NEW
74
  it('accepts an object array directly and returns only the header for an empty array', () => {
×
NEW
75
    const header = ['col1', 'file_size'];
×
NEW
76
    const keys = ['col1', 'file_size'];
×
NEW
77
    const emptyArray = [];
×
78

NEW
79
    const csv = utils.convertToCSV(emptyArray, keys, header);
×
80

NEW
81
    expect(csv).toBe('col1,file_size');
×
NEW
82
    expect(formatBytes).not.toHaveBeenCalled();
×
83
  });
84

NEW
85
  it('uses a space for null values in non-file_size fields', () => {
×
NEW
86
    const header = ['a', 'b'];
×
NEW
87
    const keys = ['a', 'b'];
×
NEW
88
    const data = [{ a: null, b: 'text' }];
×
89

NEW
90
    const csv = utils.convertToCSV(data, keys, header);
×
91

NEW
92
    expect(csv).toBe('a,b\r\n ,"text"\r\n');
×
93
  });
94
});
95

NEW
96
describe('utils - downloadJson', () => {
×
97
  let originalURL;
98
  let originalBlob;
99
  let createObjectURLMock;
100
  let blobMock;
101
  let appendSpy;
102
  let removeSpy;
103
  let createElementSpy;
104
  let clickSpy;
105
  let createdAnchor;
106

NEW
107
  beforeEach(() => {
×
NEW
108
    jest.useFakeTimers();
×
NEW
109
    jest.setSystemTime(new Date(2024, 0, 2, 3, 4, 5));
×
NEW
110
    jest.clearAllMocks();
×
111

NEW
112
    originalURL = window.URL;
×
NEW
113
    originalBlob = global.Blob;
×
114

NEW
115
    createObjectURLMock = jest.fn(() => 'blob:mock-url');
×
NEW
116
    Object.defineProperty(window, 'URL', {
×
117
      configurable: true,
118
      writable: true,
119
      value: { createObjectURL: createObjectURLMock },
120
    });
121

NEW
122
    blobMock = jest.fn(() => ({ mocked: 'blob' }));
×
NEW
123
    global.Blob = blobMock;
×
124

NEW
125
    appendSpy = jest.spyOn(document.body, 'appendChild');
×
NEW
126
    removeSpy = jest.spyOn(document.body, 'removeChild');
×
127

NEW
128
    createdAnchor = null;
×
NEW
129
    const originalCreateElement = document.createElement.bind(document);
×
130

NEW
131
    createElementSpy = jest
×
132
      .spyOn(document, 'createElement')
133
      .mockImplementation(tagName => {
NEW
134
        const element = originalCreateElement(tagName);
×
135

NEW
136
        if (String(tagName).toLowerCase() === 'a') {
×
NEW
137
          createdAnchor = element;
×
NEW
138
          clickSpy = jest
×
139
            .spyOn(createdAnchor, 'click')
140
            .mockImplementation(() => {});
141
        }
142

NEW
143
        return element;
×
144
      });
145
  });
146

NEW
147
  afterEach(() => {
×
NEW
148
    jest.useRealTimers();
×
149

NEW
150
    Object.defineProperty(window, 'URL', {
×
151
      configurable: true,
152
      writable: true,
153
      value: originalURL,
154
    });
155

NEW
156
    global.Blob = originalBlob;
×
157

NEW
158
    if (clickSpy) {
×
NEW
159
      clickSpy.mockRestore();
×
160
    }
161

NEW
162
    if (createElementSpy) {
×
NEW
163
      createElementSpy.mockRestore();
×
164
    }
165

NEW
166
    if (appendSpy) {
×
NEW
167
      appendSpy.mockRestore();
×
168
    }
169

NEW
170
    if (removeSpy) {
×
NEW
171
      removeSpy.mockRestore();
×
172
    }
173
  });
174

NEW
175
  it('creates a CSV Blob and triggers a download with the correct filename', () => {
×
NEW
176
    const tableData = [{ a: 1 }];
×
NEW
177
    const tableDownloadCSV = {
×
178
      keysToInclude: ['a'],
179
      header: ['a'],
180
      fileName: 'download',
181
    };
182

NEW
183
    utils.downloadJson(tableData, tableDownloadCSV);
×
184

NEW
185
    expect(blobMock).toHaveBeenCalledTimes(1);
×
NEW
186
    expect(blobMock).toHaveBeenCalledWith(['a\r\n"1"\r\n'], {
×
187
      type: 'text/csv',
188
    });
189

NEW
190
    expect(createObjectURLMock).toHaveBeenCalledTimes(1);
×
NEW
191
    expect(createObjectURLMock.mock.calls[0][0]).toEqual({ mocked: 'blob' });
×
192

NEW
193
    expect(createdAnchor).toBeTruthy();
×
NEW
194
    expect(createdAnchor.getAttribute('href')).toBe('blob:mock-url');
×
NEW
195
    expect(createdAnchor.getAttribute('download')).toBe(
×
196
      'download 2024-01-02 03-04-05.csv'
197
    );
198

NEW
199
    expect(appendSpy).toHaveBeenCalledTimes(1);
×
NEW
200
    expect(appendSpy).toHaveBeenCalledWith(createdAnchor);
×
201

NEW
202
    expect(clickSpy).toHaveBeenCalledTimes(1);
×
203

NEW
204
    expect(removeSpy).toHaveBeenCalledTimes(1);
×
NEW
205
    expect(removeSpy).toHaveBeenCalledWith(createdAnchor);
×
206
  });
207

NEW
208
  it('uses an empty string when fileName is missing', () => {
×
NEW
209
    const tableData = [{ x: 42 }];
×
NEW
210
    const tableDownloadCSV = {
×
211
      keysToInclude: ['x'],
212
      header: ['x'],
213
    };
214

NEW
215
    utils.downloadJson(tableData, tableDownloadCSV);
×
216

NEW
217
    expect(createdAnchor.getAttribute('download')).toBe(
×
218
      ' 2024-01-02 03-04-05.csv'
219
    );
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