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

@@ -15,11 +15,8 @@ test.describe('Import Corrupted Bruno Collection - Should Fail', () => {
await page.setInputFiles('input[type="file"]', brunoFile);
// Check for JSON parsing error
const hasImportError = await page.getByText('Failed to parse the file ensure it is valid JSON or YAML').first().isVisible({ timeout: 5000 });
// Either parsing error or import error should be shown
expect(hasImportError).toBe(true);
const errorLocator = page.getByText(/Failed to parse the file|Unsupported collection format|Invalid|Error/).first();
await expect(errorLocator).toBeVisible({ timeout: 10000 });
// Cleanup: close any open modals
await page.getByTestId('modal-close-button').click();

View File

@@ -15,10 +15,8 @@ test.describe('Import Bruno Collection - Missing Required Schema Fields', () =>
await page.setInputFiles('input[type="file"]', brunoFile);
// Check for schema validation error messages
const hasImportError = await page.getByText('Unsupported collection format').first().isVisible({ timeout: 5000 });
expect(hasImportError).toBe(true);
const errorMessage = page.getByText('Unsupported collection format').first();
await expect(errorMessage).toBeVisible({ timeout: 10000 });
// Cleanup: close any open modals
await page.getByTestId('modal-close-button').click();

View File

@@ -1,6 +1,6 @@
import { test, expect } from '../../../playwright';
import { test } from '../../../playwright';
import * as path from 'path';
import { closeAllCollections } from '../../utils/page';
import { closeAllCollections, importCollection } from '../../utils/page';
test.describe('Import Bruno Testbench Collection', () => {
test.afterAll(async ({ page }) => {
@@ -10,27 +10,8 @@ test.describe('Import Bruno Testbench Collection', () => {
test('Import Bruno Testbench collection successfully', async ({ page, createTmpDir }) => {
const brunoFile = path.resolve(__dirname, 'fixtures', 'bruno-testbench.json');
await page.locator('.plus-icon-button').click();
await page.locator('.tippy-box .dropdown-item').filter({ hasText: 'Import collection' }).click();
// Wait for import collection modal to be ready
const importModal = page.getByRole('dialog');
await importModal.waitFor({ state: 'visible' });
await expect(importModal.locator('.bruno-modal-header-title')).toContainText('Import Collection');
await page.setInputFiles('input[type="file"]', brunoFile);
// 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');
// Wait for collection to appear in the location modal
await expect(locationModal.getByText('bruno-testbench')).toBeVisible();
await page.locator('#collection-location').fill(await createTmpDir('bruno-testbench-test'));
await locationModal.getByRole('button', { name: 'Import' }).click();
await expect(page.locator('#sidebar-collection-name').getByText('bruno-testbench')).toBeVisible();
await importCollection(page, brunoFile, await createTmpDir('bruno-testbench-test'), {
expectedCollectionName: 'bruno-testbench'
});
});
});

View File

@@ -21,19 +21,24 @@ test.describe('Import Bruno Collection with Examples', () => {
await expect(importModal.locator('.bruno-modal-header-title')).toContainText('Import Collection');
});
await test.step('Upload collection file', async () => {
await test.step('Upload collection file and verify location modal appears', async () => {
await page.setInputFiles('input[type="file"]', brunoFile);
});
await test.step('Verify no parsing errors occurred', async () => {
const hasError = await page.getByText('Failed to parse the file').isVisible().catch(() => false);
if (hasError) {
const locationModal = page.locator('[data-testid="import-collection-location-modal"]');
const errorMessage = page.getByText('Failed to parse the file');
const result = await Promise.race([
locationModal.waitFor({ state: 'visible', timeout: 15000 }).then(() => 'success'),
errorMessage.waitFor({ state: 'visible', timeout: 15000 }).then(() => 'error')
]).catch(() => 'timeout');
if (result === 'error') {
throw new Error('Collection import failed with parsing error');
}
});
if (result === 'timeout') {
throw new Error('Import timed out - neither success nor error state was reached');
}
await test.step('Verify location selection modal appears', async () => {
const locationModal = page.locator('[data-testid="import-collection-location-modal"]');
await expect(locationModal.locator('.bruno-modal-header-title')).toContainText('Import Collection');
});

View File

@@ -1,34 +1,17 @@
import { test, expect } from '../../../playwright';
import { test } from '../../../playwright';
import * as path from 'path';
import { closeAllCollections } from '../../utils/page';
import { closeAllCollections, importCollection } from '../../utils/page';
test.describe('Import Insomnia Collection v4', () => {
test.afterEach(async ({ page }) => {
// cleanup: close all collections
await closeAllCollections(page);
});
test('Import Insomnia Collection v4 successfully', async ({ page, createTmpDir }) => {
const insomniaFile = path.resolve(__dirname, 'fixtures', 'insomnia-v4.json');
await page.locator('.plus-icon-button').click();
await page.locator('.tippy-box .dropdown-item').filter({ hasText: 'Import collection' }).click();
// Wait for import collection modal to be ready
const importModal = page.getByRole('dialog');
await importModal.waitFor({ state: 'visible' });
await expect(importModal.locator('.bruno-modal-header-title')).toContainText('Import Collection');
await page.setInputFiles('input[type="file"]', insomniaFile);
// 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 page.locator('#collection-location').fill(await createTmpDir('insomnia-v4-test'));
await locationModal.getByRole('button', { name: 'Import' }).click();
await expect(page.locator('#sidebar-collection-name').getByText('Test API Collection v4')).toBeVisible();
await importCollection(page, insomniaFile, await createTmpDir('insomnia-v4-test'), {
expectedCollectionName: 'Test API Collection v4'
});
});
});

View File

@@ -1,34 +1,17 @@
import { test, expect } from '../../../playwright';
import { test } from '../../../playwright';
import * as path from 'path';
import { closeAllCollections } from '../../utils/page';
import { closeAllCollections, importCollection } from '../../utils/page';
test.describe('Import Insomnia Collection v5', () => {
test.afterEach(async ({ page }) => {
// cleanup: close all collections
await closeAllCollections(page);
});
test('Import Insomnia Collection v5 successfully', async ({ page, createTmpDir }) => {
const insomniaFile = path.resolve(__dirname, 'fixtures', 'insomnia-v5.yaml');
await page.locator('.plus-icon-button').click();
await page.locator('.tippy-box .dropdown-item').filter({ hasText: 'Import collection' }).click();
// Wait for import collection modal to be ready
const importModal = page.getByRole('dialog');
await importModal.waitFor({ state: 'visible' });
await expect(importModal.locator('.bruno-modal-header-title')).toContainText('Import Collection');
await page.setInputFiles('input[type="file"]', insomniaFile);
// 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 page.locator('#collection-location').fill(await createTmpDir('insomnia-v5-test'));
await locationModal.getByRole('button', { name: 'Import' }).click();
await expect(page.locator('#sidebar-collection-name').getByText('Test API Collection v5')).toBeVisible();
await importCollection(page, insomniaFile, await createTmpDir('insomnia-v5-test'), {
expectedCollectionName: 'Test API Collection v5'
});
});
});

View File

@@ -15,11 +15,10 @@ test.describe('Invalid Insomnia Collection - Missing Collection Array', () => {
await page.setInputFiles('input[type="file"]', insomniaFile);
// Check for error message
const hasError = await page.getByText('Unsupported collection format').first().isVisible();
expect(hasError).toBe(true);
const errorLocator = page.getByText('Unsupported collection format').first();
await expect(errorLocator).toBeVisible({ timeout: 10000 });
// Cleanup: close any open modals
await page.locator('[data-test-id="modal-close-button"]').click();
await page.getByTestId('modal-close-button').click();
});
});

View File

@@ -1,39 +1,17 @@
import { test, expect } from '../../../playwright';
import { test } from '../../../playwright';
import * as path from 'path';
import { closeAllCollections } from '../../utils/page';
import { closeAllCollections, importCollection } from '../../utils/page';
test.describe('Import OpenAPI v3 JSON Collection', () => {
test.afterEach(async ({ page }) => {
// cleanup: close all collections
await closeAllCollections(page);
});
test('Import simple OpenAPI v3 JSON successfully', async ({ page, createTmpDir }) => {
const openApiFile = path.resolve(__dirname, 'fixtures', 'openapi-simple.json');
await page.locator('.plus-icon-button').click();
await page.locator('.tippy-box .dropdown-item').filter({ hasText: 'Import collection' }).click();
// Wait for import collection modal to be ready
const importModal = page.getByRole('dialog');
await importModal.waitFor({ state: 'visible' });
await expect(importModal.locator('.bruno-modal-header-title')).toContainText('Import Collection');
await page.setInputFiles('input[type="file"]', openApiFile);
// 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');
// Wait for collection to appear in the location modal
await expect(locationModal.getByText('Simple Test API')).toBeVisible();
// Select a location and import
await page.locator('#collection-location').fill(await createTmpDir('simple-test'));
await locationModal.getByRole('button', { name: 'Import' }).click();
// Verify the collection was imported successfully
await expect(page.locator('#sidebar-collection-name').getByText('Simple Test API')).toBeVisible();
await importCollection(page, openApiFile, await createTmpDir('simple-test'), {
expectedCollectionName: 'Simple Test API'
});
});
});

View File

@@ -1,39 +1,17 @@
import { test, expect } from '../../../playwright';
import { test } from '../../../playwright';
import * as path from 'path';
import { closeAllCollections } from '../../utils/page';
import { closeAllCollections, importCollection } from '../../utils/page';
test.describe('Import OpenAPI v3 YAML Collection', () => {
test.afterEach(async ({ page }) => {
// cleanup: close all collections
await closeAllCollections(page);
});
test('Import comprehensive OpenAPI v3 YAML successfully', async ({ page, createTmpDir }) => {
const openApiFile = path.resolve(__dirname, 'fixtures', 'openapi-comprehensive.yaml');
await page.locator('.plus-icon-button').click();
await page.locator('.tippy-box .dropdown-item').filter({ hasText: 'Import collection' }).click();
// Wait for import collection modal to be ready
const importModal = page.getByRole('dialog');
await importModal.waitFor({ state: 'visible' });
await expect(importModal.locator('.bruno-modal-header-title')).toContainText('Import Collection');
await page.setInputFiles('input[type="file"]', openApiFile);
// 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');
// Wait for collection to appear in the location modal
await expect(locationModal.getByText('Comprehensive API Test Collection')).toBeVisible();
// Select a location and import
await page.locator('#collection-location').fill(await createTmpDir('comprehensive-test'));
await locationModal.getByRole('button', { name: 'Import' }).click();
// Verify the collection was imported successfully
await expect(page.locator('#sidebar-collection-name').getByText('Comprehensive API Test Collection')).toBeVisible();
await importCollection(page, openApiFile, await createTmpDir('comprehensive-test'), {
expectedCollectionName: 'Comprehensive API Test Collection'
});
});
});

View File

@@ -15,12 +15,11 @@ test.describe('Invalid OpenAPI - Malformed YAML', () => {
await page.setInputFiles('input[type="file"]', openApiFile);
// Check for error message - this should fail during YAML parsing
const hasParseError = await page.getByText('Failed to parse the file').isVisible();
const hasImportError = await page.getByText('Import collection failed').isVisible();
const parseError = page.getByText('Failed to parse the file');
const importError = page.getByText('Import collection failed');
// Either parsing error or import error should be shown
expect(hasParseError || hasImportError).toBe(true);
// Wait for at least one error message to be visible
await expect(parseError.or(importError)).toBeVisible({ timeout: 10000 });
// Cleanup: close any open modals
await page.locator('[data-test-id="modal-close-button"]').click();

View File

@@ -15,11 +15,8 @@ test.describe('Invalid OpenAPI - Missing Info Section', () => {
await page.setInputFiles('input[type="file"]', openApiFile);
// The OpenAPI parser might handle missing info gracefully with defaults
const hasError = await page.getByText('Unsupported collection format').first().isVisible();
// Either should show an error or create an "Untitled Collection"
expect(hasError).toBe(true);
const errorMessage = page.getByText('Unsupported collection format').first();
await expect(errorMessage).toBeVisible({ timeout: 10000 });
// Cleanup: close any open modals
await page.locator('[data-test-id="modal-close-button"]').click();

View File

@@ -1,39 +1,17 @@
import { test, expect } from '../../../playwright';
import { test } from '../../../playwright';
import * as path from 'path';
import { closeAllCollections } from '../../utils/page';
import { closeAllCollections, importCollection } from '../../utils/page';
test.describe('Import Postman Collection v2.0', () => {
test.afterEach(async ({ page }) => {
// cleanup: close all collections
await closeAllCollections(page);
});
test('Import Postman Collection v2.0 successfully', async ({ page, createTmpDir }) => {
const postmanFile = path.resolve(__dirname, 'fixtures', 'postman-v20.json');
await page.locator('.plus-icon-button').click();
await page.locator('.tippy-box .dropdown-item').filter({ hasText: 'Import collection' }).click();
// Wait for import collection modal to be ready
const importModal = page.getByRole('dialog');
await importModal.waitFor({ state: 'visible' });
await expect(importModal.locator('.bruno-modal-header-title')).toContainText('Import Collection');
await page.setInputFiles('input[type="file"]', postmanFile);
// 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');
// Wait for collection to appear in the location modal
await expect(locationModal.getByText('Postman v2.0 Collection')).toBeVisible();
// Select a location and import
await page.locator('#collection-location').fill(await createTmpDir('postman-v20-test'));
await locationModal.getByRole('button', { name: 'Import' }).click();
// Verify the collection was imported successfully
await expect(page.locator('#sidebar-collection-name').getByText('Postman v2.0 Collection')).toBeVisible();
await importCollection(page, postmanFile, await createTmpDir('postman-v20-test'), {
expectedCollectionName: 'Postman v2.0 Collection'
});
});
});

View File

@@ -1,39 +1,17 @@
import { test, expect } from '../../../playwright';
import { test } from '../../../playwright';
import * as path from 'path';
import { closeAllCollections } from '../../utils/page';
import { closeAllCollections, importCollection } from '../../utils/page';
test.describe('Import Postman Collection v2.1', () => {
test.afterEach(async ({ page }) => {
// cleanup: close all collections
await closeAllCollections(page);
});
test('Import Postman Collection v2.1 successfully', async ({ page, createTmpDir }) => {
const postmanFile = path.resolve(__dirname, 'fixtures', 'postman-v21.json');
await page.locator('.plus-icon-button').click();
await page.locator('.tippy-box .dropdown-item').filter({ hasText: 'Import collection' }).click();
// Wait for import collection modal to be ready
const importModal = page.getByRole('dialog');
await importModal.waitFor({ state: 'visible' });
await expect(importModal.locator('.bruno-modal-header-title')).toContainText('Import Collection');
await page.setInputFiles('input[type="file"]', postmanFile);
// 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');
// Wait for collection to appear in the location modal
await expect(locationModal.getByText('Postman v2.1 Collection')).toBeVisible();
// Select a location and import
await page.locator('#collection-location').fill(await createTmpDir('postman-v21-test'));
await locationModal.getByRole('button', { name: 'Import' }).click();
// Verify the collection was imported successfully
await expect(page.locator('#sidebar-collection-name').getByText('Postman v2.1 Collection')).toBeVisible();
await importCollection(page, postmanFile, await createTmpDir('postman-v21-test'), {
expectedCollectionName: 'Postman v2.1 Collection'
});
});
});

View File

@@ -15,11 +15,10 @@ test.describe('Invalid Postman Collection - Malformed Structure', () => {
await page.setInputFiles('input[type="file"]', postmanFile);
// Check for error message
const hasError = await page.getByText('Unsupported collection format').first().isVisible();
expect(hasError).toBe(true);
const errorLocator = page.getByText(/Unsupported collection format|Failed to parse|Invalid|Error/).first();
await expect(errorLocator).toBeVisible({ timeout: 10000 });
// Cleanup: close any open modals
await page.locator('[data-test-id="modal-close-button"]').click();
await page.getByTestId('modal-close-button').click();
});
});