|
| 1 | +import type { ProtectConfigJSON } from '@clerk/shared/types'; |
| 2 | +import type { Page } from '@playwright/test'; |
| 3 | +import { expect, test } from '@playwright/test'; |
| 4 | + |
| 5 | +import { appConfigs } from '../presets'; |
| 6 | +import { createTestUtils, testAgainstRunningApps } from '../testUtils'; |
| 7 | + |
| 8 | +const mockProtectSettings = async (page: Page, config: ProtectConfigJSON) => { |
| 9 | + await page.route('*/**/v1/environment*', async route => { |
| 10 | + const response = await route.fetch(); |
| 11 | + const json = await response.json(); |
| 12 | + const newJson = { |
| 13 | + ...json, |
| 14 | + protect_config: config, |
| 15 | + }; |
| 16 | + await route.fulfill({ response, json: newJson }); |
| 17 | + }); |
| 18 | +}; |
| 19 | + |
| 20 | +testAgainstRunningApps({ withEnv: [appConfigs.envs.withEmailCodes] })('Hello World Div @xgeneric', ({ app }) => { |
| 21 | + test.describe.configure({ mode: 'parallel' }); |
| 22 | + |
| 23 | + test.afterAll(async () => { |
| 24 | + await app.teardown(); |
| 25 | + }); |
| 26 | + |
| 27 | + test('should create script when protect_config.loader is set', async ({ page, context }) => { |
| 28 | + const u = createTestUtils({ app, page, context }); |
| 29 | + await mockProtectSettings(page, { |
| 30 | + object: 'protect_config', |
| 31 | + id: 'n', |
| 32 | + loader: { |
| 33 | + type: 'script', |
| 34 | + target: 'body', |
| 35 | + attributes: { id: 'test-protect-loader', type: 'module', src: 'data:application/json;base64,Cgo=' }, |
| 36 | + }, |
| 37 | + }); |
| 38 | + await u.page.goToAppHome(); |
| 39 | + await u.page.waitForClerkJsLoaded(); |
| 40 | + await expect(page.locator('#test-protect-loader')).toHaveAttribute('type', 'module'); |
| 41 | + }); |
| 42 | + |
| 43 | + test('should not create Hello World div when protect_config.loader is not set', async ({ page, context }) => { |
| 44 | + const u = createTestUtils({ app, page, context }); |
| 45 | + await mockProtectSettings(page, undefined); |
| 46 | + await u.page.goToAppHome(); |
| 47 | + await u.page.waitForClerkJsLoaded(); |
| 48 | + expect(page.locator('#test-protect-loader')).toBeUndefined(); |
| 49 | + }); |
| 50 | +}); |
0 commit comments