@@ -12,6 +12,7 @@ import {isAssertViewError} from '@/common-utils';
1212import stripAnsi from 'strip-ansi' ;
1313import { IMAGE_COMPARISON_FAILED_MESSAGE , TestStatus } from '@/constants' ;
1414import { stringify } from '@/static/new-ui/utils' ;
15+ import { EntityType } from '@/static/new-ui/features/suites/components/SuitesPage/types' ;
1516
1617const extractErrors = ( result : ResultEntity , images : ImageEntity [ ] ) : string [ ] => {
1718 const errors = new Set < string > ( ) ;
@@ -48,7 +49,8 @@ const extractErrors = (result: ResultEntity, images: ImageEntity[]): string[] =>
4849const groupTestsByMeta = ( expr : GroupByMetaExpression , resultsById : Record < string , ResultEntity > ) : Record < string , GroupEntity > => {
4950 const DEFAULT_GROUP = `__${ GroupByType . Meta } __DEFAULT_GROUP` ;
5051 const results = Object . values ( resultsById ) ;
51- const groups : Record < string | symbol , GroupEntity > = { } ;
52+ const groupsById : Record < string | symbol , GroupEntity > = { } ;
53+ const groupingKeyToId : Record < string , string > = { } ;
5254 let id = 1 ;
5355
5456 for ( const result of results ) {
@@ -59,28 +61,35 @@ const groupTestsByMeta = (expr: GroupByMetaExpression, resultsById: Record<strin
5961 groupingKey = `${ GroupByType . Meta } __${ expr . key } __${ stringify ( result . metaInfo [ expr . key ] ) } ` ;
6062 }
6163
62- if ( ! groups [ groupingKey ] ) {
63- groups [ groupingKey ] = {
64- id : id . toString ( ) ,
64+ if ( ! groupingKeyToId [ groupingKey ] ) {
65+ groupingKeyToId [ groupingKey ] = id . toString ( ) ;
66+ id ++ ;
67+ }
68+
69+ const groupId = groupingKeyToId [ groupingKey ] ;
70+ if ( ! groupsById [ groupId ] ) {
71+ groupsById [ groupId ] = {
72+ id : groupId ,
6573 key : expr . key ,
6674 label : stringify ( result . metaInfo [ expr . key ] ) ,
6775 resultIds : [ ] ,
68- browserIds : [ ]
76+ browserIds : [ ] ,
77+ type : EntityType . Group
6978 } ;
70- id ++ ;
7179 }
7280
73- groups [ groupingKey ] . resultIds . push ( result . id ) ;
74- if ( ! groups [ groupingKey ] . browserIds . includes ( result . parentId ) ) {
75- groups [ groupingKey ] . browserIds . push ( result . parentId ) ;
81+ groupsById [ groupId ] . resultIds . push ( result . id ) ;
82+ if ( ! groupsById [ groupId ] . browserIds . includes ( result . parentId ) ) {
83+ groupsById [ groupId ] . browserIds . push ( result . parentId ) ;
7684 }
7785 }
7886
79- return groups ;
87+ return groupsById ;
8088} ;
8189
8290const groupTestsByError = ( resultsById : Record < string , ResultEntity > , imagesById : Record < string , ImageEntity > , errorPatterns : State [ 'config' ] [ 'errorPatterns' ] ) : Record < string , GroupEntity > => {
83- const groups : Record < string | symbol , GroupEntity > = { } ;
91+ const groupsById : Record < string | symbol , GroupEntity > = { } ;
92+ const groupingKeyToId : Record < string , string > = { } ;
8493 const results = Object . values ( resultsById ) ;
8594 let id = 1 ;
8695
@@ -101,25 +110,31 @@ const groupTestsByError = (resultsById: Record<string, ResultEntity>, imagesById
101110 groupingKey = `${ GroupByType . Error } __${ errorText } ` ;
102111 }
103112
104- if ( ! groups [ groupingKey ] ) {
105- groups [ groupingKey ] = {
106- id : id . toString ( ) ,
113+ if ( ! groupingKeyToId [ groupingKey ] ) {
114+ groupingKeyToId [ groupingKey ] = id . toString ( ) ;
115+ id ++ ;
116+ }
117+
118+ const groupId = groupingKeyToId [ groupingKey ] ;
119+ if ( ! groupsById [ groupId ] ) {
120+ groupsById [ groupId ] = {
121+ id : groupId ,
107122 key : 'error' ,
108123 label : stripAnsi ( groupLabel ) ,
109124 resultIds : [ ] ,
110- browserIds : [ ]
125+ browserIds : [ ] ,
126+ type : EntityType . Group
111127 } ;
112- id ++ ;
113128 }
114129
115- groups [ groupingKey ] . resultIds . push ( result . id ) ;
116- if ( ! groups [ groupingKey ] . browserIds . includes ( result . parentId ) ) {
117- groups [ groupingKey ] . browserIds . push ( result . parentId ) ;
130+ groupsById [ groupId ] . resultIds . push ( result . id ) ;
131+ if ( ! groupsById [ groupId ] . browserIds . includes ( result . parentId ) ) {
132+ groupsById [ groupId ] . browserIds . push ( result . parentId ) ;
118133 }
119134 }
120135 }
121136
122- return groups ;
137+ return groupsById ;
123138} ;
124139
125140export const groupTests = ( groupByExpressions : GroupByExpression [ ] , resultsById : Record < string , ResultEntity > , imagesById : Record < string , ImageEntity > , errorPatterns : State [ 'config' ] [ 'errorPatterns' ] ) : Record < string , GroupEntity > => {
0 commit comments