11import { render , screen , waitFor } from "@testing-library/react" ;
2+ import React from "react" ;
23import { describe , expect , it , vi , beforeEach } from "vitest" ;
34import type { Mock } from "vitest" ;
45
@@ -49,9 +50,10 @@ const mockAttributesWithSingleSelect = () => {
4950 slug : "department" ,
5051 name : "Department" ,
5152 type : AttributeType . SINGLE_SELECT ,
53+ isWeightsEnabled : false ,
5254 options : [
53- { id : "1" , value : "Sales" , slug : "sales" } ,
54- { id : "2" , value : "Engineering" , slug : "engineering" } ,
55+ { id : "1" , value : "Sales" , slug : "sales" , contains : [ ] , isGroup : false } ,
56+ { id : "2" , value : "Engineering" , slug : "engineering" , contains : [ ] , isGroup : false } ,
5557 ] ,
5658 } ,
5759 ] ,
@@ -85,9 +87,24 @@ vi.mock("@calcom/lib/hooks/useLocale", () => ({
8587} ) ) ;
8688
8789describe ( "Segment" , ( ) => {
90+ const defaultQueryValue = {
91+ id : "root" ,
92+ type : "group" ,
93+ children1 : {
94+ "rule-1" : {
95+ type : "rule" ,
96+ properties : {
97+ field : "department" ,
98+ operator : "select_equals" ,
99+ value : [ "Sales" ] ,
100+ } ,
101+ } ,
102+ } ,
103+ } as AttributesQueryValue ;
104+
88105 const defaultProps = {
89106 teamId : 1 ,
90- queryValue : null as AttributesQueryValue | null ,
107+ queryValue : defaultQueryValue ,
91108 onQueryValueChange : vi . fn ( ) ,
92109 className : "test-class" ,
93110 } ;
@@ -132,7 +149,25 @@ describe("Segment", () => {
132149 } ) ;
133150 } ) ;
134151
135- it ( "shows matching team members when query value is provided" , async ( ) => {
152+ it ( "shows no filter selected message when empty query value is provided" , async ( ) => {
153+ mockGetMatchingTeamMembers ( {
154+ isPending : true ,
155+ data : undefined ,
156+ } ) ;
157+
158+ const emptyQueryValue = {
159+ id : "root" ,
160+ type : "group" ,
161+ children1 : { } ,
162+ } as AttributesQueryValue ;
163+
164+ render ( < Segment { ...defaultProps } queryValue = { emptyQueryValue } /> ) ;
165+ await waitFor ( ( ) => {
166+ expect ( screen . getByText ( "no_filter_set" ) ) . toBeInTheDocument ( ) ;
167+ } ) ;
168+ } ) ;
169+
170+ it ( "shows matching team members when valid query value is provided" , async ( ) => {
136171 mockGetMatchingTeamMembers ( {
137172 isPending : false ,
138173 data : {
@@ -149,12 +184,7 @@ describe("Segment", () => {
149184 } ,
150185 } ) ;
151186
152- const queryValue = {
153- id : "root" ,
154- type : "group" ,
155- } as AttributesQueryValue ;
156-
157- render ( < Segment { ...defaultProps } queryValue = { queryValue } /> ) ;
187+ render ( < Segment { ...defaultProps } queryValue = { defaultQueryValue } /> ) ;
158188 await waitFor ( ( ) => {
159189 expect ( screen . getByText ( "John Doe" ) ) . toBeInTheDocument ( ) ;
160190 expect ( screen . getByText ( "(john@example.com)" ) ) . toBeInTheDocument ( ) ;
0 commit comments