Files
bruno/tests/request/encoding/curl-encoding.spec.ts
Sid 6e8cd55b76 Refactor: Change how test runner handles pageWithUserData tests (#5922)
* refactor: change how test runner opens pageWithUserData instances

* fix: test move tabs

* fix: custom ca cert tests

* fix: update file patterns and improve error messages

* fix: improve electron app launch logic

* fix: update temporary directory handling for Electron app

* fix: ensure newline at end of file in index.ts

This change adds a newline at the end of the file to comply with coding standards.

* fix: improve error handling in recursiveCopy function

- Simplified error message when source path does not exist.
- Enhanced error handling to provide clearer guidance on usage of `page` fixture.

* fix(e2e): close collections after each tests

* fix: reuse the worker instance per file instead of per user data dir

* fix: revert ssl tests as serial run is fixed

* fix: change afterEach to afterAll for cleanup

fix: change afterEach to afterAll for cleanup

---------

Co-authored-by: Bijin Bruno <bijin@usebruno.com>
2025-10-29 14:32:45 +05:30

101 lines
4.5 KiB
TypeScript

import { test, expect } from '../../../playwright';
import { closeAllCollections } from '../../utils/page';
test.describe('Code Generation URL Encoding', () => {
test.afterEach(async ({ page }) => {
try {
const modalCloseButton = page.locator('[data-test-id="modal-close-button"]');
if (await modalCloseButton.isVisible()) {
await modalCloseButton.click();
await modalCloseButton.waitFor({ state: 'hidden' });
}
} catch (e) {}
await closeAllCollections(page);
});
test('Should generate code with proper URL encoding for unencoded input', async ({
page,
createTmpDir
}) => {
await page.locator('.dropdown-icon').click();
await page.locator('.dropdown-item').filter({ hasText: 'Create Collection' }).click();
await page.getByLabel('Name').fill('unencoded-test-collection');
await page.getByLabel('Location').fill(await createTmpDir('unencoded-test-collection'));
await page.getByRole('button', { name: 'Create', exact: true }).click();
await expect(page.locator('#sidebar-collection-name').filter({ hasText: 'unencoded-test-collection' })).toBeVisible();
await page.locator('#sidebar-collection-name').filter({ hasText: 'unencoded-test-collection' }).click();
await page.getByLabel('Safe Mode').check();
await page.getByRole('button', { name: 'Save' }).click();
await page.locator('#create-new-tab').getByRole('img').click();
await page.getByPlaceholder('Request Name').fill('unencoded-request');
await page.locator('#new-request-url .CodeMirror').click();
await page.locator('textarea').fill('http://base.source?name=John Doe');
await page.getByRole('button', { name: 'Create' }).click();
await expect(page.locator('.collection-item-name').filter({ hasText: 'unencoded-request' })).toBeVisible();
await page.locator('.collection-item-name').filter({ hasText: 'unencoded-request' }).click();
await page.locator('#send-request .infotip').first().click();
await expect(page.getByRole('dialog')).toBeVisible();
await expect(page.getByRole('dialog').locator('.bruno-modal-header-title')).toContainText('Generate Code');
const codeEditor = page.locator('.editor-content .CodeMirror').first();
await expect(codeEditor).toBeVisible();
const generatedCode = await codeEditor.textContent();
expect(generatedCode).toContain('http://base.source/?name=John%20Doe');
await page.locator('[data-test-id="modal-close-button"]').click();
await page.locator('[data-test-id="modal-close-button"]').waitFor({ state: 'hidden' });
});
test('Should generate code with proper URL encoding for encoded input', async ({
page,
createTmpDir
}) => {
await page.locator('.dropdown-icon').click();
await page.locator('.dropdown-item').filter({ hasText: 'Create Collection' }).click();
await page.getByLabel('Name').fill('encoded-test-collection');
await page.getByLabel('Location').fill(await createTmpDir('encoded-test-collection'));
await page.getByRole('button', { name: 'Create', exact: true }).click();
await expect(page.locator('#sidebar-collection-name').filter({ hasText: 'encoded-test-collection' })).toBeVisible();
await page.locator('#sidebar-collection-name').filter({ hasText: 'encoded-test-collection' }).click();
await page.getByLabel('Safe Mode').check();
await page.getByRole('button', { name: 'Save' }).click();
await page.locator('#create-new-tab').getByRole('img').click();
await page.getByPlaceholder('Request Name').fill('encoded-request');
await page.locator('#new-request-url .CodeMirror').click();
await page.locator('textarea').fill('http://base.source?name=John%20Doe');
await page.getByRole('button', { name: 'Create' }).click();
await expect(page.locator('.collection-item-name').filter({ hasText: 'encoded-request' })).toBeVisible();
await page.locator('.collection-item-name').filter({ hasText: 'encoded-request' }).click();
await page.locator('#send-request .infotip').first().click();
await expect(page.getByRole('dialog')).toBeVisible();
await expect(page.getByRole('dialog').locator('.bruno-modal-header-title')).toContainText('Generate Code');
const codeEditor = page.locator('.editor-content .CodeMirror').first();
await expect(codeEditor).toBeVisible();
const generatedCode = await codeEditor.textContent();
expect(generatedCode).toContain('http://base.source/?name=John%20Doe');
await page.locator('[data-test-id="modal-close-button"]').click();
await page.locator('[data-test-id="modal-close-button"]').waitFor({ state: 'hidden' });
});
});