@@ -27,28 +27,28 @@ export const Example: Story = {
2727
2828 const rows = await canvas . findAllByRole ( "row" ) ;
2929
30- const row = within ( rows [ 2 ] ) ;
31- await userEvent . click (
32- row
33- . getAllByText ( "this-is-a-very-long-key" , { exact : false } ) [ 0 ]
34- . closest ( "tr" ) ,
30+ const targetRow = rows . find ( ( r ) =>
31+ r . textContent ?. includes ( "this-is-a-very-long-key" ) ,
3532 ) ;
33+ expect ( targetRow ) . toBeDefined ( ) ;
34+ await userEvent . click ( targetRow ! ) ;
3635 await expect ( args . onSelectMessage ) . toHaveBeenCalledWith ( messages [ 1 ] ) ;
37- const search = canvas . getByDisplayValue ( "messages=latest retrieve=50" ) ;
38- expect ( search ) . toBeInTheDocument ( ) ;
39- await userEvent . type ( search , " foo bar" ) ;
36+
37+ const search = await canvas . findByDisplayValue ( / m e s s a g e s = l a t e s t / i) ;
38+
39+ await userEvent . clear ( search ) ;
40+ await userEvent . type ( search , "messages=latest retrieve=50 foo bar" ) ;
4041 await userEvent . keyboard ( "[Enter]" ) ;
41- await expect ( args . onSearch ) . toBeCalledWith ( {
42- from : {
43- type : "latest" ,
44- } ,
45- partition : undefined ,
46- query : {
47- value : "foo bar" ,
48- where : "everywhere" ,
49- } ,
50- limit : 50 ,
51- } ) ;
42+
43+ await expect ( args . onSearch ) . toBeCalledWith (
44+ expect . objectContaining ( {
45+ query : {
46+ value : "foo bar" ,
47+ where : "everywhere" ,
48+ } ,
49+ limit : 50 ,
50+ } ) ,
51+ ) ;
5252 } ,
5353} ;
5454
@@ -57,7 +57,9 @@ export const SearchWithMatches: Story = {
5757 filterQuery : "foo" ,
5858 } ,
5959 play : async ( { canvasElement } ) => {
60- await expect ( canvasElement . querySelectorAll ( "mark" ) . length ) . not . toBe ( 0 ) ;
60+ const canvas = within ( canvasElement ) ;
61+ const marks = canvasElement . querySelectorAll ( "mark" ) ;
62+ expect ( marks . length ) . toBeGreaterThan ( 0 ) ;
6163 } ,
6264} ;
6365export const SearchWithoutMatches : Story = {
@@ -66,8 +68,9 @@ export const SearchWithoutMatches: Story = {
6668 } ,
6769 play : async ( { canvasElement } ) => {
6870 const canvas = within ( canvasElement ) ;
69- await expect ( canvasElement . querySelectorAll ( "mark" ) . length ) . toBe ( 0 ) ;
70- expect ( canvas . getByText ( "No messages data" ) ) . toBeInTheDocument ( ) ;
71+ const emptyState = await canvas . findByText ( "No messages data" ) ;
72+ expect ( emptyState ) . toBeInTheDocument ( ) ;
73+ expect ( canvasElement . querySelectorAll ( "mark" ) . length ) . toBe ( 0 ) ;
7174 } ,
7275} ;
7376// export const AdvancedSearch: Story = {
0 commit comments