Files
bruno/tests/snapshots/folder.spec.ts
Sid 7d2af32d9c fix: tab type resolution for non request types (#8097)
* fix: tab type resolution for non request types

* Remove console log from snapshot test

Removed console log statement from folder.spec.ts

* test(snapshot): deserializeTab test addition for the removed guard
2026-05-26 13:45:05 +05:30

119 lines
4.7 KiB
TypeScript

import path from 'path';
import fs from 'fs';
import { test, expect, closeElectronApp } from '../../playwright';
import {
createCollection,
createFolder,
createWorkspace,
openfolder,
selectfolderPaneTab,
switchWorkspace,
waitForReadyPage
} from '../utils/page';
import { buildCommonLocators } from '../utils/page/locators';
const readSnapshot = (userDataPath: string) => {
const snapshotPath = path.join(userDataPath, 'ui-state-snapshot.json');
if (!fs.existsSync(snapshotPath)) return null;
return JSON.parse(fs.readFileSync(snapshotPath, 'utf-8'));
};
const findSnapshotFolderTab = (snapshot: any, folderName: string) => {
if (!snapshot || !Array.isArray(snapshot.collections)) return null;
for (const collection of snapshot.collections) {
if (!Array.isArray(collection?.tabs)) continue;
const tab = collection.tabs.find(
(t: any) => t?.type === 'folder-settings' && typeof t?.pathname === 'string' && t.pathname.includes(folderName)
);
if (tab) return tab;
}
return null;
};
test.describe('Snapshot: folder Pane Interactivity', () => {
test('folder pane tab interactivity is preserved after workspace switch', async ({ launchElectronApp, createTmpDir }) => {
const userDataPath = await createTmpDir('snap-folder-workspace-switch');
const colPath = await createTmpDir('col');
const app = await launchElectronApp({ userDataPath });
const page = await waitForReadyPage(app);
await test.step('Create collection and folder, open folder settings', async () => {
await createCollection(page, 'TestCol', colPath);
await createFolder(page, 'TestFolder', 'TestCol');
await openfolder(page, 'TestCol', 'TestFolder', { persist: true });
await selectfolderPaneTab(page, 'auth');
});
await test.step('Switch to a new workspace', async () => {
await page.waitForTimeout(1000);
await createWorkspace(page, 'SecondWorkspace');
await expect(page.getByTestId('workspace-name')).toHaveText('SecondWorkspace', { timeout: 5000 });
});
await test.step('Switch back to original workspace and verify folder pane interactivity', async () => {
await switchWorkspace(page, 'My Workspace');
await openfolder(page, 'TestCol', 'TestFolder', { persist: true });
const locators = buildCommonLocators(page);
await expect(locators.tabs.folderTab('TestFolder')).toBeVisible({ timeout: 10000 });
await locators.tabs.folderTab('TestFolder').click({ force: true });
await selectfolderPaneTab(page, 'auth');
await selectfolderPaneTab(page, 'headers');
await selectfolderPaneTab(page, 'docs');
await selectfolderPaneTab(page, 'script');
await selectfolderPaneTab(page, 'vars');
});
await closeElectronApp(app);
});
test('folder pane tab interactivity is preserved after app restart', async ({ launchElectronApp, createTmpDir }) => {
const userDataPath = await createTmpDir('snap-folder-restart');
const colPath = await createTmpDir('col');
const app = await launchElectronApp({ userDataPath });
const page = await waitForReadyPage(app);
await test.step('Create collection and folder, open folder settings on auth tab', async () => {
await createCollection(page, 'TestCol', colPath);
await createFolder(page, 'TestFolder', 'TestCol');
await openfolder(page, 'TestCol', 'TestFolder', { persist: true });
await selectfolderPaneTab(page, 'auth');
});
await test.step('Close app and verify snapshot stores folder-settings tab', async () => {
await page.waitForTimeout(2000);
await closeElectronApp(app);
const snapshotPath = path.join(userDataPath, 'ui-state-snapshot.json');
await expect.poll(() => fs.existsSync(snapshotPath)).toBe(true);
const snapshot = readSnapshot(userDataPath);
const tab = findSnapshotFolderTab(snapshot, 'TestFolder');
expect(tab).toBeTruthy();
expect(tab.type).toBe('folder-settings');
expect(tab.permanent).toBe(true);
});
await test.step('Restart app and verify folder pane interactivity is restored', async () => {
const app2 = await launchElectronApp({ userDataPath });
const page2 = await waitForReadyPage(app2);
const locators = buildCommonLocators(page2);
await expect(locators.tabs.folderTab('TestFolder')).toBeVisible({ timeout: 15000 });
await locators.tabs.folderTab('TestFolder').click({ force: true });
await selectfolderPaneTab(page2, 'auth');
await selectfolderPaneTab(page2, 'headers');
await selectfolderPaneTab(page2, 'docs');
await selectfolderPaneTab(page2, 'script');
await selectfolderPaneTab(page2, 'vars');
await closeElectronApp(app2);
});
});
});