Skip to content

Commit 6263a95

Browse files
[Security Solution] clean unused types, export components and add many unit tests (#217100)
## Summary This code change was originally part of [a bigger PR](#216744) related to the AI for SOC effort. I decided to split the work for 2 reasons: - less files to review, less teams impacted - this current PR will easily be backported to `8.x` while the AI for SOC is only targeting `9.1` This PR makes only a few small changes: - remove unused types - export a few components/functions outside of the `alerts_table` folder to make them reusable within the new AI for SOC alert summary page (see PR linked above) - add a lot of unit tests to everything, especially the now exported components/functions #### UI remains unchanged: ![Screenshot 2025-04-03 at 6 09 57 PM](https://github.com/user-attachments/assets/3e4135e7-6e2f-4b4f-94e5-0dd72f1710bb) ![Screenshot 2025-04-03 at 6 10 06 PM](https://github.com/user-attachments/assets/382391d6-7ae1-4da4-a76f-495b6db69db3) ![Screenshot 2025-04-03 at 6 10 13 PM](https://github.com/user-attachments/assets/28c5947b-2168-4080-b298-5fea1f3f97c7) ![Screenshot 2025-04-03 at 6 10 21 PM](https://github.com/user-attachments/assets/2dc75fcb-9929-4821-830d-b84fceaf232d) ### Checklist - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md) - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios Will unblock elastic/security-team#11973 (cherry picked from commit 837059b) # Conflicts: # src/platform/packages/shared/kbn-grouping/src/containers/query/index.test.ts # src/platform/packages/shared/kbn-grouping/src/mocks.ts
1 parent 111f6f5 commit 6263a95

11 files changed

Lines changed: 343 additions & 499 deletions

File tree

src/platform/packages/shared/kbn-grouping/src/components/grouping.mock.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import React from 'react';
1111
import { EuiContextMenuItem } from '@elastic/eui';
12+
1213
export const host1Name = 'nice-host';
1314
export const host2Name = 'cool-host';
1415

@@ -48,9 +49,6 @@ export const mockGroupingProps = {
4849
},
4950
],
5051
},
51-
countSeveritySubAggregation: {
52-
value: 1,
53-
},
5452
usersCountAggregation: {
5553
value: 1,
5654
},
@@ -81,9 +79,6 @@ export const mockGroupingProps = {
8179
},
8280
],
8381
},
84-
countSeveritySubAggregation: {
85-
value: 1,
86-
},
8782
usersCountAggregation: {
8883
value: 1,
8984
},
@@ -115,9 +110,6 @@ export const mockGroupingProps = {
115110
},
116111
],
117112
},
118-
countSeveritySubAggregation: {
119-
value: 11,
120-
},
121113
usersCountAggregation: {
122114
value: 11,
123115
},

