11import { remapToApiFilters } from '../util/filters'
22import {
33 formatSegmentIdAsLabelKey ,
4- getSearchToApplySingleSegmentFilter ,
4+ getSearchToSetSegmentFilter ,
55 getSegmentNamePlaceholder ,
66 isSegmentIdLabelKey ,
77 parseApiSegmentData ,
@@ -64,9 +64,57 @@ describe(`${parseApiSegmentData.name}`, () => {
6464 } )
6565} )
6666
67- describe ( `${ getSearchToApplySingleSegmentFilter . name } ` , ( ) => {
68- test ( 'generated search function applies single segment correctly' , ( ) => {
69- const searchFunction = getSearchToApplySingleSegmentFilter ( {
67+ describe ( `${ getSearchToSetSegmentFilter . name } ` , ( ) => {
68+ test ( 'generated search function omits other filters segment correctly' , ( ) => {
69+ const searchFunction = getSearchToSetSegmentFilter (
70+ {
71+ name : 'APAC' ,
72+ id : 500
73+ } ,
74+ { omitAllOtherFilters : true }
75+ )
76+ const existingSearch = {
77+ date : '2025-02-10' ,
78+ filters : [
79+ [ 'is' , 'country' , [ 'US' ] ] ,
80+ [ 'is' , 'page' , [ '/blog' ] ]
81+ ] ,
82+ labels : { US : 'United States' }
83+ }
84+ expect ( searchFunction ( existingSearch ) ) . toEqual ( {
85+ date : '2025-02-10' ,
86+ filters : [ [ 'is' , 'segment' , [ 500 ] ] ] ,
87+ labels : { 'segment-500' : 'APAC' }
88+ } )
89+ } )
90+
91+ test ( 'generated search function replaces existing segment filter correctly' , ( ) => {
92+ const searchFunction = getSearchToSetSegmentFilter ( {
93+ name : 'APAC' ,
94+ id : 500
95+ } )
96+ const existingSearch = {
97+ date : '2025-02-10' ,
98+ filters : [
99+ [ 'is' , 'segment' , [ 100 ] ] ,
100+ [ 'is' , 'country' , [ 'US' ] ] ,
101+ [ 'is' , 'page' , [ '/blog' ] ]
102+ ] ,
103+ labels : { US : 'United States' , 'segment-100' : 'Scandinavia' }
104+ }
105+ expect ( searchFunction ( existingSearch ) ) . toEqual ( {
106+ date : '2025-02-10' ,
107+ filters : [
108+ [ 'is' , 'segment' , [ 500 ] ] ,
109+ [ 'is' , 'country' , [ 'US' ] ] ,
110+ [ 'is' , 'page' , [ '/blog' ] ]
111+ ] ,
112+ labels : { US : 'United States' , 'segment-500' : 'APAC' }
113+ } )
114+ } )
115+
116+ test ( 'generated search function sets new segment filter correctly' , ( ) => {
117+ const searchFunction = getSearchToSetSegmentFilter ( {
70118 name : 'APAC' ,
71119 id : 500
72120 } )
@@ -80,8 +128,12 @@ describe(`${getSearchToApplySingleSegmentFilter.name}`, () => {
80128 }
81129 expect ( searchFunction ( existingSearch ) ) . toEqual ( {
82130 date : '2025-02-10' ,
83- filters : [ [ 'is' , 'segment' , [ 500 ] ] ] ,
84- labels : { 'segment-500' : 'APAC' }
131+ filters : [
132+ [ 'is' , 'segment' , [ 500 ] ] ,
133+ [ 'is' , 'country' , [ 'US' ] ] ,
134+ [ 'is' , 'page' , [ '/blog' ] ]
135+ ] ,
136+ labels : { US : 'United States' , 'segment-500' : 'APAC' }
85137 } )
86138 } )
87139} )
0 commit comments