1
1
import React from 'react' ;
2
- import { render , screen } from '@testing-library/react' ;
3
- import { SearchActions , State } from '@yext/search-headless-react' ;
4
- import { mockAnswersHooks , spyOnActions } from '../__utils__/mocks' ;
5
- import { FilterOptionConfig } from '../../src/components/Filters' ;
2
+ import { render , screen } from '@testing-library/react' ;
3
+ import { Matcher , SearchActions , State } from '@yext/search-headless-react' ;
4
+ import { mockAnswersHooks , spyOnActions } from '../__utils__/mocks' ;
5
+ import { FilterOptionConfig } from '../../src/components/Filters' ;
6
6
import userEvent from '@testing-library/user-event' ;
7
- import { StaticFilters } from '../../src/components' ;
8
- import { staticFilters , staticFiltersProps } from '../__fixtures__/data/filters' ;
9
- import { testSSR } from '../ssr/utils' ;
7
+ import { StaticFilters , StaticFiltersProps } from '../../src/components' ;
8
+ import { staticFilters , staticFiltersProps } from '../__fixtures__/data/filters' ;
9
+ import { testSSR } from '../ssr/utils' ;
10
+
11
+ const hoursFilterProps : StaticFiltersProps = {
12
+ fieldId : 'builtin.hours' ,
13
+ title : 'Open Now' ,
14
+ filterOptions : [
15
+ {
16
+ value : 'now' ,
17
+ matcher : Matcher . OpenAt
18
+ }
19
+ ]
20
+ } ;
10
21
11
22
const mockedState : Partial < State > = {
12
23
filters : {
@@ -58,6 +69,15 @@ describe('Static Filters', () => {
58
69
expect ( screen . getByText ( 'Clifford' ) ) . toBeDefined ( ) ;
59
70
} ) ;
60
71
72
+ it ( 'Properly renders static filters with Matchers other than Equals' , ( ) => {
73
+ render ( < StaticFilters { ...hoursFilterProps } /> ) ;
74
+
75
+ expect ( screen . getByRole ( 'button' , { name : 'Open Now' } ) ) . toBeDefined ( ) ;
76
+ expect ( screen . queryByRole ( 'textbox' ) ) . toBeNull ( ) ;
77
+
78
+ expect ( screen . getByText ( 'Open Now' ) ) . toBeDefined ( ) ;
79
+ } ) ;
80
+
61
81
it ( 'Clicking an unselected filter option checkbox selects it' , async ( ) => {
62
82
const actions = spyOnActions ( ) ;
63
83
render ( < StaticFilters { ...staticFiltersProps } /> ) ;
@@ -72,6 +92,20 @@ describe('Static Filters', () => {
72
92
expectFilterOptionSet ( actions , staticFiltersProps . fieldId , martyFilter , true ) ;
73
93
} ) ;
74
94
95
+ it ( 'Clicking an unselected openAt filter option checkbox selects it' , async ( ) => {
96
+ const actions = spyOnActions ( ) ;
97
+ render ( < StaticFilters { ...hoursFilterProps } /> ) ;
98
+
99
+ const hoursFilter = hoursFilterProps . filterOptions [ 0 ] ;
100
+ const hoursCheckbox : HTMLInputElement = screen . getByLabelText (
101
+ hoursFilter . displayName ?? hoursFilter . value . toString ( )
102
+ ) ;
103
+ expect ( hoursCheckbox . checked ) . toBeFalsy ( ) ;
104
+
105
+ await userEvent . click ( hoursCheckbox ) ;
106
+ expectFilterOptionSet ( actions , hoursFilterProps . fieldId , hoursFilter , true ) ;
107
+ } ) ;
108
+
75
109
it ( 'Clicking a selected filter option checkbox unselects it' , async ( ) => {
76
110
const actions = spyOnActions ( ) ;
77
111
render ( < StaticFilters { ...staticFiltersProps } /> ) ;
@@ -168,7 +202,7 @@ function expectFilterOptionSet(
168
202
filter : {
169
203
kind : 'fieldValue' ,
170
204
fieldId,
171
- matcher : '$eq' ,
205
+ matcher : filterOption . matcher ?? '$eq' ,
172
206
value : filterOption . value
173
207
} ,
174
208
displayName : filterOption . displayName ?? filterOption . value ,
0 commit comments