@@ -14,18 +14,20 @@ describe('link tooltip in commenting mode', () => {
1414 'pageflow_scrolled.review.link_tooltip.password_protected' : 'Password protected' ,
1515 'pageflow_scrolled.review.link_tooltip.open_preview' : 'Open preview' ,
1616 'pageflow_scrolled.review.link_tooltip.open_draft_preview' : 'Open draft preview' ,
17+ 'pageflow_scrolled.review.link_tooltip.section_in' : 'Section in' ,
1718 'pageflow_scrolled.inline_editing.link_tooltip.opens_in_same_tab' : 'Opens in same tab'
1819 } ) ;
1920
20- function renderLink ( href , { publicationState = 'not_published' } = { } ) {
21+ function renderLink ( href , { publicationState = 'not_published' , chapters } = { } ) {
2122 return renderEntry ( {
2223 seed : {
2324 linkedEntries : [ {
2425 id : 7 ,
2526 title : 'Other story' ,
2627 url : 'https://example.com/other' ,
2728 previewUrl : '/admin/entries/other/preview' ,
28- publicationState
29+ publicationState,
30+ chapters
2931 } ]
3032 } ,
3133 contentElement : { ui : < Link href = { href } > A link</ Link > }
@@ -92,4 +94,43 @@ describe('link tooltip in commenting mode', () => {
9294
9395 expect ( entry . getAllByRole ( 'link' ) ) . toHaveLength ( 1 ) ;
9496 } ) ;
97+
98+ describe ( 'with chapter or section' , ( ) => {
99+ it ( 'offers preview of chapter' , async ( ) => {
100+ const user = userEvent . setup ( ) ;
101+ const entry = renderLink ( { entry : 7 , chapter : 20 , signature : 's' } , {
102+ chapters : [ { permaId : 20 , title : 'New chapter' , slug : 'new-chapter' ,
103+ previewSlug : 'new-chapter' } ]
104+ } ) ;
105+
106+ await user . hover ( entry . getByText ( 'A link' ) ) ;
107+
108+ expect ( entry . getByText ( 'Other story › New chapter' ) ) . toBeInTheDocument ( ) ;
109+ expect ( entry . getByRole ( 'link' , { name : 'Open preview' } ) )
110+ . toHaveAttribute ( 'href' , '/admin/entries/other/preview#new-chapter' ) ;
111+ } ) ;
112+
113+ it ( 'offers preview of section' , async ( ) => {
114+ const user = userEvent . setup ( ) ;
115+ const entry = renderLink ( { entry : 7 , section : 30 , signature : 's' } ) ;
116+
117+ await user . hover ( entry . getByText ( 'A link' ) ) ;
118+
119+ expect ( entry . getByText ( 'Section in Other story' ) ) . toBeInTheDocument ( ) ;
120+ expect ( entry . getByRole ( 'link' , { name : 'Open preview' } ) )
121+ . toHaveAttribute ( 'href' , '/admin/entries/other/preview#section-30' ) ;
122+ } ) ;
123+
124+ it ( 'does not display tooltip for chapters of published entries' , async ( ) => {
125+ const user = userEvent . setup ( ) ;
126+ const entry = renderLink ( { entry : 7 , chapter : 20 , signature : 's' } , {
127+ publicationState : 'published_without_password_protection' ,
128+ chapters : [ { permaId : 20 , title : 'Intro' , slug : 'intro' , previewSlug : 'intro' } ]
129+ } ) ;
130+
131+ await user . hover ( entry . getByText ( 'A link' ) ) ;
132+
133+ expect ( entry . getAllByRole ( 'link' ) ) . toHaveLength ( 1 ) ;
134+ } ) ;
135+ } ) ;
95136} ) ;
0 commit comments