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:
Sid
2026-06-12 19:13:34 +05:30
committed by lohit
parent a09ddedf90
commit f05bb9c49d
9 changed files with 343 additions and 34 deletions

View File

@@ -857,6 +857,101 @@ const selectfolderPaneTab = async (page: Page, tabName: string) => {
});
};
/**
* Select a sub-tab in the folder script pane (Pre Request or Post Response)
* @param page - The page object
* @param tabName - 'pre-request' or 'post-response'
* @returns void
*/
const selectFolderScriptPaneTab = async (page: Page, tabName: 'pre-request' | 'post-response') => {
await test.step(`Select folder script pane tab "${tabName}"`, async () => {
const locators = buildCommonLocators(page);
const tab = locators.paneTabs.folderScriptTab(tabName);
await tab.click();
await expect(tab).toContainClass('active');
});
};
/**
* Open a collection's settings tab by clicking on it in the sidebar
* @param page - The page object
* @param collectionName - The name of the collection
* @param options - Optional settings (persist: double-click to make tab permanent)
* @returns void
*/
const openCollectionSettings = async (page: Page, collectionName: string, { persist = false } = {}) => {
await test.step(`Open collection settings for "${collectionName}"`, async () => {
const locators = buildCommonLocators(page);
const collection = locators.sidebar.collection(collectionName);
if (!persist) {
await collection.click();
} else {
await collection.dblclick();
}
});
};
/**
* Select a tab in the collection settings pane
* @param page - The page object
* @param tabName - The tab name key (e.g. 'auth', 'headers', 'overview', 'script', 'vars')
* @returns void
*/
const selectCollectionPaneTab = async (page: Page, tabName: string) => {
await test.step(`Select collection pane tab "${tabName}"`, async () => {
const locators = buildCommonLocators(page);
const tab = locators.paneTabs.collectionSettingsTab(tabName.toLowerCase());
await tab.click();
await expect(tab).toContainClass('active');
});
};
/**
* Select a sub-tab in the collection script pane (Pre Request or Post Response)
* @param page - The page object
* @param tabName - 'pre-request' or 'post-response'
* @returns void
*/
const selectCollectionScriptPaneTab = async (page: Page, tabName: 'pre-request' | 'post-response') => {
await test.step(`Select collection script pane tab "${tabName}"`, async () => {
const locators = buildCommonLocators(page);
const tab = locators.paneTabs.tabTrigger(tabName);
await tab.click();
await expect(tab).toContainClass('active');
});
};
/**
* Focus the folder settings tab in the tab bar after restore
* @param page - The page object
* @param folderName - The name of the folder
* @param options - Optional timeout in milliseconds
* @returns void
*/
const focusFolderSettingsTab = async (page: Page, folderName: string, { timeout = 10000 } = {}) => {
await test.step(`Focus folder settings tab "${folderName}"`, async () => {
const locators = buildCommonLocators(page);
const tab = locators.tabs.folderTab(folderName);
await expect(tab).toBeVisible({ timeout });
await tab.click({ force: true });
});
};
/**
* Focus the collection settings tab in the tab bar after restore
* @param page - The page object
* @param options - Optional timeout in milliseconds
* @returns void
*/
const focusCollectionSettingsTab = async (page: Page, { timeout = 10000 } = {}) => {
await test.step('Focus collection settings tab', async () => {
const locators = buildCommonLocators(page);
const tab = locators.tabs.collectionSettingsTab();
await expect(tab).toBeVisible({ timeout });
await tab.click({ force: true });
});
};
/**
* Open a request within a folder
* @param page - The page object
@@ -1667,6 +1762,12 @@ export {
openfolder,
openFolderRequest,
selectfolderPaneTab,
selectFolderScriptPaneTab,
openCollectionSettings,
selectCollectionPaneTab,
selectCollectionScriptPaneTab,
focusFolderSettingsTab,
focusCollectionSettingsTab,
getResponseBody,
expectResponseContains,
selectRequestPaneTab,

View File

@@ -1,3 +1,4 @@
export * from './actions';
export * from './runner';
export * from './locators';
export * from '../snapshot';

View File

@@ -38,6 +38,8 @@ export const buildCommonLocators = (page: Page) => ({
tabs: {
requestTab: (requestName: string) => page.locator('.request-tab .tab-label').filter({ hasText: requestName }),
folderTab: (folderName: string) => page.locator('.request-tab .tab-label').filter({ hasText: folderName }),
collectionSettingsTab: () =>
page.locator('.request-tab').filter({ has: page.locator('.tab-label', { hasText: 'Collection' }) }),
activeRequestTab: () => page.locator('.request-tab.active'),
closeTab: (requestName: string) => page.locator('.request-tab').filter({ hasText: requestName }).getByTestId('request-tab-close-icon'),
draftIndicator: () => page.locator('.request-tab.active .has-changes-icon')
@@ -46,6 +48,7 @@ export const buildCommonLocators = (page: Page) => ({
responsiveTab: (key: string) => page.getByTestId(`responsive-tab-${key}`),
collectionSettingsTab: (key: string) => page.getByTestId(`collection-settings-tab-${key}`),
folderSettingsTab: (key: string) => page.getByTestId(`folder-settings-tab-${key}`),
folderScriptTab: (key: 'pre-request' | 'post-response') => page.getByTestId(`tab-trigger-${key}`),
tabTrigger: (key: string) => page.getByTestId(`tab-trigger-${key}`)
},
folder: {

43
tests/utils/snapshot.ts Normal file
View File

@@ -0,0 +1,43 @@
import path from 'path';
import fs from 'fs';
import { expect } from '../../playwright';
export const getSnapshotPath = (userDataPath: string) =>
path.join(userDataPath, 'ui-state-snapshot.json');
/**
* Read the snapshot JSON from the user data directory.
* electron-store saves it as `ui-state-snapshot.json`.
*/
export const readSnapshot = (userDataPath: string) => {
const snapshotPath = getSnapshotPath(userDataPath);
if (!fs.existsSync(snapshotPath)) return null;
return JSON.parse(fs.readFileSync(snapshotPath, 'utf-8'));
};
export const waitForSnapshotFile = async (userDataPath: string) => {
await expect.poll(() => fs.existsSync(getSnapshotPath(userDataPath))).toBe(true);
};
export 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;
};
export const findSnapshotCollectionTab = (snapshot: any, collectionPath: string) => {
if (!snapshot || !Array.isArray(snapshot.collections)) return null;
for (const collection of snapshot.collections) {
if (collectionPath && collection?.pathname && !collection.pathname.includes(collectionPath)) continue;
if (!Array.isArray(collection?.tabs)) continue;
const tab = collection.tabs.find((t: any) => t?.type === 'collection-settings');
if (tab) return tab;
}
return null;
};