Skip to content

Commit a97298c

Browse files
bjoernricksgreenbonebot
authored andcommitted
Use empty calls to BaseFilter.fromString to create an empty filter
1 parent 896a891 commit a97298c

11 files changed

Lines changed: 54 additions & 42 deletions

src/gmp/models/filter/__tests__/base-filter.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ describe('BaseFilter tests', () => {
4848
});
4949

5050
describe('BaseFilter fromString', () => {
51+
test('should parse empty string', () => {
52+
const filter = BaseFilter.fromString('');
53+
expect(filter.toFilterString()).toEqual('');
54+
expect(filter.length).toBe(0);
55+
});
56+
57+
test('should parse undefined string', () => {
58+
const filter = BaseFilter.fromString();
59+
expect(filter.toFilterString()).toEqual('');
60+
expect(filter.length).toBe(0);
61+
});
62+
5163
test('should parse terms from string', () => {
5264
const filter = BaseFilter.fromString('foo=bar lorem~ipsum');
5365
expect(filter.toFilterString()).toEqual('foo=bar lorem~ipsum');

src/web/entities/__tests__/BulkTags.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('BulkTags tests', () => {
1616
test('should render the BulkTags component', () => {
1717
const entities = [new Task({id: '1'}), new Task({id: '2'})];
1818
const entitiesCounts = new CollectionCounts({filtered: 2, all: 2});
19-
const filter = BaseFilter.fromString('');
19+
const filter = BaseFilter.fromString();
2020
const selectedEntities = [];
2121
const onClose = testing.fn();
2222
const getAllTags = testing
@@ -43,7 +43,7 @@ describe('BulkTags tests', () => {
4343
test('should allow to tag all filtered entities', () => {
4444
const entities = [new Task({id: '1'}), new Task({id: '2'})];
4545
const entitiesCounts = new CollectionCounts({filtered: 2, all: 2});
46-
const filter = BaseFilter.fromString('');
46+
const filter = BaseFilter.fromString();
4747
const selectedEntities = [];
4848
const onClose = testing.fn();
4949
const getAllTags = testing
@@ -70,7 +70,7 @@ describe('BulkTags tests', () => {
7070
test('should allow to tag tasks with a new tag', async () => {
7171
const entities = [new Task({id: '1'}), new Task({id: '2'})];
7272
const entitiesCounts = new CollectionCounts({filtered: 2, all: 2});
73-
const filter = BaseFilter.fromString('');
73+
const filter = BaseFilter.fromString();
7474
const selectedEntities = [];
7575
const onClose = testing.fn();
7676
const createTag = testing.fn().mockResolvedValue({data: {id: '2'}});

src/web/pages/reports/__fixtures__/MockAuditReport.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ export const getMockAuditReport = () => {
368368
task: task1,
369369
});
370370

371-
const errorsCollection = parseErrors(report, BaseFilter.fromString(''));
371+
const errorsCollection = parseErrors(report, BaseFilter.fromString());
372372

373373
const os1 = new ReportOperatingSystem({
374374
id: 'cpe:/foo/bar',
@@ -393,7 +393,7 @@ export const getMockAuditReport = () => {
393393
rows: 2,
394394
length: 2,
395395
}),
396-
filter: BaseFilter.fromString(''),
396+
filter: BaseFilter.fromString(),
397397
};
398398

399399
return {

src/web/pages/reports/__fixtures__/MockReport.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ export const getMockReport = () => {
313313
_id: '1234',
314314
});
315315

316-
const errorsCollection = parseErrors(report, BaseFilter.fromString(''));
316+
const errorsCollection = parseErrors(report, BaseFilter.fromString());
317317

318318
const os1 = new ReportOperatingSystem({
319319
id: 'cpe:/foo/bar',
@@ -336,7 +336,7 @@ export const getMockReport = () => {
336336
rows: 2,
337337
length: 2,
338338
}),
339-
filter: BaseFilter.fromString(''),
339+
filter: BaseFilter.fromString(),
340340
};
341341

342342
const cert1 = ReportTLSCertificate.fromElement(tlsCertificate1);
@@ -350,7 +350,7 @@ export const getMockReport = () => {
350350
rows: 2,
351351
length: 2,
352352
}),
353-
filter: BaseFilter.fromString(''),
353+
filter: BaseFilter.fromString(),
354354
};
355355

356356
const resultsCollection = {
@@ -362,7 +362,7 @@ export const getMockReport = () => {
362362
rows: report.result_count?.filtered ?? 0,
363363
length: report.result_count?.filtered ?? 0,
364364
}),
365-
filter: BaseFilter.fromString(''),
365+
filter: BaseFilter.fromString(),
366366
};
367367

368368
const portsCollection = {
@@ -374,7 +374,7 @@ export const getMockReport = () => {
374374
rows: report.ports?.count ?? 0,
375375
length: report.ports?.count ?? 0,
376376
}),
377-
filter: BaseFilter.fromString(''),
377+
filter: BaseFilter.fromString(),
378378
};
379379

380380
const applicationsCollection = {
@@ -386,7 +386,7 @@ export const getMockReport = () => {
386386
rows: report.apps?.count ?? 0,
387387
length: report.apps?.count ?? 0,
388388
}),
389-
filter: BaseFilter.fromString(''),
389+
filter: BaseFilter.fromString(),
390390
};
391391

392392
const cvesCollection = {
@@ -398,7 +398,7 @@ export const getMockReport = () => {
398398
rows: report.vulns?.count ?? 0,
399399
length: report.vulns?.count ?? 0,
400400
}),
401-
filter: BaseFilter.fromString(''),
401+
filter: BaseFilter.fromString(),
402402
};
403403

404404
const closedCvesCollection = {
@@ -410,7 +410,7 @@ export const getMockReport = () => {
410410
rows: report.closed_cves?.count ?? 0,
411411
length: report.closed_cves?.count ?? 0,
412412
}),
413-
filter: BaseFilter.fromString(''),
413+
filter: BaseFilter.fromString(),
414414
};
415415

416416
return {

src/web/pages/reports/__tests__/AuditDeltaDetailsPage.test.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const createGmp = ({reportResultsThreshold = 10} = {}) => ({
4444
get: testing.fn().mockResolvedValue({
4545
data: mockEntity.report?.results?.entities ?? [],
4646
meta: {
47-
filter: BaseFilter.fromString(''),
47+
filter: BaseFilter.fromString(),
4848
counts: new CollectionCounts({
4949
filtered: 2,
5050
all: 2,
@@ -63,7 +63,7 @@ const createGmp = ({reportResultsThreshold = 10} = {}) => ({
6363
{ip: '109.876.54.322', id: '109.876.54.322', hostname: 'host3'},
6464
],
6565
meta: {
66-
filter: BaseFilter.fromString(''),
66+
filter: BaseFilter.fromString(),
6767
counts: new CollectionCounts({filtered: 3, all: 3, first: 1, rows: 10}),
6868
},
6969
}),

src/web/pages/reports/__tests__/AuditReportDetailsPage.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ const createGmp = () => ({
107107
},
108108
],
109109
meta: {
110-
filter: BaseFilter.fromString(''),
110+
filter: BaseFilter.fromString(),
111111
counts: new CollectionCounts({
112112
first: 1,
113113
all: 1,
@@ -122,7 +122,7 @@ const createGmp = () => ({
122122
get: testing.fn().mockResolvedValue({
123123
data: [],
124124
meta: {
125-
filter: BaseFilter.fromString(''),
125+
filter: BaseFilter.fromString(),
126126
counts: new CollectionCounts(),
127127
},
128128
}),

src/web/pages/reports/__tests__/DeltaReportDetailsContent.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const createGmp = ({
5252
get: testing.fn().mockResolvedValue({
5353
data: mockEntity.report?.results?.entities ?? [],
5454
meta: {
55-
filter: BaseFilter.fromString(''),
55+
filter: BaseFilter.fromString(),
5656
counts: new CollectionCounts({
5757
filtered: 2,
5858
all: 2,
@@ -70,7 +70,7 @@ const createGmp = ({
7070
{ip: '109.876.54.321', id: '109.876.54.321', hostname: 'lorem.ipsum'},
7171
],
7272
meta: {
73-
filter: BaseFilter.fromString(''),
73+
filter: BaseFilter.fromString(),
7474
counts: new CollectionCounts({filtered: 2, all: 2, first: 1, rows: 10}),
7575
},
7676
}),

src/web/pages/reports/__tests__/ReportDetailsContent.test.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const createGmp = ({reportResultsThreshold = 10} = {}) => ({
5353
get: testing.fn().mockResolvedValue({
5454
data: mockReport.hosts ?? [],
5555
meta: {
56-
filter: BaseFilter.fromString(''),
56+
filter: BaseFilter.fromString(),
5757
counts: new CollectionCounts({filtered: 2, all: 2}),
5858
},
5959
}),
@@ -62,7 +62,7 @@ const createGmp = ({reportResultsThreshold = 10} = {}) => ({
6262
get: testing.fn().mockResolvedValue({
6363
data: [],
6464
meta: {
65-
filter: BaseFilter.fromString(''),
65+
filter: BaseFilter.fromString(),
6666
counts: new CollectionCounts({filtered: 2, all: 2}),
6767
},
6868
}),
@@ -71,7 +71,7 @@ const createGmp = ({reportResultsThreshold = 10} = {}) => ({
7171
get: testing.fn().mockResolvedValue({
7272
data: [],
7373
meta: {
74-
filter: BaseFilter.fromString(''),
74+
filter: BaseFilter.fromString(),
7575
counts: new CollectionCounts({filtered: 4, all: 4}),
7676
},
7777
}),
@@ -80,7 +80,7 @@ const createGmp = ({reportResultsThreshold = 10} = {}) => ({
8080
get: testing.fn().mockResolvedValue({
8181
data: [],
8282
meta: {
83-
filter: BaseFilter.fromString(''),
83+
filter: BaseFilter.fromString(),
8484
counts: new CollectionCounts({filtered: 2, all: 2}),
8585
},
8686
}),
@@ -89,7 +89,7 @@ const createGmp = ({reportResultsThreshold = 10} = {}) => ({
8989
get: testing.fn().mockResolvedValue({
9090
data: [],
9191
meta: {
92-
filter: BaseFilter.fromString(''),
92+
filter: BaseFilter.fromString(),
9393
counts: new CollectionCounts({filtered: 2, all: 2}),
9494
},
9595
}),
@@ -98,7 +98,7 @@ const createGmp = ({reportResultsThreshold = 10} = {}) => ({
9898
get: testing.fn().mockResolvedValue({
9999
data: [],
100100
meta: {
101-
filter: BaseFilter.fromString(''),
101+
filter: BaseFilter.fromString(),
102102
counts: new CollectionCounts({filtered: 2, all: 2}),
103103
},
104104
}),
@@ -107,7 +107,7 @@ const createGmp = ({reportResultsThreshold = 10} = {}) => ({
107107
get: testing.fn().mockResolvedValue({
108108
data: [],
109109
meta: {
110-
filter: BaseFilter.fromString(''),
110+
filter: BaseFilter.fromString(),
111111
counts: new CollectionCounts({filtered: 2, all: 2}),
112112
},
113113
}),
@@ -142,7 +142,7 @@ const createGmp = ({reportResultsThreshold = 10} = {}) => ({
142142
get: testing.fn().mockResolvedValue({
143143
data: [],
144144
meta: {
145-
filter: BaseFilter.fromString(''),
145+
filter: BaseFilter.fromString(),
146146
counts: new CollectionCounts({filtered: 0, all: 0}),
147147
},
148148
}),

src/web/pages/reports/details/__tests__/ContainerScanningResultsTab.test.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const createGmp = ({
2525
data: [result],
2626
meta: {
2727
counts: new CollectionCounts({filtered: 1, all: 1, first: 1, rows: 10}),
28-
filter: BaseFilter.fromString(''),
28+
filter: BaseFilter.fromString(),
2929
},
3030
}),
3131
} = {}) => ({
@@ -44,7 +44,7 @@ const createGmp = ({
4444
describe('ContainerScanningResultsTab', () => {
4545
test('should render loading state initially', () => {
4646
const reportId = 'report-123';
47-
const filter = BaseFilter.fromString('');
47+
const filter = BaseFilter.fromString();
4848

4949
const gmp = createGmp();
5050

@@ -89,7 +89,7 @@ describe('ContainerScanningResultsTab', () => {
8989

9090
test('should handle sorting', async () => {
9191
const reportId = 'report-123';
92-
const filter = BaseFilter.fromString('');
92+
const filter = BaseFilter.fromString();
9393
const mockResults = [
9494
Result.fromElement({
9595
_id: '1',
@@ -302,7 +302,7 @@ describe('ContainerScanningResultsTab', () => {
302302

303303
test('should handle pagination - last page', async () => {
304304
const reportId = 'report-123';
305-
const filter = BaseFilter.fromString('');
305+
const filter = BaseFilter.fromString();
306306
const mockResults = [
307307
Result.fromElement({
308308
_id: '1',
@@ -410,7 +410,7 @@ describe('ContainerScanningResultsTab', () => {
410410

411411
test('should render error panel on error', async () => {
412412
const reportId = 'report-123';
413-
const filter = BaseFilter.fromString('');
413+
const filter = BaseFilter.fromString();
414414

415415
const getMock = testing.fn().mockRejectedValue(new Error('API Error'));
416416

@@ -439,7 +439,7 @@ describe('ContainerScanningResultsTab', () => {
439439

440440
test('should show subtle loading indicator when refetching (not full spinner)', async () => {
441441
const reportId = 'report-123';
442-
const filter = BaseFilter.fromString('');
442+
const filter = BaseFilter.fromString();
443443
const mockResults = [
444444
Result.fromElement({
445445
_id: '1',
@@ -546,7 +546,7 @@ describe('ContainerScanningResultsTab', () => {
546546
first: 1,
547547
rows: 10,
548548
}),
549-
filter: BaseFilter.fromString(''),
549+
filter: BaseFilter.fromString(),
550550
},
551551
});
552552

@@ -555,7 +555,7 @@ describe('ContainerScanningResultsTab', () => {
555555

556556
render(
557557
<ContainerScanningResultsTab
558-
reportFilter={BaseFilter.fromString('')}
558+
reportFilter={BaseFilter.fromString()}
559559
reportId={'report-123'}
560560
status={status}
561561
/>,

src/web/pages/reports/details/__tests__/ReportTabDefinitions.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const entities = {
3535

3636
const baseParams = {
3737
activeReport: {} as ReportReport,
38-
activeFilter: BaseFilter.fromString(''),
38+
activeFilter: BaseFilter.fromString(),
3939
reportId: 'report-123',
4040
isImport: false,
4141
isAgentScanning: false,

0 commit comments

Comments
 (0)