feat(sandbox): create a dropdown selector for sandbox mode (#6519)

This commit is contained in:
Bijin A B
2025-12-30 23:03:06 +05:30
committed by GitHub
parent 0848393319
commit 8fa8ae5fed
12 changed files with 278 additions and 190 deletions

View File

@@ -1,39 +1,28 @@
import { test, expect } from '../../../playwright';
import { createCollection, openCollection } from '../../utils/page/actions';
import { buildSandboxLocators } from '../../utils/page/locators';
test.describe('Default JavaScript Sandbox Mode', () => {
test('should set jsSandboxMode to safe by default when creating a new collection', async ({ page, createTmpDir }) => {
const collectionName = 'test-sandbox-collection';
await createCollection(page, collectionName, await createTmpDir());
const sandboxLocators = buildSandboxLocators(page);
// Verify sandbox mode is set to safe by default
const sandboxModeSelector = page.getByTestId('sandbox-mode-selector');
await expect(sandboxModeSelector).toBeVisible();
await expect(sandboxModeSelector).toHaveAttribute('title', 'Safe Mode');
await expect(sandboxLocators.sandboxModeSelector()).toBeVisible();
// Click on sandbox mode selector to open security settings
await sandboxModeSelector.click();
await sandboxLocators.sandboxModeSelector().click();
// Change to developer mode
const developerRadio = page.locator('input[id="developer"]');
await developerRadio.click();
const developerRadio = sandboxLocators.developerModeRadio();
await developerRadio.check();
// Save
const saveButton = page.getByRole('button', { name: 'Save' });
await saveButton.click();
// For developer mode, check if safe mode is currently selected
const safeModeChecked = await sandboxLocators.safeModeRadio().isChecked().catch(() => false);
await expect(safeModeChecked).toBe(false);
// Verify mode changed to developer
await expect(sandboxModeSelector).toHaveAttribute('title', 'Developer Mode');
// Close all tabs
const modifier = process.platform === 'darwin' ? 'Meta' : 'Control';
await page.keyboard.press(`${modifier}+Shift+W`);
// Reopen the collection
await openCollection(page, collectionName);
// Verify mode is still developer (persisted)
await expect(sandboxModeSelector).toHaveAttribute('title', 'Developer Mode');
await page.keyboard.press('Escape');
});
});