diff --git a/e2e/environment.spec.ts b/e2e/environment.spec.ts index 6d1d825..5b36a80 100644 --- a/e2e/environment.spec.ts +++ b/e2e/environment.spec.ts @@ -156,4 +156,58 @@ test.describe('Environment Management', () => { const pageContent = await page.content(); expect(pageContent).toContain('!!! custom'); }); + + test('should not duplicate params when placeholder already exists in template', async ({ page }) => { + await page.goto('/'); + await page.click('button:has-text("Create new")'); + + // Step 1: Add a param to DEFAULT + const nameInput = page.locator('input[placeholder="name"]').first(); + const valueInput = page.locator('input[placeholder="value"]').first(); + const addButton = page.locator('button.btn-success').first(); + + await nameInput.fill('host'); + await valueInput.fill('localhost:8080'); + await addButton.click(); + await page.waitForTimeout(500); + + // Step 2: Switch to Content Template tab + await page.click('a:has-text("Content Template")'); + await page.waitForTimeout(500); + + // Step 3: Click Edit and manually add @host@ usage in a custom field + await page.click('button:has-text("Edit")'); + await page.waitForTimeout(300); + + const textarea = page.locator('textarea'); + // Add a custom field that uses @host@ placeholder + await textarea.fill('{\n "!!! host": "@host@",\n "apiUrl": "http://@host@/api"\n}'); + await page.waitForTimeout(300); + + // Step 4: Save + await page.click('button:has-text("Save")'); + await page.waitForTimeout(500); + + // Step 5: Add ANOTHER param with same name (host) - should not create duplicate + await page.click('a:has-text("Env")'); + await page.waitForTimeout(300); + + await nameInput.fill('host'); + await valueInput.fill('updated-host:9090'); + await addButton.click(); + await page.waitForTimeout(500); + + // Step 6: Switch back to Content Template and verify no duplicate + await page.click('a:has-text("Content Template")'); + await page.waitForTimeout(500); + + // Count occurrences of "!!! host" - should be exactly 1 + const templateContent = await page.locator('.config-template-editor').textContent(); + const hostKeyCount = (templateContent.match(/!!! host/g) || []).length; + expect(hostKeyCount).toBe(1); + + // The @host@ placeholder should appear twice (once in !!! host, once in apiUrl) + const hostPlaceholderCount = (templateContent.match(/@host@/g) || []).length; + expect(hostPlaceholderCount).toBe(2); + }); });