@@ -132,27 +132,35 @@ describe('SearchQueryBuilder', function () {
132132 render (
133133 < SearchQueryBuilder
134134 { ...defaultProps }
135- initialQuery = ""
135+ initialQuery = "a "
136136 onChange = { mockOnChange }
137137 onBlur = { mockOnBlur }
138138 onSearch = { mockOnSearch }
139139 />
140140 ) ;
141141
142142 await userEvent . click ( getLastInput ( ) ) ;
143- await userEvent . keyboard ( 'foo{enter}' ) ;
143+ await userEvent . keyboard ( 'b{enter}' ) ;
144+
145+ const expectedQueryState = expect . objectContaining ( {
146+ parsedQuery : expect . arrayContaining ( [ expect . any ( Object ) ] ) ,
147+ queryIsValid : true ,
148+ } ) ;
144149
145150 // Should call onChange and onSearch after enter
146151 await waitFor ( ( ) => {
147- expect ( mockOnChange ) . toHaveBeenCalledWith ( 'foo' ) ;
148- expect ( mockOnSearch ) . toHaveBeenCalledWith ( 'foo' ) ;
152+ expect ( mockOnChange ) . toHaveBeenCalledTimes ( 1 ) ;
153+ expect ( mockOnChange ) . toHaveBeenCalledWith ( 'ab' , expectedQueryState ) ;
154+ expect ( mockOnSearch ) . toHaveBeenCalledTimes ( 1 ) ;
155+ expect ( mockOnSearch ) . toHaveBeenCalledWith ( 'ab' , expectedQueryState ) ;
149156 } ) ;
150157
151158 await userEvent . click ( document . body ) ;
152159
153160 // Clicking outside activates onBlur
154161 await waitFor ( ( ) => {
155- expect ( mockOnBlur ) . toHaveBeenCalledWith ( 'foo' ) ;
162+ expect ( mockOnBlur ) . toHaveBeenCalledTimes ( 1 ) ;
163+ expect ( mockOnBlur ) . toHaveBeenCalledWith ( 'ab' , expectedQueryState ) ;
156164 } ) ;
157165 } ) ;
158166 } ) ;
@@ -172,8 +180,8 @@ describe('SearchQueryBuilder', function () {
172180 userEvent . click ( screen . getByRole ( 'button' , { name : 'Clear search query' } ) ) ;
173181
174182 await waitFor ( ( ) => {
175- expect ( mockOnChange ) . toHaveBeenCalledWith ( '' ) ;
176- expect ( mockOnSearch ) . toHaveBeenCalledWith ( '' ) ;
183+ expect ( mockOnChange ) . toHaveBeenCalledWith ( '' , expect . anything ( ) ) ;
184+ expect ( mockOnSearch ) . toHaveBeenCalledWith ( '' , expect . anything ( ) ) ;
177185 } ) ;
178186
179187 expect (
@@ -253,7 +261,10 @@ describe('SearchQueryBuilder', function () {
253261 expect ( screen . getByRole ( 'textbox' ) ) . toHaveValue ( 'browser.name:firefox assigned:me' ) ;
254262
255263 await waitFor ( ( ) => {
256- expect ( mockOnChange ) . toHaveBeenLastCalledWith ( 'browser.name:firefox assigned:me' ) ;
264+ expect ( mockOnChange ) . toHaveBeenLastCalledWith (
265+ 'browser.name:firefox assigned:me' ,
266+ expect . anything ( )
267+ ) ;
257268 } ) ;
258269 } ) ;
259270 } ) ;
@@ -534,7 +545,7 @@ describe('SearchQueryBuilder', function () {
534545 await userEvent . click ( getLastInput ( ) ) ;
535546 await userEvent . type ( screen . getByRole ( 'combobox' ) , 'some free text{enter}' ) ;
536547 await waitFor ( ( ) => {
537- expect ( mockOnSearch ) . toHaveBeenCalledWith ( 'some free text' ) ;
548+ expect ( mockOnSearch ) . toHaveBeenCalledWith ( 'some free text' , expect . anything ( ) ) ;
538549 } ) ;
539550 // Should still have text in the input
540551 expect ( screen . getByRole ( 'combobox' ) ) . toHaveValue ( 'some free text' ) ;
@@ -831,7 +842,7 @@ describe('SearchQueryBuilder', function () {
831842
832843 // Pressing delete should remove all selected tokens
833844 await userEvent . keyboard ( '{Backspace}' ) ;
834- expect ( mockOnChange ) . toHaveBeenCalledWith ( '' ) ;
845+ expect ( mockOnChange ) . toHaveBeenCalledWith ( '' , expect . anything ( ) ) ;
835846 } ) ;
836847
837848 it ( 'focus goes to first input after ctrl+a and arrow left' , async function ( ) {
@@ -933,7 +944,7 @@ describe('SearchQueryBuilder', function () {
933944 await userEvent . keyboard ( '{Control>}x{/Control}' ) ;
934945
935946 expect ( navigator . clipboard . writeText ) . toHaveBeenCalledWith ( 'browser.name:firefox' ) ;
936- expect ( mockOnChange ) . toHaveBeenCalledWith ( '' ) ;
947+ expect ( mockOnChange ) . toHaveBeenCalledWith ( '' , expect . anything ( ) ) ;
937948 } ) ;
938949
939950 it ( 'can undo last action with ctrl-z' , async function ( ) {
@@ -1118,7 +1129,7 @@ describe('SearchQueryBuilder', function () {
11181129 ) ;
11191130 await userEvent . click ( await screen . findByRole ( 'option' , { name : 'does not have' } ) ) ;
11201131 await waitFor ( ( ) => {
1121- expect ( mockOnChange ) . toHaveBeenCalledWith ( '!has:key' ) ;
1132+ expect ( mockOnChange ) . toHaveBeenCalledWith ( '!has:key' , expect . anything ( ) ) ;
11221133 } ) ;
11231134 expect (
11241135 within (
@@ -1311,7 +1322,10 @@ describe('SearchQueryBuilder', function () {
13111322
13121323 // Value should be surrounded by quotes and escaped
13131324 await waitFor ( ( ) => {
1314- expect ( mockOnChange ) . toHaveBeenCalledWith ( `browser.name:${ expected } ` ) ;
1325+ expect ( mockOnChange ) . toHaveBeenCalledWith (
1326+ `browser.name:${ expected } ` ,
1327+ expect . anything ( )
1328+ ) ;
13151329 } ) ;
13161330 } ) ;
13171331
@@ -1826,7 +1840,7 @@ describe('SearchQueryBuilder', function () {
18261840 ) . toBeInTheDocument ( ) ;
18271841
18281842 await waitFor ( ( ) => {
1829- expect ( mockOnChange ) . toHaveBeenCalledWith ( 'foo age:-1h' ) ;
1843+ expect ( mockOnChange ) . toHaveBeenCalledWith ( 'foo age:-1h' , expect . anything ( ) ) ;
18301844 } ) ;
18311845 } ) ;
18321846
@@ -1854,7 +1868,7 @@ describe('SearchQueryBuilder', function () {
18541868 ) . toBeInTheDocument ( ) ;
18551869
18561870 await waitFor ( ( ) => {
1857- expect ( mockOnChange ) . toHaveBeenCalledWith ( 'foo age:+1h' ) ;
1871+ expect ( mockOnChange ) . toHaveBeenCalledWith ( 'foo age:+1h' , expect . anything ( ) ) ;
18581872 } ) ;
18591873 } ) ;
18601874
@@ -1876,7 +1890,7 @@ describe('SearchQueryBuilder', function () {
18761890 await userEvent . click ( screen . getByRole ( 'button' , { name : 'Save' } ) ) ;
18771891
18781892 await waitFor ( ( ) => {
1879- expect ( mockOnChange ) . toHaveBeenCalledWith ( 'age:>2017-10-17' ) ;
1893+ expect ( mockOnChange ) . toHaveBeenCalledWith ( 'age:>2017-10-17' , expect . anything ( ) ) ;
18801894 } ) ;
18811895 } ) ;
18821896
@@ -1899,7 +1913,10 @@ describe('SearchQueryBuilder', function () {
18991913 await userEvent . click ( await screen . findByRole ( 'button' , { name : 'Save' } ) ) ;
19001914
19011915 await waitFor ( ( ) => {
1902- expect ( mockOnChange ) . toHaveBeenCalledWith ( 'age:>2017-10-17T00:00:00Z' ) ;
1916+ expect ( mockOnChange ) . toHaveBeenCalledWith (
1917+ 'age:>2017-10-17T00:00:00Z' ,
1918+ expect . anything ( )
1919+ ) ;
19031920 } ) ;
19041921 } ) ;
19051922
@@ -1923,7 +1940,10 @@ describe('SearchQueryBuilder', function () {
19231940 await userEvent . click ( await screen . findByRole ( 'button' , { name : 'Save' } ) ) ;
19241941
19251942 await waitFor ( ( ) => {
1926- expect ( mockOnChange ) . toHaveBeenCalledWith ( 'age:>2017-10-17T00:00:00+00:00' ) ;
1943+ expect ( mockOnChange ) . toHaveBeenCalledWith (
1944+ 'age:>2017-10-17T00:00:00+00:00' ,
1945+ expect . anything ( )
1946+ ) ;
19271947 } ) ;
19281948 } ) ;
19291949
0 commit comments