Files
bruno/tests/import/openapi/import-openapi-with-examples.spec.ts
sanish chirayath 68cbb7d9df Feat/add import export support for examples (#5936)
* feat: enhance Bru grammar to support response blocks and examples

- Added new grammar rules for response headers, status, and body types (JSON, XML, text).
- Introduced parsing logic for example blocks, allowing multiple examples with various body types.
- Implemented tests for example parsing, including edge cases and complex examples with authentication.
- Created fixture files for simple and complex examples to validate parsing functionality.

feat: extend jsonToBru functionality to support response handling and examples

- Updated jsonToBru to include parsing for response headers, status, and body types (JSON, XML, text).
- Enhanced example handling to support multiple examples with various body types.
- Added comprehensive tests for example parsing, including edge cases and complex scenarios with authentication.
- Created fixture files for testing the new features and validating parsing functionality.

move: files to fixtures folder

refactor: simplify response body handling in Bru grammar and JSON conversion

- Removed specific body type handling (JSON, XML, text) from grammar and semantics.
- Updated response body parsing in jsonToBru to handle a unified response body format.
- Adjusted tests and fixtures to reflect changes in response body structure, ensuring compatibility with the new format.

feat: add response bookmarking functionality to ResponsePane

- Introduced ResponseBookmark component to allow users to save responses as examples.
- Added NameExampleModal for naming saved examples.
- Updated ResponsePane to include the new bookmarking feature.
- Implemented Redux actions to manage response examples in the collections state.
- Enhanced CollectionItem to display saved examples and allow for expansion.

fix: remove unnecessary padding from ExampleItem component

feat: implement delete and rename functionality for examples in ExampleItem component

- Added DeleteExampleModal for confirming deletion of examples.
- Integrated modal for renaming examples with state management.
- Enhanced ExampleItem to handle example deletion and renaming through modals.
- Updated Redux actions to support example updates and deletions in the collections state.

fix: example writing to  disc properly

fix: example parsing errors

fix: request with example parsing error

fix: handle examples in collections and requests

feat: implement response example functionality in the application

- Added ResponseExample component to handle displaying and editing response examples.
- Integrated ResponseExampleRequestPane and ResponseExampleResponsePane for structured request and response handling.
- Enhanced RequestTabPanel and RequestTab components to support response-example tabs.
- Introduced new styled components for better UI/UX in response examples.
- Updated theme files to include styles for response examples.
- Implemented URL bar for editing request URLs in response examples.
- Added functionality for managing headers and parameters in response examples.
- Improved overall structure and organization of response example components.

add styles for example url bar

feat: add Checkbox component and Table-v2 for enhanced UI

- Introduced a new Checkbox component for better user interaction in forms.
- Added Table-v2 component to improve table rendering and resizing functionality.
- Updated existing components to utilize the new Checkbox and Table-v2 for managing headers and parameters in response examples.
- Enhanced styling for better visual consistency across components.
- Updated theme files to include styles for the new components.

feat: implement custom scrollbar styles for response example components

fix: features

add actions , view more

feat: enhance response example functionality

- Added GenerateCodeItem component for generating code snippets from response examples.
- Integrated modal for code generation within ResponseExample component.
- Updated ResponseExampleTopBar to handle example name and description editing.
- Improved state management for response examples, including new actions for updating names and descriptions.
- Enhanced ResponseExampleRequestPane to support editing and saving request details.
- Refactored URL handling in ResponseExampleUrlBar to utilize example-specific data.
- Improved overall user experience with better UI elements and state management.

feat: enhance response example management and UI components

feat: enhance editing capabilities in response example components

feat: update multipart form parameter handling in response examples

feat: refactor response example parameter handling and enhance UI interactions

feat: introduce RadioButton component and update Checkbox usage in response examples

fix: styles

fix radio button styling

fixed radio button styles

feat: add create example from sidebar

feat: enhance ResponseExample components with layout adjustments and new HeightBoundContainer

feat: add Checkbox and RadioButton components with comprehensive tests for rendering, user interactions, and accessibility

feat: playwright test csaes

rm: comments

fix: linting

fix: tests

refactor: update response example tests and enhance functionality

fix: tests

fix: e2e-tests

refactor: implement hasRequestChanges utility for better change detection

rm: console

rm: consoles

fix: lint

fix: tests

fix: response header disabled by default issue

Feat/with bru example parser (#5892)

* fix: response header disabled by default issue

feat: new parsing logic

fix: change test cases to accomodate new brulang

add: path params features

rm:consoles

six: make tab permanent on double click

fix width

feat: add status editing

feat: review fixes

review fixes

fix: review fixes

fix: post review

mv: test files

fix: review

* fix: lint

* fix: review comments

* fix: icons folder strcuture

fix: tests

fix: lint

fix: unit tests

feat: body mode selector

fix: close all collections

rm: example

feat added tests. lang change

feat: add custom status text

fix: status update

feat: add body mode, update tests

add default name prefilled for example

fix: active tab styles, prefilled name, text fixes

fix : pkg lock

fix: review

fix: review comments

fix: hide cursor when readonly

fix: height

fix: null body

fix: response body parsing

fix: test cases

feat: add method support for examples

fix: reponse parsing

fix: update response body type when content type is updated

rm : commented code

feat: update parser logic

fix: organize files

feat: enhance examples handling in collection export and import

feat: postman imports fro examples

feat: enhance OpenAPI import functionality to support examples

feat: support postman export

fix: postman export import

fix: open api tests, remove requestbody related logic

rm: examples

fix:  move common attributes files

ui fixes

fix: clone issue

fix: create example from request menu

review fixes

more review fixes

mv: files, fix mode req error

organize files

fix:tests

fix: save dot issue

fix: bugs

fix: postman export

fix: import path params

* chore:improve modal handling in environment and response example tests

fix: test issues resolved

* chore: update response example tests to use new fixture files and improve cleanup logic

---------

Co-authored-by: Abhishek S Lal <abhishek@usebruno.com>
Co-authored-by: Bijin Bruno <bijin@usebruno.com>
2025-11-01 05:56:11 +05:30

249 lines
11 KiB
TypeScript

import { test, expect } from '../../../playwright';
import * as path from 'path';
import { closeAllCollections, openCollectionAndAcceptSandbox } from '../../utils/page';
test.describe('Import OpenAPI Collection with Examples', () => {
let originalShowOpenDialog;
test.beforeAll(async ({ electronApp }) => {
// save the original showOpenDialog function
await electronApp.evaluate(({ dialog }) => {
originalShowOpenDialog = dialog.showOpenDialog;
});
});
test.afterAll(async ({ electronApp, page }) => {
await closeAllCollections(page);
// restore the original showOpenDialog function
await electronApp.evaluate(({ dialog }) => {
dialog.showOpenDialog = originalShowOpenDialog;
});
});
test('should import OpenAPI collection with examples successfully', async ({ page, electronApp, createTmpDir }) => {
const openApiFile = path.resolve(__dirname, 'fixtures', 'openapi-with-examples.yaml');
// Create a temporary directory for the collection to be imported into
const importDir = await createTmpDir('imported-openapi-collection');
// Mock the electron dialog to return the import directory selection
await electronApp.evaluate(({ dialog }, { importDir }) => {
dialog.showOpenDialog = async () => ({
canceled: false,
filePaths: [importDir]
});
}, { importDir });
await test.step('Open import collection modal', async () => {
await page.getByRole('button', { name: 'Import Collection' }).click();
});
await test.step('Wait for import modal and verify title', async () => {
const importModal = page.getByRole('dialog');
await importModal.waitFor({ state: 'visible' });
await expect(importModal.locator('.bruno-modal-header-title')).toContainText('Import Collection');
});
await test.step('Upload OpenAPI collection file using hidden file input', async () => {
// The "choose a file" button triggers a hidden file input, so we can directly set files on it
await page.setInputFiles('input[type="file"]', openApiFile);
});
await test.step('Wait for file processing to complete', async () => {
await page.locator('#import-collection-loader').waitFor({ state: 'hidden' });
});
await test.step('Verify no parsing errors occurred', async () => {
const hasError = await page.getByText('Failed to parse the file').isVisible().catch(() => false);
if (hasError) {
throw new Error('Collection import failed with parsing error');
}
});
await test.step('Verify OpenAPI import settings modal appears', async () => {
const settingsModal = page.getByRole('dialog');
await expect(settingsModal.locator('.bruno-modal-header-title')).toContainText('OpenAPI Import Settings');
await settingsModal.getByRole('button', { name: 'Import' }).click();
});
await test.step('Click Browse link to select collection folder', async () => {
const settingsModal = page.getByRole('dialog');
await settingsModal.getByText('Browse').click();
});
await test.step('Complete import by clicking import button', async () => {
const settingsModal = page.getByRole('dialog');
await settingsModal.getByRole('button', { name: 'Import' }).click();
});
await test.step('Handle sandbox modal', async () => {
await openCollectionAndAcceptSandbox(page, 'API with Examples', 'safe');
});
await test.step('Verify collection name appears in sidebar', async () => {
const collectionName = page.locator('#sidebar-collection-name').getByText('API with Examples');
await expect(collectionName).toBeVisible();
});
await test.step('Verify GET /users request exists and has examples', async () => {
const getUsersRequest = page.locator('.collection-item-name').getByText('Get all users');
await expect(getUsersRequest).toBeVisible();
// Find the chevron icon specifically for the "Get all users" request
const chevronIcon = page.getByTestId('request-item-chevron').nth(0);
await expect(chevronIcon).toBeVisible();
// Click the chevron to expand examples
await chevronIcon.click();
// Check if examples are visible
const successExample = page.locator('.collection-item-name').getByText('Success Response');
const emptyExample = page.locator('.collection-item-name').getByText('Empty Response');
const validationErrorExample = page.locator('.collection-item-name').getByText('Validation Error');
const serverErrorExample = page.locator('.collection-item-name').getByText('Server Error');
await expect(successExample).toBeVisible();
await expect(emptyExample).toBeVisible();
await expect(validationErrorExample).toBeVisible();
await expect(serverErrorExample).toBeVisible();
await chevronIcon.click();
});
await test.step('Verify POST /users request exists and has examples', async () => {
// Click on the POST request
const createUserRequest = page.locator('.collection-item-name').getByText('Create a new user');
await expect(createUserRequest).toBeVisible();
await createUserRequest.click();
// Find the chevron icon specifically for the "Create a new user" request
const chevronIcon = page.getByTestId('request-item-chevron').nth(1);
await expect(chevronIcon).toBeVisible();
// Click the chevron to expand examples
await chevronIcon.click();
// Check if examples are visible
const createdExample = page.locator('.collection-item-name').getByText('User Created');
const validationErrorExample = page.locator('.collection-item-name').getByText('Validation Error');
await expect(createdExample).toBeVisible();
await expect(validationErrorExample).toBeVisible();
});
await test.step('Cleanup - close all collections', async () => {
await closeAllCollections(page);
});
});
test('should import OpenAPI collection with path-based grouping', async ({ page, electronApp, createTmpDir }) => {
const openApiFile = path.resolve(__dirname, 'fixtures', 'openapi-with-examples.yaml');
// Create a temporary directory for the collection to be imported into
const importDir = await createTmpDir('imported-openapi-collection-path');
// Mock the electron dialog to return the import directory selection
await electronApp.evaluate(({ dialog }, { importDir }) => {
dialog.showOpenDialog = async () => ({
canceled: false,
filePaths: [importDir]
});
}, { importDir });
await test.step('Open import collection modal', async () => {
await page.getByRole('button', { name: 'Import Collection' }).click();
});
await test.step('Wait for import modal and verify title', async () => {
const importModal = page.getByRole('dialog');
await importModal.waitFor({ state: 'visible' });
await expect(importModal.locator('.bruno-modal-header-title')).toContainText('Import Collection');
});
await test.step('Upload OpenAPI collection file using hidden file input', async () => {
await page.setInputFiles('input[type="file"]', openApiFile);
});
await test.step('Wait for file processing to complete', async () => {
await page.locator('#import-collection-loader').waitFor({ state: 'hidden' });
});
await test.step('Verify no parsing errors occurred', async () => {
const hasError = await page.getByText('Failed to parse the file').isVisible().catch(() => false);
if (hasError) {
throw new Error('Collection import failed with parsing error');
}
});
await test.step('Verify OpenAPI import settings modal appears', async () => {
const settingsModal = page.getByRole('dialog');
await expect(settingsModal.locator('.bruno-modal-header-title')).toContainText('OpenAPI Import Settings');
});
await test.step('Select path-based grouping option from dropdown', async () => {
const settingsModal = page.getByRole('dialog');
// Click on the grouping dropdown to open it
const groupingDropdown = settingsModal.getByTestId('grouping-dropdown');
await groupingDropdown.click();
// Wait for dropdown to open and select "Paths" option (note: it's "Paths" not "Path")
const pathOption = page.getByTestId('grouping-option-path');
await pathOption.click();
// click on import button
const importButton = settingsModal.getByRole('button', { name: 'Import' });
await importButton.click();
});
await test.step('Click Browse link to select collection folder', async () => {
const settingsModal = page.getByRole('dialog');
await settingsModal.getByText('Browse').click();
});
await test.step('Complete import by clicking import button', async () => {
const settingsModal = page.getByRole('dialog');
await settingsModal.getByRole('button', { name: 'Import' }).click();
});
await test.step('Handle sandbox modal', async () => {
await openCollectionAndAcceptSandbox(page, 'API with Examples', 'safe');
});
await test.step('Verify collection name appears in sidebar', async () => {
const collectionName = page.locator('#sidebar-collection-name').getByText('API with Examples');
await expect(collectionName).toBeVisible();
});
await test.step('Verify path-based grouping structure', async () => {
// With path-based grouping, requests should be organized by their path
// users should be a folder containing GET and POST requests
const usersFolder = page.locator('.collection-item-name').getByText('users');
await expect(usersFolder).toBeVisible();
// Click on the users folder to expand it
await usersFolder.click();
// Verify that the requests are inside the users folder
const getUsersRequest = page.locator('.collection-item-name').getByText('Get all users');
const createUserRequest = page.locator('.collection-item-name').getByText('Create a new user');
await expect(getUsersRequest).toBeVisible();
await expect(createUserRequest).toBeVisible();
});
await test.step('Verify examples work with path-based grouping', async () => {
// Test GET /users request examples
const getUsersRequest = page.locator('.collection-item-name').getByText('Get all users');
await expect(getUsersRequest).toBeVisible();
const chevronIcon = page.getByTestId('request-item-chevron').nth(0);
await expect(chevronIcon).toBeVisible();
await chevronIcon.click();
// Check if examples are visible
const successExample = page.locator('.collection-item-name').getByText('Success Response');
await expect(successExample).toBeVisible();
});
});
});