improve: tests (#6321)

* improve: tests

* fixes

* fixes
This commit is contained in:
naman-bruno
2025-12-06 15:36:58 +05:30
committed by GitHub
parent 4a8d787f31
commit e93e545b81
29 changed files with 822 additions and 684 deletions

View File

@@ -1,126 +1,65 @@
import { test, expect } from '../../../playwright';
import path from 'path';
import {
importCollection,
createEnvironment,
addEnvironmentVariables,
saveEnvironment,
closeEnvironmentPanel,
sendRequest,
expectResponseContains,
removeCollection
} from '../../utils/page';
import { buildCommonLocators } from '../../utils/page/locators';
test.describe('Collection Environment Create Tests', () => {
test('should import collection and create environment for request usage', async ({
page,
createTmpDir
}) => {
const openApiFile = path.join(__dirname, 'fixtures', 'bruno-collection.json');
const collectionFile = path.join(__dirname, 'fixtures', 'bruno-collection.json');
const locators = buildCommonLocators(page);
// Import test collection
await page.locator('.plus-icon-button').click();
await page.locator('.tippy-box .dropdown-item').filter({ hasText: 'Import collection' }).click();
await test.step('Import collection', async () => {
await importCollection(page, collectionFile, await createTmpDir('env-test'), {
expectedCollectionName: 'test_collection',
openWithSandboxMode: 'safe'
});
});
const importModal = page.locator('[data-testid="import-collection-modal"]');
await importModal.waitFor({ state: 'visible' });
await test.step('Create environment with variables', async () => {
await createEnvironment(page, 'Test Environment', 'collection');
await page.setInputFiles('input[type="file"]', openApiFile);
await addEnvironmentVariables(page, [
{ name: 'host', value: 'https://echo.usebruno.com' },
{ name: 'userId', value: '1' },
{ name: 'postTitle', value: 'Test Post from Environment' },
{ name: 'postBody', value: 'This is a test post body with environment variables' },
{ name: 'secretApiToken', value: 'super-secret-token-12345', isSecret: true }
]);
const locationModal = page.locator('[data-testid="import-collection-location-modal"]');
await expect(locationModal.locator('.bruno-modal-header-title')).toContainText('Import Collection');
await expect(locationModal.getByText('test_collection')).toBeVisible();
await saveEnvironment(page);
await closeEnvironmentPanel(page);
await expect(locators.environment.currentEnvironment()).toContainText('Test Environment');
});
await page.locator('#collection-location').fill(await createTmpDir('env-test'));
await locationModal.getByRole('button', { name: 'Import' }).click();
await test.step('Test GET request with environment variables', async () => {
await page.locator('.collection-item-name').first().click();
await expect(locators.request.urlLine()).toContainText('{{host}}');
await sendRequest(page, 200);
});
await expect(page.locator('#sidebar-collection-name').filter({ hasText: 'test_collection' })).toBeVisible();
await test.step('Verify response contains environment variables', async () => {
await expectResponseContains(page, [
'"userId": 1',
'"title": "Test Post from Environment"',
'"body": "This is a test post body with environment variables"',
'"apiToken": "super-secret-token-12345"'
]);
});
// Configure collection
await page.locator('#sidebar-collection-name').filter({ hasText: 'test_collection' }).click();
await page.getByLabel('Safe Mode').check();
await page.getByRole('button', { name: 'Save' }).click();
// Create environment
await page.locator('[data-testid="environment-selector-trigger"]').click();
await expect(page.locator('[data-testid="env-tab-collection"]')).toHaveClass(/active/);
// Create new environment
await page.locator('button[id="create-env"]').click();
// Fill environment name
const environmentNameInput = page.locator('input[name="name"]');
await expect(environmentNameInput).toBeVisible();
await environmentNameInput.fill('Test Environment');
await page.getByRole('button', { name: 'Create' }).click();
// Add environment variables
await page.locator('button[data-testid="add-variable"]').click();
await page.locator('input[name="0.name"]').fill('host');
await page
.locator('tr')
.filter({ has: page.locator('input[name="0.name"]') })
.locator('.CodeMirror')
.click();
await page.keyboard.type('https://echo.usebruno.com');
// Add userId
await page.locator('button[data-testid="add-variable"]').click();
await page.locator('input[name="1.name"]').fill('userId');
await page
.locator('tr')
.filter({ has: page.locator('input[name="1.name"]') })
.locator('.CodeMirror')
.click();
await page.keyboard.type('1');
// Add postTitle
await page.locator('button[data-testid="add-variable"]').click();
await page.locator('input[name="2.name"]').fill('postTitle');
await page
.locator('tr')
.filter({ has: page.locator('input[name="2.name"]') })
.locator('.CodeMirror')
.click();
await page.keyboard.type('Test Post from Environment');
// Add postBody
await page.locator('button[data-testid="add-variable"]').click();
await page.locator('input[name="3.name"]').fill('postBody');
await page
.locator('tr')
.filter({ has: page.locator('input[name="3.name"]') })
.locator('.CodeMirror')
.click();
await page.keyboard.type('This is a test post body with environment variables');
// Add secret token
await page.locator('button[data-testid="add-variable"]').click();
await page.locator('input[name="4.name"]').fill('secretApiToken');
await page
.locator('tr')
.filter({ has: page.locator('input[name="4.name"]') })
.locator('.CodeMirror')
.click();
await page.keyboard.type('super-secret-token-12345');
await page.locator('input[name="4.secret"]').check();
// Save environment
await page.getByRole('button', { name: 'Save' }).click();
await page.getByText('×').click();
await expect(page.locator('.current-environment')).toContainText('Test Environment');
// Test GET request with environment variables
await page.locator('.collection-item-name').first().click();
await expect(page.locator('#request-url .CodeMirror-line')).toContainText('{{host}}');
await page.locator('[data-testid="send-arrow-icon"]').click();
await page.locator('[data-testid="response-status-code"]').waitFor({ state: 'visible' });
await expect(page.locator('[data-testid="response-status-code"]')).toContainText('200');
// Verify the JSON response contains the environment variables
const responsePane = page.locator('.response-pane');
await expect(responsePane).toContainText('"userId": 1');
await expect(responsePane).toContainText('"title": "Test Post from Environment"');
await expect(responsePane).toContainText('"body": "This is a test post body with environment variables"');
await expect(responsePane).toContainText('"apiToken": "super-secret-token-12345"');
// Cleanup - use new "Remove" action in workspace UI
const collectionRow = page.locator('.collection-name').filter({ has: page.locator('#sidebar-collection-name:has-text("test_collection")') });
await collectionRow.hover();
await collectionRow.locator('.collection-actions .icon').click();
await page.locator('.dropdown-item').filter({ hasText: 'Remove' }).click();
const closeModal = page.getByRole('dialog').filter({ has: page.getByText('Remove Collection') });
await closeModal.getByRole('button', { name: 'Remove' }).click();
await test.step('Cleanup', async () => {
await removeCollection(page, 'test_collection');
});
});
});

View File

@@ -1,125 +1,67 @@
import { test, expect } from '../../../playwright';
import path from 'path';
import { closeAllCollections } from '../../utils/page';
import {
importCollection,
createEnvironment,
addEnvironmentVariables,
saveEnvironment,
closeEnvironmentPanel,
sendRequest,
expectResponseContains,
closeAllCollections
} from '../../utils/page';
import { buildCommonLocators } from '../../utils/page/locators';
test.describe('Global Environment Create Tests', () => {
test.setTimeout(60000);
test('should import collection and create global environment for request usage', async ({
page,
createTmpDir
}) => {
const openApiFile = path.join(__dirname, 'fixtures', 'bruno-collection.json');
const collectionFile = path.join(__dirname, 'fixtures', 'bruno-collection.json');
const locators = buildCommonLocators(page);
// Import test collection
await page.locator('.plus-icon-button').click();
await page.locator('.tippy-box .dropdown-item').filter({ hasText: 'Import collection' }).click();
await test.step('Import collection', async () => {
await importCollection(page, collectionFile, await createTmpDir('global-env-test'), {
expectedCollectionName: 'test_collection',
openWithSandboxMode: 'safe'
});
});
const importModal = page.locator('[data-testid="import-collection-modal"]');
await importModal.waitFor({ state: 'visible' });
await test.step('Create global environment with variables', async () => {
await createEnvironment(page, 'Test Global Environment', 'global');
await page.setInputFiles('input[type="file"]', openApiFile);
await addEnvironmentVariables(page, [
{ name: 'host', value: 'https://echo.usebruno.com' },
{ name: 'userId', value: '1' },
{ name: 'postTitle', value: 'Global Test Post from Environment' },
{ name: 'postBody', value: 'This is a global test post body with environment variables' },
{ name: 'secretApiToken', value: 'global-secret-token-12345', isSecret: true }
]);
// Wait for location modal to appear after file processing
const locationModal = page.locator('[data-testid="import-collection-location-modal"]');
await locationModal.waitFor({ state: 'visible', timeout: 10000 });
await expect(locationModal.locator('.bruno-modal-header-title')).toContainText('Import Collection');
await expect(locationModal.getByText('test_collection')).toBeVisible();
await saveEnvironment(page);
await closeEnvironmentPanel(page);
await expect(locators.environment.currentEnvironment()).toContainText('Test Global Environment');
});
await page.locator('#collection-location').fill(await createTmpDir('global-env-test'));
await locationModal.getByRole('button', { name: 'Import' }).click();
await test.step('Test GET request with environment variables', async () => {
await page.locator('.collection-item-name').first().click();
await expect(locators.request.urlLine()).toContainText('{{host}}');
await sendRequest(page, 200);
});
await expect(page.locator('#sidebar-collection-name').filter({ hasText: 'test_collection' })).toBeVisible();
await test.step('Verify response contains environment variables', async () => {
await expectResponseContains(page, [
'"userId": 1',
'"title": "Global Test Post from Environment"',
'"body": "This is a global test post body with environment variables"',
'"apiToken": "global-secret-token-12345"'
]);
});
// Configure collection
await page.locator('#sidebar-collection-name').filter({ hasText: 'test_collection' }).click();
await page.getByLabel('Safe Mode').check();
await page.getByRole('button', { name: 'Save' }).click();
// Create global environment
await page.locator('[data-testid="environment-selector-trigger"]').click();
await page.locator('[data-testid="env-tab-global"]').click();
await expect(page.locator('[data-testid="env-tab-global"]')).toHaveClass(/active/);
// Create new global environment
await page.locator('button[id="create-env"]').click();
// Fill environment name
const environmentNameInput = page.locator('input[name="name"]');
await expect(environmentNameInput).toBeVisible();
await environmentNameInput.fill('Test Global Environment');
await page.getByRole('button', { name: 'Create' }).click();
// Add environment variables
await page.locator('button[data-testid="add-variable"]').click();
await page.locator('input[name="0.name"]').fill('host');
await page
.locator('tr')
.filter({ has: page.locator('input[name="0.name"]') })
.locator('.CodeMirror')
.click();
await page.keyboard.type('https://echo.usebruno.com');
// Add userId
await page.locator('button[data-testid="add-variable"]').click();
await page.locator('input[name="1.name"]').fill('userId');
await page
.locator('tr')
.filter({ has: page.locator('input[name="1.name"]') })
.locator('.CodeMirror')
.click();
await page.keyboard.type('1');
// Add postTitle
await page.locator('button[data-testid="add-variable"]').click();
await page.locator('input[name="2.name"]').fill('postTitle');
await page
.locator('tr')
.filter({ has: page.locator('input[name="2.name"]') })
.locator('.CodeMirror')
.click();
await page.keyboard.type('Global Test Post from Environment');
// Add postBody
await page.locator('button[data-testid="add-variable"]').click();
await page.locator('input[name="3.name"]').fill('postBody');
await page
.locator('tr')
.filter({ has: page.locator('input[name="3.name"]') })
.locator('.CodeMirror')
.click();
await page.keyboard.type('This is a global test post body with environment variables');
// Add secret token
await page.locator('button[data-testid="add-variable"]').click();
await page.locator('input[name="4.name"]').fill('secretApiToken');
await page
.locator('tr')
.filter({ has: page.locator('input[name="4.name"]') })
.locator('.CodeMirror')
.click();
await page.keyboard.type('global-secret-token-12345');
await page.locator('input[name="4.secret"]').check();
await expect(page.locator('input[name="4.secret"]')).toBeChecked();
// Save environment
await page.getByRole('button', { name: 'Save' }).click();
await page.getByText('×').click();
await expect(page.locator('.current-environment')).toContainText('Test Global Environment');
// Test GET request with environment variables
await page.locator('.collection-item-name').first().click();
await expect(page.locator('#request-url .CodeMirror-line')).toContainText('{{host}}');
await page.locator('[data-testid="send-arrow-icon"]').click();
await page.locator('[data-testid="response-status-code"]').waitFor({ state: 'visible' });
await expect(page.locator('[data-testid="response-status-code"]')).toContainText('200');
// Verify the JSON response contains the environment variables
const responsePane = page.locator('.response-pane');
await expect(responsePane).toContainText('"userId": 1');
await expect(responsePane).toContainText('"title": "Global Test Post from Environment"');
await expect(responsePane).toContainText('"body": "This is a global test post body with environment variables"');
await expect(responsePane).toContainText('"apiToken": "global-secret-token-12345"');
// cleanup: close all collections
await closeAllCollections(page);
await test.step('Cleanup', async () => {
await closeAllCollections(page);
});
});
});