x-pack/solutions/observability/packages/kbn-alerts-grouping/src/mocks/grouping_query.mock.ts

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,6 @@ export const groupingSearchResponse = {
131131
},
132132
],
133133
},
134-
countSeveritySubAggregation: {
135-
value: 1,
136-
},
137134
usersCountAggregation: {
138135
value: 0,
139136
},
@@ -182,9 +179,6 @@ export const groupingSearchResponse = {
182179
},
183180
],
184181
},
185-
countSeveritySubAggregation: {
186-
value: 1,
187-
},
188182
usersCountAggregation: {
189183
value: 0,
190184
},
@@ -233,9 +227,6 @@ export const groupingSearchResponse = {
233227
},
234228
],
235229
},
236-
countSeveritySubAggregation: {
237-
value: 1,
238-
},
239230
usersCountAggregation: {
240231
value: 0,
241232
},
@@ -284,9 +275,6 @@ export const groupingSearchResponse = {
284275
},
285276
],
286277
},
287-
countSeveritySubAggregation: {
288-
value: 1,
289-
},
290278
usersCountAggregation: {
291279
value: 0,
292280
},
@@ -335,9 +323,6 @@ export const groupingSearchResponse = {
335323
},
336324
],
337325
},
338-
countSeveritySubAggregation: {
339-
value: 1,
340-
},
341326
usersCountAggregation: {
342327
value: 0,
343328
},
@@ -386,9 +371,6 @@ export const groupingSearchResponse = {
386371
},
387372
],
388373
},
389-
countSeveritySubAggregation: {
390-
value: 1,
391-
},
392374
usersCountAggregation: {
393375
value: 0,
394376
},
@@ -437,9 +419,6 @@ export const groupingSearchResponse = {
437419
},
438420
],
439421
},
440-
countSeveritySubAggregation: {
441-
value: 1,
442-
},
443422
usersCountAggregation: {
444423
value: 0,
445424
},
@@ -488,9 +467,6 @@ export const groupingSearchResponse = {
488467
},
489468
],
490469
},
491-
countSeveritySubAggregation: {
492-
value: 1,
493-
},
494470
usersCountAggregation: {
495471
value: 0,
496472
},
@@ -539,9 +515,6 @@ export const groupingSearchResponse = {
539515
},
540516
],
541517
},
542-
countSeveritySubAggregation: {
543-
value: 1,
544-
},
545518
usersCountAggregation: {
546519
value: 91,
547520
},
@@ -590,9 +563,6 @@ export const groupingSearchResponse = {
590563
},
591564
],
592565
},
593-
countSeveritySubAggregation: {
594-
value: 1,
595-
},
596566
usersCountAggregation: {
597567
value: 91,
598568
},
@@ -641,9 +611,6 @@ export const groupingSearchResponse = {
641611
},
642612
],
643613
},
644-
countSeveritySubAggregation: {
645-
value: 1,
646-
},
647614
usersCountAggregation: {
648615
value: 91,
649616
},
@@ -692,9 +659,6 @@ export const groupingSearchResponse = {
692659
},
693660
],
694661
},
695-
countSeveritySubAggregation: {
696-
value: 1,
697-
},
698662
usersCountAggregation: {
699663
value: 91,
700664
},
@@ -743,9 +707,6 @@ export const groupingSearchResponse = {
743707
},
744708
],
745709
},
746-
countSeveritySubAggregation: {
747-
value: 1,
748-
},
749710
usersCountAggregation: {
750711
value: 91,
751712
},
@@ -794,9 +755,6 @@ export const groupingSearchResponse = {
794755
},
795756
],
796757
},
797-
countSeveritySubAggregation: {
798-
value: 1,
799-
},
800758
usersCountAggregation: {
801759
value: 91,
802760
},
@@ -845,9 +803,6 @@ export const groupingSearchResponse = {
845803
},
846804
],
847805
},
848-
countSeveritySubAggregation: {
849-
value: 1,
850-
},
851806
usersCountAggregation: {
852807
value: 91,
853808
},
@@ -896,9 +851,6 @@ export const groupingSearchResponse = {
896851
},
897852
],
898853
},
899-
countSeveritySubAggregation: {
900-
value: 1,
901-
},
902854
usersCountAggregation: {
903855
value: 91,
904856
},
@@ -947,9 +899,6 @@ export const groupingSearchResponse = {
947899
},
948900
],
949901
},
950-
countSeveritySubAggregation: {
951-
value: 1,
952-
},
953902
usersCountAggregation: {
954903
value: 0,
955904
},
@@ -998,9 +947,6 @@ export const groupingSearchResponse = {
998947
},
999948
],
1000949
},
1001-
countSeveritySubAggregation: {
1002-
value: 1,
1003-
},
1004950
usersCountAggregation: {
1005951
value: 0,
1006952
},
@@ -1049,9 +995,6 @@ export const groupingSearchResponse = {
1049995
},
1050996
],
1051997
},
1052-
countSeveritySubAggregation: {
1053-
value: 1,
1054-
},
1055998
usersCountAggregation: {
1056999
value: 0,
10571000
},
@@ -1100,9 +1043,6 @@ export const groupingSearchResponse = {
11001043
},
11011044
],
11021045
},
1103-
countSeveritySubAggregation: {
1104-
value: 1,
1105-
},
11061046
usersCountAggregation: {
11071047
value: 0,
11081048
},
@@ -1151,9 +1091,6 @@ export const groupingSearchResponse = {
11511091
},
11521092
],
11531093
},
1154-
countSeveritySubAggregation: {
1155-
value: 1,
1156-
},
11571094
usersCountAggregation: {
11581095
value: 0,
11591096
},
@@ -1202,9 +1139,6 @@ export const groupingSearchResponse = {
12021139
},
12031140
],
12041141
},
1205-
countSeveritySubAggregation: {
1206-
value: 1,
1207-
},
12081142
usersCountAggregation: {
12091143
value: 0,
12101144
},
@@ -1253,9 +1187,6 @@ export const groupingSearchResponse = {
12531187
},
12541188
],
12551189
},
1256-
countSeveritySubAggregation: {
1257-
value: 1,
1258-
},
12591190
usersCountAggregation: {
12601191
value: 0,
12611192
},
@@ -1304,9 +1235,6 @@ export const groupingSearchResponse = {
13041235
},
13051236
],
13061237
},
1307-
countSeveritySubAggregation: {
1308-
value: 1,
1309-
},
13101238
usersCountAggregation: {
13111239
value: 0,
13121240
},
@@ -1355,9 +1283,6 @@ export const groupingSearchResponse = {
13551283
},
13561284
],
13571285
},
1358-
countSeveritySubAggregation: {
1359-
value: 1,
1360-
},
13611286
usersCountAggregation: {
13621287
value: 91,
13631288
},

