@@ -95,31 +95,14 @@ beforeEach(() => {
9595} )
9696
9797describe ( 'SelectorCombobox label hydration' , ( ) => {
98- it . each ( [
99- {
100- state : 'preview' ,
101- isPreview : true ,
102- disabled : false ,
103- previewValue : 'preview-label' ,
104- detailId : 'preview-label' ,
105- } ,
106- {
107- state : 'disabled' ,
108- isPreview : false ,
109- disabled : true ,
110- previewValue : undefined ,
111- detailId : 'stored-label' ,
112- } ,
113- ] ) ( 'keeps the list disabled but hydrates the selected value when $state' , ( state ) => {
98+ it ( 'renders a hydrated selected label while disabled without enabling the list' , ( ) => {
11499 const html = renderToStaticMarkup (
115100 < SelectorCombobox
116101 blockId = 'block-1'
117102 subBlock = { { id : 'label' , title : 'Label' , type : 'combobox' } }
118103 selectorKey = 'jira.issues'
119104 selectorContext = { { workspaceId : 'workspace-1' , oauthCredential : 'credential-1' } }
120- isPreview = { state . isPreview }
121- disabled = { state . disabled }
122- previewValue = { state . previewValue }
105+ disabled
123106 />
124107 )
125108
@@ -130,72 +113,14 @@ describe('SelectorCombobox label hydration', () => {
130113 )
131114 expect ( mockUseSelectorOptionDetail ) . toHaveBeenCalledWith (
132115 'jira.issues' ,
133- expect . objectContaining ( { detailId : state . detailId , enabled : true } )
116+ expect . objectContaining ( { detailId : 'stored-label' , enabled : true } )
134117 )
135118 } )
136119
137- it . each ( [
138- {
139- state : 'preview' ,
140- isPreview : true ,
141- disabled : false ,
142- previewValue : [ 'preview-label' , '{{SHARED_LABEL}}' , '<Block.output>' ] ,
143- detailIds : [ 'preview-label' , '{{SHARED_LABEL}}' ] ,
144- } ,
145- {
146- state : 'disabled' ,
147- isPreview : false ,
148- disabled : true ,
149- previewValue : undefined ,
150- detailIds : [ 'stored-one' , 'stored-two' ] ,
151- } ,
152- ] ) ( 'hydrates selected multi-values without enabling the list when $state' , ( state ) => {
153- if ( ! state . isPreview ) selectorState . storeValue = [ 'stored-one' , 'stored-two' ]
154-
155- const html = renderToStaticMarkup (
156- < SelectorCombobox
157- blockId = 'block-1'
158- subBlock = { { id : 'labels' , title : 'Labels' , type : 'combobox' } }
159- selectorKey = 'jira.issues'
160- selectorContext = { { workspaceId : 'workspace-1' , oauthCredential : 'credential-1' } }
161- isPreview = { state . isPreview }
162- disabled = { state . disabled }
163- previewValue = { state . previewValue }
164- multiSelect
165- />
166- )
167-
168- for ( const id of state . detailIds ) expect ( html ) . toContain ( `Hydrated ${ id } ` )
169- if ( state . isPreview ) expect ( html ) . toContain ( '<Block.output>' )
170- expect ( mockUseSelectorOptions ) . toHaveBeenCalledWith (
171- 'jira.issues' ,
172- expect . objectContaining ( { enabled : false } )
173- )
174- expect ( mockUseSelectorOptionDetails ) . toHaveBeenCalledWith (
175- 'jira.issues' ,
176- expect . objectContaining ( { detailIds : state . detailIds , enabled : true } )
177- )
178- } )
179-
180- it . each ( [
181- {
182- state : 'preview' ,
183- isPreview : true ,
184- disabled : false ,
185- previewValue : [ 'preview-label' , '{{SHARED_LABEL}}' , '<Block.output>' ] ,
186- listedValues : [ 'preview-label' ] ,
187- } ,
188- {
189- state : 'disabled' ,
190- isPreview : false ,
191- disabled : true ,
192- previewValue : undefined ,
193- listedValues : [ 'stored-one' , 'stored-two' ] ,
194- } ,
195- ] ) ( 'uses a search-free list to hydrate no-detail multi-values when $state' , ( state ) => {
196- if ( ! state . isPreview ) selectorState . storeValue = [ 'stored-one' , 'stored-two' ]
120+ it ( 'renders preview labels from a search-free list when detail lookup is unsupported' , ( ) => {
121+ const previewValue = [ 'preview-label' , '{{SHARED_LABEL}}' , '<Block.output>' ]
197122 mockUseSelectorOptions . mockReturnValue ( {
198- data : state . listedValues . map ( ( id ) => ( { id, label : ` Listed ${ id } ` } ) ) ,
123+ data : [ { id : 'preview-label' , label : ' Listed preview-label' } ] ,
199124 isLoading : false ,
200125 hasMore : false ,
201126 error : null ,
@@ -207,18 +132,15 @@ describe('SelectorCombobox label hydration', () => {
207132 subBlock = { { id : 'labels' , title : 'Labels' , type : 'combobox' } }
208133 selectorKey = 'gmail.labels'
209134 selectorContext = { { workspaceId : 'workspace-1' , oauthCredential : 'credential-1' } }
210- isPreview = { state . isPreview }
211- disabled = { state . disabled }
212- previewValue = { state . previewValue }
135+ isPreview
136+ previewValue = { previewValue }
213137 multiSelect
214138 />
215139 )
216140
217- for ( const id of state . listedValues ) expect ( html ) . toContain ( `Listed ${ id } ` )
218- if ( state . isPreview ) {
219- expect ( html ) . toContain ( '{{SHARED_LABEL}}' )
220- expect ( html ) . toContain ( '<Block.output>' )
221- }
141+ expect ( html ) . toContain ( 'Listed preview-label' )
142+ expect ( html ) . toContain ( '{{SHARED_LABEL}}' )
143+ expect ( html ) . toContain ( '<Block.output>' )
222144 expect ( mockUseSelectorOptions ) . toHaveBeenCalledWith (
223145 'gmail.labels' ,
224146 expect . objectContaining ( { enabled : true , search : undefined } )
@@ -228,24 +150,4 @@ describe('SelectorCombobox label hydration', () => {
228150 expect . objectContaining ( { enabled : false } )
229151 )
230152 } )
231-
232- it ( 'does not detail-hydrate a runtime reference' , ( ) => {
233- selectorState . storeValue = '<Block.output>'
234-
235- const html = renderToStaticMarkup (
236- < SelectorCombobox
237- blockId = 'block-1'
238- subBlock = { { id : 'label' , title : 'Label' , type : 'combobox' } }
239- selectorKey = 'gmail.labels'
240- selectorContext = { { workspaceId : 'workspace-1' , oauthCredential : 'credential-1' } }
241- disabled
242- />
243- )
244-
245- expect ( html ) . toContain ( '<Block.output>' )
246- expect ( mockUseSelectorOptionDetail ) . toHaveBeenCalledWith (
247- 'gmail.labels' ,
248- expect . objectContaining ( { detailId : undefined , enabled : false } )
249- )
250- } )
251153} )
0 commit comments