@@ -46,6 +46,8 @@ async function setupPermalinkTest(
4646 return page . frameLocator ( 'iframe[title="comments-frame"]' ) ;
4747}
4848
49+ const TALL_BODY_HTML = '<html><head><meta charset="UTF-8" /></head><body><div style="width: 100%; height: 1500px;"></div></body></html>' ;
50+
4951test . describe ( 'Comment Permalinks' , async ( ) => {
5052 test ( 'timestamp is a link with correct permalink href' , async ( { page} ) => {
5153 const mockedApi = new MockedApi ( { } ) ;
@@ -100,8 +102,7 @@ test.describe('Comment Permalinks', async () => {
100102 } ) ;
101103
102104 // Include a tall div to push comments below viewport (like lazy-loading test)
103- const tallBodyHtml = '<html><head><meta charset="UTF-8" /></head><body><div style="width: 100%; height: 1500px;"></div></body></html>' ;
104- const commentsFrame = await setupPermalinkTest ( page , mockedApi , `#ghost-comments-${ commentId } ` , tallBodyHtml ) ;
105+ const commentsFrame = await setupPermalinkTest ( page , mockedApi , `#ghost-comments-${ commentId } ` , TALL_BODY_HTML ) ;
105106
106107 await page . locator ( 'iframe[title="comments-frame"]' ) . waitFor ( { state : 'attached' } ) ;
107108
@@ -161,12 +162,16 @@ test.describe('Comment Permalinks', async () => {
161162 html : '<p>Regular comment</p>'
162163 } ) ;
163164
164- const commentsFrame = await setupPermalinkTest ( page , mockedApi , '#ghost-comments-nonexistent123' ) ;
165+ const commentsFrame = await setupPermalinkTest ( page , mockedApi , '#ghost-comments-dead00000000000000000000' , TALL_BODY_HTML ) ;
165166
166167 // Comments should still load and display normally even with invalid ID
167168 await expect ( commentsFrame . getByText ( 'Regular comment' ) ) . toBeVisible ( ) ;
168169
169- // No errors should be thrown - page should function normally
170+ // A permalink to a non-existent comment should show a notice and scroll to comments
171+ await expect ( commentsFrame . getByTestId ( 'missing-comment-notice' ) ) . toContainText ( 'The linked comment is no longer available.' ) ;
172+ await expect . poll ( ( ) => page . evaluate ( ( ) => window . scrollY ) ) . toBeGreaterThan ( 0 ) ;
173+
174+ // Page should still function normally
170175 const comments = commentsFrame . getByTestId ( 'comment-component' ) ;
171176 await expect ( comments ) . toHaveCount ( 1 ) ;
172177 } ) ;
@@ -180,8 +185,7 @@ test.describe('Comment Permalinks', async () => {
180185 } ) ;
181186
182187 // Include a tall div to push comments below viewport
183- const tallBodyHtml = '<html><head><meta charset="UTF-8" /></head><body><div style="width: 100%; height: 1500px;"></div></body></html>' ;
184- const commentsFrame = await setupPermalinkTest ( page , mockedApi , '#some-other-hash' , tallBodyHtml ) ;
188+ const commentsFrame = await setupPermalinkTest ( page , mockedApi , '#some-other-hash' , TALL_BODY_HTML ) ;
185189
186190 await page . locator ( 'iframe[title="comments-frame"]' ) . waitFor ( { state : 'attached' } ) ;
187191
@@ -190,7 +194,7 @@ test.describe('Comment Permalinks', async () => {
190194 await expect ( commentsFrame . getByTestId ( 'loading' ) ) . toHaveCount ( 1 ) ;
191195 } ) ;
192196
193- test ( 'does not scroll to hidden comment ' , async ( { page} ) => {
197+ test ( 'shows missing-comment notice for hidden permalink and scrolls to comments area ' , async ( { page} ) => {
194198 const mockedApi = new MockedApi ( { } ) ;
195199 mockedApi . setMember ( { } ) ;
196200
@@ -207,22 +211,26 @@ test.describe('Comment Permalinks', async () => {
207211 status : 'hidden'
208212 } ) ;
209213
210- const commentsFrame = await setupPermalinkTest ( page , mockedApi , `#ghost-comments-${ hiddenCommentId } ` ) ;
214+ const commentsFrame = await setupPermalinkTest ( page , mockedApi , `#ghost-comments-${ hiddenCommentId } ` , TALL_BODY_HTML ) ;
211215
212216 // The visible comment should be displayed
213217 await expect ( commentsFrame . getByText ( 'Visible comment' ) ) . toBeVisible ( ) ;
214218
215- // The hidden comment element should not be scrolled to or highlighted
219+ // The hidden comment element should not be rendered
216220 // (hidden comments are not visible to regular members)
217221 const hiddenCommentElement = commentsFrame . locator ( `[id="${ hiddenCommentId } "]` ) ;
218222 await expect ( hiddenCommentElement ) . toHaveCount ( 0 ) ;
219223
220- // Page should function normally with no errors
224+ // A permalink to a non-available comment should show a notice and scroll to comments
225+ await expect ( commentsFrame . getByTestId ( 'missing-comment-notice' ) ) . toContainText ( 'The linked comment is no longer available.' ) ;
226+ await expect . poll ( ( ) => page . evaluate ( ( ) => window . scrollY ) ) . toBeGreaterThan ( 0 ) ;
227+
228+ // Page should still function normally
221229 const comments = commentsFrame . getByTestId ( 'comment-component' ) ;
222230 await expect ( comments ) . toHaveCount ( 1 ) ;
223231 } ) ;
224232
225- test ( 'does not scroll to deleted comment ' , async ( { page} ) => {
233+ test ( 'shows missing-comment notice for deleted permalink and scrolls to comments area ' , async ( { page} ) => {
226234 const mockedApi = new MockedApi ( { } ) ;
227235 mockedApi . setMember ( { } ) ;
228236
@@ -239,16 +247,20 @@ test.describe('Comment Permalinks', async () => {
239247 status : 'deleted'
240248 } ) ;
241249
242- const commentsFrame = await setupPermalinkTest ( page , mockedApi , `#ghost-comments-${ deletedCommentId } ` ) ;
250+ const commentsFrame = await setupPermalinkTest ( page , mockedApi , `#ghost-comments-${ deletedCommentId } ` , TALL_BODY_HTML ) ;
243251
244252 // The visible comment should be displayed
245253 await expect ( commentsFrame . getByText ( 'Visible comment' ) ) . toBeVisible ( ) ;
246254
247- // The deleted comment element should not be scrolled to or highlighted
255+ // The deleted comment element should not be rendered
248256 const deletedCommentElement = commentsFrame . locator ( `[id="${ deletedCommentId } "]` ) ;
249257 await expect ( deletedCommentElement ) . toHaveCount ( 0 ) ;
250258
251- // Page should function normally with no errors
259+ // A permalink to a non-available comment should show a notice and scroll to comments
260+ await expect ( commentsFrame . getByTestId ( 'missing-comment-notice' ) ) . toContainText ( 'The linked comment is no longer available.' ) ;
261+ await expect . poll ( ( ) => page . evaluate ( ( ) => window . scrollY ) ) . toBeGreaterThan ( 0 ) ;
262+
263+ // Page should still function normally
252264 const comments = commentsFrame . getByTestId ( 'comment-component' ) ;
253265 await expect ( comments ) . toHaveCount ( 1 ) ;
254266 } ) ;
0 commit comments