x-pack/solutions/security/plugins/security_solution/public/detections/components/alerts_table/grouping_settings/default_group_stats_aggregations.test.tsx

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ describe('defaultGroupStatsAggregations', () => {
2929
]);
3030
});
3131

32-
it('should return values depending on the input field', () => {
33-
const ruleAggregations = defaultGroupStatsAggregations('kibana.alert.rule.name');
34-
expect(ruleAggregations).toEqual([
32+
it('should return values depending for kibana.alert.rule.name input field', () => {
33+
const aggregations = defaultGroupStatsAggregations('kibana.alert.rule.name');
34+
expect(aggregations).toEqual([
3535
{
3636
unitsCount: {
3737
cardinality: {
@@ -47,13 +47,6 @@ describe('defaultGroupStatsAggregations', () => {
4747
},
4848
},
4949
},
50-
{
51-
countSeveritySubAggregation: {
52-
cardinality: {
53-
field: 'kibana.alert.severity',
54-
},
55-
},
56-
},
5750
{
5851
severitiesSubAggregation: {
5952
terms: {
@@ -83,9 +76,11 @@ describe('defaultGroupStatsAggregations', () => {
8376
},
8477
},
8578
]);
79+
});
8680

87-
const hostAggregations = defaultGroupStatsAggregations('host.name');
88-
expect(hostAggregations).toEqual([
81+
it('should return values depending for host.name input field', () => {
82+
const aggregations = defaultGroupStatsAggregations('host.name');
83+
expect(aggregations).toEqual([
8984
{
9085
unitsCount: {
9186
cardinality: {
@@ -100,13 +95,6 @@ describe('defaultGroupStatsAggregations', () => {
10095
},
10196
},
10297
},
103-
{
104-
countSeveritySubAggregation: {
105-
cardinality: {
106-
field: 'kibana.alert.severity',
107-
},
108-
},
109-
},
11098
{
11199
severitiesSubAggregation: {
112100
terms: {
@@ -122,9 +110,11 @@ describe('defaultGroupStatsAggregations', () => {
122110
},
123111
},
124112
]);
113+
});
125114

126-
const userAggregations = defaultGroupStatsAggregations('user.name');
127-
expect(userAggregations).toEqual([
115+
it('should return values depending for user.name input field', () => {
116+
const aggregations = defaultGroupStatsAggregations('user.name');
117+
expect(aggregations).toEqual([
128118
{
129119
unitsCount: {
130120
cardinality: {
@@ -139,13 +129,6 @@ describe('defaultGroupStatsAggregations', () => {
139129
},
140130
},
141131
},
142-
{
143-
countSeveritySubAggregation: {
144-
cardinality: {
145-
field: 'kibana.alert.severity',
146-
},
147-
},
148-
},
149132
{
150133
severitiesSubAggregation: {
151134
terms: {
@@ -161,9 +144,11 @@ describe('defaultGroupStatsAggregations', () => {
161144
},
162145
},
163146
]);
147+
});
164148

165-
const sourceAggregations = defaultGroupStatsAggregations('source.ip');
166-
expect(sourceAggregations).toEqual([
149+
it('should return values depending for source.ip input field', () => {
150+
const aggregations = defaultGroupStatsAggregations('source.ip');
151+
expect(aggregations).toEqual([
167152
{
168153
unitsCount: {
169154
cardinality: {
@@ -178,13 +163,6 @@ describe('defaultGroupStatsAggregations', () => {
178163
},
179164
},
180165
},
181-
{
182-
countSeveritySubAggregation: {
183-
cardinality: {
184-
field: 'kibana.alert.severity',
185-
},
186-
},
187-
},
188166
{
189167
severitiesSubAggregation: {
190168
terms: {

0 commit comments

Comments
 (0)