Files
bruno/tests/collection/open/open-multiple-collections.spec.ts
Abhishek S Lal 0197ae37c8 refactor: update AppTitleBar and SidebarHeader components (#6341)
* refactor: update AppTitleBar and SidebarHeader components to use MenuDropdown and ActionIcon for improved UI consistency

* refactor: update button locators in tests to use data-testid for consistency and improved readability
2025-12-08 22:06:24 +05:30

109 lines
3.9 KiB
TypeScript

import { test, expect } from '../../../playwright';
import * as path from 'path';
import * as fs from 'fs';
import { closeAllCollections } from '../../utils/page';
test.describe('Open Multiple Collections', () => {
let originalShowOpenDialog;
test.beforeAll(async ({ electronApp }) => {
// save the original showOpenDialog function
await electronApp.evaluate(({ dialog }) => {
originalShowOpenDialog = dialog.showOpenDialog;
});
});
test.afterAll(async ({ electronApp }) => {
// restore the original showOpenDialog function
await electronApp.evaluate(({ dialog }) => {
dialog.showOpenDialog = originalShowOpenDialog;
});
});
test('Should open multiple collections using Open Collection feature', async ({
page,
electronApp,
createTmpDir
}) => {
// Create two test collections with proper bruno.json files
const collection1Dir = await createTmpDir('collection-1');
const collection2Dir = await createTmpDir('collection-2');
// Create bruno.json for first collection
const collection1Config = {
version: '1',
name: 'Test Collection 1',
type: 'collection'
};
// Create bruno.json for second collection
const collection2Config = {
version: '1',
name: 'Test Collection 2',
type: 'collection'
};
fs.writeFileSync(path.join(collection1Dir, 'bruno.json'), JSON.stringify(collection1Config, null, 2));
fs.writeFileSync(path.join(collection2Dir, 'bruno.json'), JSON.stringify(collection2Config, null, 2));
// Mock the electron dialog to return multiple folder selections
await electronApp.evaluate(({ dialog }, { collection1Dir, collection2Dir }) => {
dialog.showOpenDialog = async () => ({
canceled: false,
filePaths: [collection1Dir, collection2Dir]
});
},
{ collection1Dir, collection2Dir });
await expect(page.locator('#sidebar-collection-name').getByText('Test Collection 1')).not.toBeVisible();
// Click on plus icon button and then "Open collection" in the dropdown
await page.getByTestId('collections-header-add-menu').click();
await page.locator('.tippy-box .dropdown-item').filter({ hasText: 'Open collection' }).click();
// Wait for both collections to appear in the sidebar
const collection1Element = page.locator('#sidebar-collection-name').getByText('Test Collection 1');
const collection2Element = page.locator('#sidebar-collection-name').getByText('Test Collection 2');
await expect(collection1Element).toBeVisible();
await expect(collection2Element).toBeVisible();
// cleanup: close all collections
await closeAllCollections(page);
});
test('Should handle invalid collection path and display error', async ({
page,
electronApp,
createTmpDir
}) => {
// Directory without bruno.json file
const collection1Dir = await createTmpDir('collection-1');
const collection2Dir = 'invalid-collection-path';
// Count collections before attempting to open invalid ones
const collectionCountBefore = await page.locator('#sidebar-collection-name').count();
// Mock the electron dialog to return multiple folder selections
await electronApp.evaluate(({ dialog }, { collection1Dir, collection2Dir }) => {
dialog.showOpenDialog = async () => ({
canceled: false,
filePaths: [collection1Dir, collection2Dir]
});
},
{ collection1Dir, collection2Dir });
await page.getByTestId('collections-header-add-menu').click();
await page.locator('.tippy-box .dropdown-item').filter({ hasText: 'Open collection' }).click();
// Wait for error toasts to appear
await page.waitForTimeout(1000);
// Verify no collections were opened
await expect(page.locator('#sidebar-collection-name')).toHaveCount(collectionCountBefore);
// Verify invalid collection error
const invalidCollectionError = page.getByText('The collection is not valid').first();
await expect(invalidCollectionError).toBeVisible();
});
});