Files
bruno/tests/request/newlines/newlines-persistence.spec.ts
Pooja 5e6444b8b5 feat: Set JavaScript sandbox to safe mode by default for new collections (#4824)
* feat: Set JavaScript sandbox to safe mode by default for new collections

* rm: sandbox code in playwright test

* rm: safe mode code in var interpolation test

* rm: sandbox modal code

* fix

* fix

* fix

* fix

* improve

* improvement

* fix

* fix
2025-12-18 17:27:38 +05:30

79 lines
4.0 KiB
TypeScript

import { test, expect } from '../../../playwright';
import { openCollection } from '../../utils/page';
import { getTableCell } from '../../utils/page/locators';
test('should persist request with newlines across app restarts', async ({ createTmpDir, launchElectronApp }) => {
const userDataPath = await createTmpDir('newlines-persistence-userdata');
const collectionPath = await createTmpDir('newlines-persistence-collection');
// Create collection and request
const app1 = await launchElectronApp({ userDataPath });
const page = await app1.firstWindow();
await page.getByTestId('collections-header-add-menu').click();
await page.locator('.tippy-box .dropdown-item').filter({ hasText: 'Create collection' }).click();
await page.locator('.bruno-modal').getByLabel('Name').fill('newlines-persistence');
await page.locator('.bruno-modal').getByLabel('Location').fill(collectionPath);
await page.locator('.bruno-modal').getByRole('button', { name: 'Create' }).click();
const collection = page.getByTestId('collections').locator('.collection-name').filter({ hasText: 'newlines-persistence' });
await collection.hover();
await collection.locator('.collection-actions .icon').click();
await page.locator('.dropdown-item').filter({ hasText: 'New Request' }).click();
await page.getByPlaceholder('Request Name').fill('persistence-test');
await page.locator('#new-request-url').locator('.CodeMirror').click();
await page.locator('#new-request-url').locator('textarea').fill('https://httpbin.org/get');
await page.locator('.bruno-modal').getByRole('button', { name: 'Create', exact: true }).click();
await openCollection(page, 'newlines-persistence');
await page.locator('.collection-item-name').filter({ hasText: 'persistence-test' }).dblclick();
await page.getByRole('tab', { name: 'Params' }).click();
const paramRow = page.locator('table tbody tr').first();
await getTableCell(paramRow, 0).getByRole('textbox').fill('queryParamKey');
await page.getByRole('tab', { name: 'Headers' }).click();
const headerRow = page.locator('table tbody tr').first();
await getTableCell(headerRow, 0).locator('.CodeMirror').click();
await getTableCell(headerRow, 0).locator('textarea').fill('headerKey');
await getTableCell(headerRow, 1).locator('.CodeMirror').click();
await getTableCell(headerRow, 1).locator('textarea').fill('header\nValue');
await page.getByRole('tab', { name: 'Vars' }).click();
const preReqRow = page.locator('table').first().locator('tbody tr').first();
await getTableCell(preReqRow, 0).getByRole('textbox').fill('preRequestVar');
await getTableCell(preReqRow, 1).locator('.CodeMirror').click();
await getTableCell(preReqRow, 1).locator('textarea').fill('pre\nRequest\nValue');
const postResRow = page.locator('table').nth(1).locator('tbody tr').first();
await getTableCell(postResRow, 0).getByRole('textbox').fill('postResponseVar');
await getTableCell(postResRow, 1).locator('.CodeMirror').click();
await getTableCell(postResRow, 1).locator('textarea').fill('post\nResponse\nValue');
await page.keyboard.press('Meta+s');
await app1.close();
// Verify persistence after restart
const app2 = await launchElectronApp({ userDataPath });
const page2 = await app2.firstWindow();
await page2.getByTestId('collections').locator('.collection-name').filter({ hasText: 'newlines-persistence' }).click();
await page2.locator('.collection-item-name').filter({ hasText: 'persistence-test' }).dblclick();
// Verify params persisted
await page2.getByRole('tab', { name: 'Params' }).click();
await expect(page2.locator('table tbody tr')).toHaveCount(2);
// Verify headers persisted
await page2.getByRole('tab', { name: 'Headers' }).click();
await expect(page2.locator('table tbody tr')).toHaveCount(2);
// Verify vars persisted
await page2.getByRole('tab', { name: 'Vars' }).click();
await expect(page2.locator('table').first().locator('tbody tr')).toHaveCount(2);
await expect(page2.locator('table').nth(1).locator('tbody tr')).toHaveCount(2);
await app2.close();
});