File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -451,6 +451,23 @@ describe('AddSidebar', () => {
451451 expect ( clearSelection ) . not . toHaveBeenCalled ( ) ;
452452 } ) ;
453453
454+ it ( 'back from subsection without section clears selection' , async ( ) => {
455+ const user = userEvent . setup ( ) ;
456+ const section = outlineChildren [ 0 ] ;
457+ const subsection = section . childInfo . children [ 0 ] ;
458+ selectedContainerState = {
459+ currentId : subsection . id ,
460+ subsectionId : subsection . id ,
461+ } ;
462+ renderComponent ( ) ;
463+
464+ const back = await screen . findByRole ( 'button' , { name : 'Back' } ) ;
465+ await user . click ( back ) ;
466+
467+ expect ( clearSelection ) . toHaveBeenCalled ( ) ;
468+ expect ( openContainerSidebar ) . not . toHaveBeenCalled ( ) ;
469+ } ) ;
470+
454471 it ( 'back from section clears selection' , async ( ) => {
455472 const user = userEvent . setup ( ) ;
456473 const section = outlineChildren [ 0 ] ;
Original file line number Diff line number Diff line change @@ -401,8 +401,12 @@ export const AddSidebar = () => {
401401 const subsectionIndex = section
402402 ?. childInfo . children . findIndex ( ( subsection ) => subsection . id === subsectionId ) ?? - 1 ;
403403
404- if ( currentId === subsectionId && sectionId ) {
405- openContainerSidebar ( sectionId , undefined , sectionId , sectionIndex >= 0 ? sectionIndex : undefined ) ;
404+ if ( currentId === subsectionId ) {
405+ if ( sectionId ) {
406+ openContainerSidebar ( sectionId , undefined , sectionId , sectionIndex >= 0 ? sectionIndex : undefined ) ;
407+ return ;
408+ }
409+ clearSelection ( ) ;
406410 return ;
407411 }
408412
Original file line number Diff line number Diff line change @@ -157,6 +157,28 @@ describe('OutlineAlignSidebar', () => {
157157 } ) ;
158158 } ) ;
159159
160+ it ( 'back button from subsection without section clears selection' , async ( ) => {
161+ jest
162+ . spyOn ( OutlineSidebarContext , 'useOutlineSidebarContext' )
163+ . mockReturnValue ( {
164+ selectedContainerState : {
165+ currentId : 'subsection-1' ,
166+ subsectionId : 'subsection-1' ,
167+ } ,
168+ clearSelection,
169+ openContainerSidebar,
170+ } as any ) ;
171+
172+ render ( < OutlineAlignSidebar /> ) ;
173+
174+ const backButton = await screen . findByRole ( 'button' , { name : / b a c k / i } ) ;
175+ backButton . click ( ) ;
176+
177+ expect ( clearSelection ) . toHaveBeenCalled ( ) ;
178+ expect ( setCurrentSelection ) . toHaveBeenCalledWith ( undefined ) ;
179+ expect ( openContainerSidebar ) . not . toHaveBeenCalled ( ) ;
180+ } ) ;
181+
160182 it ( 'back button from section clears selection' , async ( ) => {
161183 jest
162184 . spyOn ( OutlineSidebarContext , 'useOutlineSidebarContext' )
Original file line number Diff line number Diff line change @@ -30,13 +30,18 @@ export const OutlineAlignSidebar = () => {
3030 return ;
3131 }
3232
33- if ( currentId === subsectionId && sectionId ) {
34- openContainerSidebar ( sectionId , undefined , sectionId , sectionIndex >= 0 ? sectionIndex : undefined ) ;
35- setCurrentSelection ( {
36- currentId : sectionId ,
37- sectionId,
38- index : sectionIndex >= 0 ? sectionIndex : undefined ,
39- } ) ;
33+ if ( currentId === subsectionId ) {
34+ if ( sectionId ) {
35+ openContainerSidebar ( sectionId , undefined , sectionId , sectionIndex >= 0 ? sectionIndex : undefined ) ;
36+ setCurrentSelection ( {
37+ currentId : sectionId ,
38+ sectionId,
39+ index : sectionIndex >= 0 ? sectionIndex : undefined ,
40+ } ) ;
41+ return ;
42+ }
43+ clearSelection ( ) ;
44+ setCurrentSelection ( undefined ) ;
4045 return ;
4146 }
4247
You can’t perform that action at this time.
0 commit comments