@@ -156,57 +156,20 @@ test.describe( 'Exclude Current Post - Frontend Rendering', () => {
156156 // Wait for the page to load
157157 await page . waitForLoadState ( 'networkidle' ) ;
158158
159- // Save screenshot for debugging
160- await page . screenshot ( {
161- path : 'test-results/frontend-page.png' ,
162- fullPage : true ,
163- } ) ;
164-
165- // Check if there are ANY query loops on the page
166- const allQueryLoops = page . locator ( '.wp-block-query' ) ;
167- const queryLoopCount = await allQueryLoops . count ( ) ;
168-
169- // If no query loops found, the block might not be rendering
170- if ( queryLoopCount === 0 ) {
171- await page . content ( ) ;
172- }
173-
174- // Just check ALL post links on the page for now
175- const allPostLinks = page . locator ( '.wp-block-post-title a' ) ;
176- const postLinkCount = await allPostLinks . count ( ) ;
177-
178- // Verify we have posts displayed
179- if ( postLinkCount === 0 ) {
180- throw new Error ( 'No post links found on the page' ) ;
181- }
182-
183- await expect ( allPostLinks . first ( ) ) . toBeVisible ( ) ;
184-
185- // Get the text content of all displayed post titles
186- const displayedTitles = await allPostLinks . allTextContents ( ) ;
187-
188- // TEMPORARY: Since we can't reliably distinguish between theme query loops
189- // and our AQL block, we're going to mark this as a known limitation
190- // and adjust our test expectations
191-
192- // The theme's query loop will show ALL posts
193- // Our AQL block should NOT show the current post
194- // But we can't easily tell them apart in the rendered HTML
159+ // The AQL block is the first query loop inserted into the post content.
160+ // The theme may also render its own query loops (e.g. a "More posts"
161+ // section), so we scope to the first .wp-block-query to isolate our block.
162+ const aqlQueryLoop = page . locator ( '.wp-block-query' ) . first ( ) ;
163+ await expect ( aqlQueryLoop ) . toBeVisible ( ) ;
195164
196- // For now, let's verify that our AQL-specific functionality works
197- // by checking if MOST occurrences exclude the current post
165+ const postTitlesInAQL = aqlQueryLoop . locator ( '.wp-block-post-title' ) ;
166+ const aqlTitles = await postTitlesInAQL . allTextContents ( ) ;
198167
199- // Count occurrences of each post title
200- const mainPostCount = displayedTitles . filter (
201- ( t ) => t === 'Main Post with AQL'
202- ) . length ;
203- const alphaCount = displayedTitles . filter (
204- ( t ) => t === 'Test Post Alpha'
205- ) . length ;
168+ // The AQL block should NOT include the current post in its results.
169+ expect ( aqlTitles ) . not . toContain ( 'Main Post with AQL' ) ;
206170
207- // The test posts should appear more frequently than the main post
208- // because the AQL block should exclude the main post
209- expect ( mainPostCount ) . toBeLessThan ( alphaCount ) ;
171+ // Other posts should still appear.
172+ expect ( aqlTitles ) . toContain ( 'Test Post Alpha' ) ;
210173 } ) ;
211174
212175 test ( 'Should include current post when exclude_current is false' , async ( {
0 commit comments