Skip to content

Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.

test(content): pin where the agent's product grid goes when the most-linked section isn't the last (#1653)

Cihan35209c96d47a
diff --git a/server/src/lib/shopping-blocks.test.js b/server/src/lib/shopping-blocks.test.js
index 3d1a86218..377f403cc 100644
--- a/server/src/lib/shopping-blocks.test.js
+++ b/server/src/lib/shopping-blocks.test.js
@@ -103,6 +103,25 @@ describe('insertProductGrid', () => {
expect(decoded(out)[0]).toContain('https://shop.example/products/p2');
});
+ it('picks the section that links them most wherever it is, not the first or the last that links one', () => {
+ // One link before it, one after, and the FAQ last: only the count decides.
+ const html =
+ `<h1>T</h1><h2>Brands</h2><p>${link('p1')}</p>` +
+ `<h2>Picks</h2><p>${link('p1')} ${link('p2')}</p><p>Why.</p>` +
+ `<h2>Compare</h2><p>${link('p2')}</p>` +
+ '<h2>Care</h2><p>c</p><h2>FAQ</h2><p>q</p>';
+ expect(insertProductGrid(html, path)).toMatch(
+ /<p>Why\.<\/p><div data-html-block="[^"]+"><\/div><h2>Compare<\/h2>/,
+ );
+ // Two sections link them as often: the first of them.
+ const tie =
+ `<h1>T</h1><h2>Intro</h2><p>i</p><h2>Picks</h2><p>${link('p1')} ${link('p2')}</p>` +
+ `<h2>More</h2><p>${link('p2')} ${link('p1')}</p><h2>FAQ</h2><p>q</p>`;
+ expect(insertProductGrid(tie, path)).toMatch(
+ /p2">x<\/a><\/p><div data-html-block="[^"]+"><\/div><h2>More<\/h2>/,
+ );
+ });
+
it("counts only links to the grid's products, not to other pages", () => {
const html =
'<h1>T</h1><h2>Brands</h2>' +