@@ -935,12 +935,12 @@ describe('DataChunks.addClusterFacet()', () => {
935
935
d . load ( chunks ) ;
936
936
937
937
// Define a facet function
938
- d . addFacet ( 'url' , ( bundle ) => [ bundle . url ] ) ;
938
+ d . addFacet ( 'url' , ( bundle ) => [ bundle . url ] , 'some' , 'never' ) ;
939
939
940
940
// Add a cluster facet based on the 'url' facet
941
941
d . addClusterFacet ( 'urlCluster' , 'url' , {
942
942
count : Math . log10 ( d . facets . url . length ) ,
943
- } ) ;
943
+ } , 'some' , 'never' ) ;
944
944
945
945
const { facets } = d ;
946
946
@@ -951,35 +951,62 @@ describe('DataChunks.addClusterFacet()', () => {
951
951
assert . equal ( facets . urlCluster [ 2 ] . value , 'https://www.aem.live/developer/tutorial' ) ;
952
952
} ) ;
953
953
954
+ it ( 'should handle null facetMatch gracefully' , ( ) => {
955
+ const d = new DataChunks ( ) ;
956
+ d . load ( chunks ) ;
957
+
958
+ // Define a facet function
959
+ d . addFacet ( 'url' , ( bundle ) => [ bundle . url ] , 'some' , 'never' ) ;
960
+
961
+ // Add a cluster facet based on the 'url' facet
962
+ d . addClusterFacet ( 'urlCluster' , 'url' , {
963
+ count : Math . log10 ( d . facets . url . length ) ,
964
+ } , 'some' , 'never' ) ;
965
+
966
+ // Simulate a null facetMatch scenario
967
+ const facetMatch = null ;
968
+ const producer = ( value ) => [ value , value ] ;
969
+ const clusters = ( facetMatch && producer ( facetMatch . value ) ) || [ ] ;
970
+
971
+ assert . deepEqual ( clusters , [ ] ) ;
972
+ } ) ;
973
+
954
974
it ( 'should handle empty facet values gracefully' , ( ) => {
955
975
const d = new DataChunks ( ) ;
956
976
d . load ( [ ] ) ;
957
977
958
978
// Define a facet function
959
- d . addFacet ( 'url' , ( bundle ) => [ bundle . url ] ) ;
979
+ d . addFacet ( 'url' , ( bundle ) => [ bundle . url ] , 'some' , 'never' ) ;
960
980
961
981
// Add a cluster facet based on the 'url' facet
962
982
d . addClusterFacet ( 'urlCluster' , 'url' , {
963
983
count : Math . log10 ( d . facets . url . length ) ,
964
- } ) ;
984
+ } , 'some' , 'never' ) ;
965
985
966
986
const { facets } = d ;
967
987
968
988
assert . equal ( facets . urlCluster . length , 0 ) ;
989
+
990
+ // Simulate an empty facetMatch scenario
991
+ const facetMatch = { } ;
992
+ const producer = ( value ) => [ value , value ] ;
993
+ const clusters = ( facetMatch && producer ( facetMatch . value ) ) || [ ] ;
994
+
995
+ assert . deepEqual ( clusters , [ undefined , undefined ] ) ;
969
996
} ) ;
970
997
971
998
it ( 'should log the correct cluster count' , ( ) => {
972
999
const d = new DataChunks ( ) ;
973
1000
d . load ( chunks ) ;
974
1001
975
1002
// Define a facet function
976
- d . addFacet ( 'url' , ( bundle ) => [ bundle . url ] ) ;
1003
+ d . addFacet ( 'url' , ( bundle ) => [ bundle . url ] , 'some' , 'never' ) ;
977
1004
978
1005
// Add a cluster facet based on the 'url' facet
979
1006
const count = Math . floor ( Math . log10 ( 92 ) ) ;
980
1007
d . addClusterFacet ( 'urlCluster' , 'url' , {
981
1008
count,
982
- } ) ;
1009
+ } , 'some' , 'never' ) ;
983
1010
984
1011
// Check if the count is correct
985
1012
assert . strictEqual ( count , 1 ) ;
@@ -990,12 +1017,12 @@ describe('DataChunks.addClusterFacet()', () => {
990
1017
d . load ( chunks ) ;
991
1018
992
1019
// Define a facet function
993
- d . addFacet ( 'url' , ( bundle ) => [ bundle . url ] ) ;
1020
+ d . addFacet ( 'url' , ( bundle ) => [ bundle . url ] , 'some' , 'never' ) ;
994
1021
995
1022
// Add a cluster facet based on the 'url' facet
996
1023
d . addClusterFacet ( 'urlCluster' , 'url' , {
997
1024
count : Math . log10 ( d . facets . url . length ) ,
998
- } ) ;
1025
+ } , 'some' , 'never' ) ;
999
1026
1000
1027
const { facets } = d ;
1001
1028
0 commit comments