mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-09 06:55:03 +00:00
fix(snapshot): folder nested script tab interactivity and tests (#8225)
* fix(snapshot): folder script interactivity * fix: add tests for collection scripts
This commit is contained in:
135
tests/snapshots/collection.spec.ts
Normal file
135
tests/snapshots/collection.spec.ts
Normal file
@@ -0,0 +1,135 @@
|
||||
import { test, expect, closeElectronApp } from '../../playwright';
|
||||
import {
|
||||
createCollection,
|
||||
createWorkspace,
|
||||
focusCollectionSettingsTab,
|
||||
openCollectionSettings,
|
||||
readSnapshot,
|
||||
findSnapshotCollectionTab,
|
||||
selectCollectionPaneTab,
|
||||
selectCollectionScriptPaneTab,
|
||||
switchWorkspace,
|
||||
waitForReadyPage,
|
||||
waitForSnapshotFile
|
||||
} from '../utils/page';
|
||||
|
||||
test.describe('Snapshot: collection Pane Interactivity', () => {
|
||||
test('collection pane tab interactivity is preserved after workspace switch', async ({ launchElectronApp, createTmpDir }) => {
|
||||
const userDataPath = await createTmpDir('snap-collection-workspace-switch');
|
||||
const colPath = await createTmpDir('col');
|
||||
|
||||
const app = await launchElectronApp({ userDataPath });
|
||||
const page = await waitForReadyPage(app);
|
||||
|
||||
await test.step('Create collection and open collection settings', async () => {
|
||||
await createCollection(page, 'TestCol', colPath);
|
||||
await openCollectionSettings(page, 'TestCol', { persist: true });
|
||||
await selectCollectionPaneTab(page, 'auth');
|
||||
});
|
||||
|
||||
await test.step('Switch to a new workspace', async () => {
|
||||
// Background flushing takes about 2 seconds to complete
|
||||
await page.waitForTimeout(2000);
|
||||
await createWorkspace(page, 'SecondWorkspace');
|
||||
await expect(page.getByTestId('workspace-name')).toHaveText('SecondWorkspace', { timeout: 5000 });
|
||||
});
|
||||
|
||||
await test.step('Switch back to original workspace and verify collection pane interactivity', async () => {
|
||||
await switchWorkspace(page, 'My Workspace');
|
||||
await openCollectionSettings(page, 'TestCol', { persist: true });
|
||||
|
||||
await focusCollectionSettingsTab(page);
|
||||
|
||||
await selectCollectionPaneTab(page, 'auth');
|
||||
await selectCollectionPaneTab(page, 'headers');
|
||||
await selectCollectionPaneTab(page, 'overview');
|
||||
await selectCollectionPaneTab(page, 'script');
|
||||
await selectCollectionPaneTab(page, 'vars');
|
||||
});
|
||||
|
||||
await closeElectronApp(app);
|
||||
});
|
||||
|
||||
test('collection pane tab interactivity is preserved after app restart', async ({ launchElectronApp, createTmpDir }) => {
|
||||
const userDataPath = await createTmpDir('snap-collection-restart');
|
||||
const colPath = await createTmpDir('col');
|
||||
|
||||
const app = await launchElectronApp({ userDataPath });
|
||||
const page = await waitForReadyPage(app);
|
||||
|
||||
await test.step('Create collection and open collection settings on auth tab', async () => {
|
||||
await createCollection(page, 'TestCol', colPath);
|
||||
await openCollectionSettings(page, 'TestCol', { persist: true });
|
||||
await selectCollectionPaneTab(page, 'auth');
|
||||
});
|
||||
|
||||
await test.step('Close app and verify snapshot stores collection-settings tab', async () => {
|
||||
await page.waitForTimeout(2000);
|
||||
await closeElectronApp(app);
|
||||
|
||||
await waitForSnapshotFile(userDataPath);
|
||||
|
||||
const snapshot = readSnapshot(userDataPath);
|
||||
const tab = findSnapshotCollectionTab(snapshot, colPath);
|
||||
expect(tab).toBeTruthy();
|
||||
expect(tab.type).toBe('collection-settings');
|
||||
expect(tab.permanent).toBe(true);
|
||||
});
|
||||
|
||||
await test.step('Restart app and verify collection pane interactivity is restored', async () => {
|
||||
const app2 = await launchElectronApp({ userDataPath });
|
||||
const page2 = await waitForReadyPage(app2);
|
||||
|
||||
await focusCollectionSettingsTab(page2, { timeout: 15000 });
|
||||
|
||||
await selectCollectionPaneTab(page2, 'auth');
|
||||
await selectCollectionPaneTab(page2, 'headers');
|
||||
await selectCollectionPaneTab(page2, 'overview');
|
||||
await selectCollectionPaneTab(page2, 'script');
|
||||
await selectCollectionPaneTab(page2, 'vars');
|
||||
|
||||
await closeElectronApp(app2);
|
||||
});
|
||||
});
|
||||
|
||||
test('collection script\'s tabs need to be interactive after app restart', async ({ launchElectronApp, createTmpDir }) => {
|
||||
const userDataPath = await createTmpDir('snap-collection-restart');
|
||||
const colPath = await createTmpDir('col');
|
||||
|
||||
const app = await launchElectronApp({ userDataPath });
|
||||
const page = await waitForReadyPage(app);
|
||||
|
||||
await test.step('Create collection and open collection settings on script tab', async () => {
|
||||
await createCollection(page, 'TestCol', colPath);
|
||||
await openCollectionSettings(page, 'TestCol', { persist: true });
|
||||
await selectCollectionPaneTab(page, 'script');
|
||||
});
|
||||
|
||||
await test.step('Close app and verify snapshot stores collection-settings tab', async () => {
|
||||
await page.waitForTimeout(2000);
|
||||
await closeElectronApp(app);
|
||||
|
||||
await waitForSnapshotFile(userDataPath);
|
||||
|
||||
const snapshot = readSnapshot(userDataPath);
|
||||
const tab = findSnapshotCollectionTab(snapshot, colPath);
|
||||
expect(tab).toBeTruthy();
|
||||
expect(tab.type).toBe('collection-settings');
|
||||
expect(tab.permanent).toBe(true);
|
||||
});
|
||||
|
||||
await test.step('Restart app and verify collection script pane is interactive', async () => {
|
||||
const app2 = await launchElectronApp({ userDataPath });
|
||||
const page2 = await waitForReadyPage(app2);
|
||||
|
||||
await focusCollectionSettingsTab(page2, { timeout: 15000 });
|
||||
|
||||
await selectCollectionPaneTab(page2, 'script');
|
||||
|
||||
await selectCollectionScriptPaneTab(page2, 'pre-request');
|
||||
await selectCollectionScriptPaneTab(page2, 'post-response');
|
||||
|
||||
await closeElectronApp(app2);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,34 +1,18 @@
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import { test, expect, closeElectronApp } from '../../playwright';
|
||||
import {
|
||||
createCollection,
|
||||
createFolder,
|
||||
createWorkspace,
|
||||
focusFolderSettingsTab,
|
||||
openfolder,
|
||||
readSnapshot,
|
||||
findSnapshotFolderTab,
|
||||
selectfolderPaneTab,
|
||||
selectFolderScriptPaneTab,
|
||||
switchWorkspace,
|
||||
waitForReadyPage
|
||||
waitForReadyPage,
|
||||
waitForSnapshotFile
|
||||
} 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 }) => {
|
||||
@@ -55,10 +39,7 @@ test.describe('Snapshot: folder Pane Interactivity', () => {
|
||||
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 focusFolderSettingsTab(page, 'TestFolder');
|
||||
|
||||
await selectfolderPaneTab(page, 'auth');
|
||||
await selectfolderPaneTab(page, 'headers');
|
||||
@@ -88,8 +69,7 @@ test.describe('Snapshot: folder Pane Interactivity', () => {
|
||||
await page.waitForTimeout(2000);
|
||||
await closeElectronApp(app);
|
||||
|
||||
const snapshotPath = path.join(userDataPath, 'ui-state-snapshot.json');
|
||||
await expect.poll(() => fs.existsSync(snapshotPath)).toBe(true);
|
||||
await waitForSnapshotFile(userDataPath);
|
||||
|
||||
const snapshot = readSnapshot(userDataPath);
|
||||
const tab = findSnapshotFolderTab(snapshot, 'TestFolder');
|
||||
@@ -102,9 +82,7 @@ test.describe('Snapshot: folder Pane Interactivity', () => {
|
||||
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 focusFolderSettingsTab(page2, 'TestFolder', { timeout: 15000 });
|
||||
|
||||
await selectfolderPaneTab(page2, 'auth');
|
||||
await selectfolderPaneTab(page2, 'headers');
|
||||
@@ -115,4 +93,46 @@ test.describe('Snapshot: folder Pane Interactivity', () => {
|
||||
await closeElectronApp(app2);
|
||||
});
|
||||
});
|
||||
|
||||
test('folder script\'s tabs need to be interactive 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, 'script');
|
||||
});
|
||||
|
||||
await test.step('Close app and verify snapshot stores folder-settings tab', async () => {
|
||||
await page.waitForTimeout(2000);
|
||||
await closeElectronApp(app);
|
||||
|
||||
await waitForSnapshotFile(userDataPath);
|
||||
|
||||
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 script pane is interactive', async () => {
|
||||
const app2 = await launchElectronApp({ userDataPath });
|
||||
const page2 = await waitForReadyPage(app2);
|
||||
|
||||
await focusFolderSettingsTab(page2, 'TestFolder', { timeout: 15000 });
|
||||
|
||||
await selectfolderPaneTab(page2, 'script');
|
||||
|
||||
await selectFolderScriptPaneTab(page2, 'pre-request');
|
||||
await selectFolderScriptPaneTab(page2, 'post-response');
|
||||
|
||||
await closeElectronApp(app2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user