|
1 | | -import { DUB_ANALYTICS_SCRIPT_URL } from '@/app/constants'; |
2 | 1 | import { test, expect } from '@playwright/test'; |
3 | 2 |
|
4 | 3 | declare global { |
@@ -27,6 +26,11 @@ test.describe('Outbound domains tracking', () => { |
27 | 26 | expect(exampleHref).toContain('dub_id=test-click-id'); |
28 | 27 | expect(otherHref).toContain('dub_id=test-click-id'); |
29 | 28 | expect(unrelatedHref).not.toContain('dub_id=test-click-id'); |
| 29 | + |
| 30 | + // Also verify wildcard domain functionality |
| 31 | + const wildcardLink = await page.$('a[href*="api.wildcard.com"]'); |
| 32 | + const wildcardHref = await wildcardLink?.getAttribute('href'); |
| 33 | + expect(wildcardHref).toContain('dub_id=test-click-id'); |
30 | 34 | }); |
31 | 35 |
|
32 | 36 | test('should handle iframe src attributes', async ({ page }) => { |
@@ -149,4 +153,59 @@ test.describe('Outbound domains tracking', () => { |
149 | 153 | const iframeSrc = await iframe?.getAttribute('src'); |
150 | 154 | expect(iframeSrc).toContain('dub_id=test-click-id'); |
151 | 155 | }); |
| 156 | + |
| 157 | + test('should handle wildcard domains correctly', async ({ page }) => { |
| 158 | + await page.goto('/outbound?dub_id=test-click-id'); |
| 159 | + await page.waitForFunction(() => window._dubAnalytics !== undefined); |
| 160 | + |
| 161 | + await page.waitForTimeout(1000); |
| 162 | + |
| 163 | + // Test wildcard domain matching - *.wildcard.com should match all subdomains |
| 164 | + const wildcardLink = await page.$('a[href*="api.wildcard.com"]'); |
| 165 | + const wildcardSubdomainLink = await page.$('a[href*="admin.wildcard.com"]'); |
| 166 | + const wildcardNestedLink = await page.$( |
| 167 | + 'a[href*="deep.nested.wildcard.com"]', |
| 168 | + ); |
| 169 | + const wildcardRootLink = await page.$('a[href*="wildcard.com"]'); |
| 170 | + |
| 171 | + // Test non-wildcard domain that shouldn't match wildcard pattern |
| 172 | + const nonWildcardLink = await page.$('a[href*="notwildcard.com"]'); |
| 173 | + |
| 174 | + const wildcardHref = await wildcardLink?.getAttribute('href'); |
| 175 | + const wildcardSubdomainHref = |
| 176 | + await wildcardSubdomainLink?.getAttribute('href'); |
| 177 | + const wildcardNestedHref = await wildcardNestedLink?.getAttribute('href'); |
| 178 | + const wildcardRootHref = await wildcardRootLink?.getAttribute('href'); |
| 179 | + const nonWildcardHref = await nonWildcardLink?.getAttribute('href'); |
| 180 | + |
| 181 | + // All wildcard.com subdomains should have tracking |
| 182 | + expect(wildcardHref).toContain('dub_id=test-click-id'); |
| 183 | + expect(wildcardSubdomainHref).toContain('dub_id=test-click-id'); |
| 184 | + expect(wildcardNestedHref).toContain('dub_id=test-click-id'); |
| 185 | + expect(wildcardRootHref).toContain('dub_id=test-click-id'); |
| 186 | + |
| 187 | + // Non-wildcard domain should not have tracking |
| 188 | + expect(nonWildcardHref).not.toContain('dub_id=test-click-id'); |
| 189 | + }); |
| 190 | + |
| 191 | + test('should handle wildcard with www prefix correctly', async ({ page }) => { |
| 192 | + await page.goto('/outbound?dub_id=test-click-id'); |
| 193 | + await page.waitForFunction(() => window._dubAnalytics !== undefined); |
| 194 | + |
| 195 | + await page.waitForTimeout(1000); |
| 196 | + |
| 197 | + // Test wildcard domain with www prefix |
| 198 | + const wwwWildcardLink = await page.$('a[href*="www.api.wildcard.com"]'); |
| 199 | + const wwwWildcardSubdomainLink = await page.$( |
| 200 | + 'a[href*="www.admin.wildcard.com"]', |
| 201 | + ); |
| 202 | + |
| 203 | + const wwwWildcardHref = await wwwWildcardLink?.getAttribute('href'); |
| 204 | + const wwwWildcardSubdomainHref = |
| 205 | + await wwwWildcardSubdomainLink?.getAttribute('href'); |
| 206 | + |
| 207 | + // www. prefix should be ignored, so these should still match wildcard pattern |
| 208 | + expect(wwwWildcardHref).toContain('dub_id=test-click-id'); |
| 209 | + expect(wwwWildcardSubdomainHref).toContain('dub_id=test-click-id'); |
| 210 | + }); |
152 | 211 | }); |
0 commit comments