Repository navigation
fix(snapshot): folder nested script tab interactivity and tests - #8225
Conversation
WalkthroughThis PR fixes state synchronization for folder and collection settings tabs in the Bruno app. Core Redux reducer logic and tab selection now properly distinguish between parent folder UIDs and individual settings tab UIDs, with new snapshot-based tests validating that both folder and collection settings panes remain interactive across workspace switches and app restarts. ChangesSettings Tab Persistence and Sync
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (3)
tests/utils/snapshot.ts (1)
22-32: 💤 Low valueConsider more precise folder matching.
Line 27 uses
t.pathname.includes(folderName), which will match partial strings. For example,"Folder"would match both"TestFolder"and"MyFolder", potentially returning the wrong tab in tests with similarly-named folders.If the pathname format is predictable, consider using
endsWithor a path-based comparison.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/utils/snapshot.ts` around lines 22 - 32, findSnapshotFolderTab currently uses t.pathname.includes(folderName) which matches substrings and can return the wrong tab; update the pathname check in findSnapshotFolderTab to a stricter comparison (for example use t.pathname.endsWith(folderName) or compare the last path segment: t.pathname.split('/').pop() === folderName) so only exact folder matches are returned while keeping the existing null/array guards.tests/snapshots/collection.spec.ts (1)
32-32: ⚡ Quick winConsider replacing hardcoded timeouts with event-driven waits.
Lines 32, 67, and 109 use
page.waitForTimeout()with fixed 2-second delays. Per coding guidelines, prefer event-driven waits over magic timeouts.If this timeout is necessary for background snapshot flushing, add a comment documenting the requirement and consider waiting for an observable state change instead.
Also applies to: 67-67, 109-109
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/snapshots/collection.spec.ts` at line 32, Replace the hardcoded delays using page.waitForTimeout(2000) in the test file by waiting for an observable event or state change instead: identify the operation that requires waiting (e.g., snapshot flush/response/update) and use Playwright's event-driven waits such as page.waitForResponse, page.waitForSelector, or page.waitForFunction to detect completion; if the sleep is truly unavoidable, add a clear comment above each page.waitForTimeout call explaining why the timeout is required (background snapshot flushing) and consider creating a helper (e.g., waitForSnapshotFlush) that polls the application state via page.evaluate or an API endpoint so tests are deterministic.tests/snapshots/folder.spec.ts (1)
33-33: ⚡ Quick winConsider replacing hardcoded timeouts with event-driven waits.
Lines 33, 69, and 112 use
page.waitForTimeout()with fixed delays. Per coding guidelines, these should be replaced with assertions or locator waits where possible.If the timeout is needed for background state flushing, add a comment explaining why the specific duration is required.
Also applies to: 69-69, 112-112
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/snapshots/folder.spec.ts` at line 33, Replace the three instances of the hardcoded await page.waitForTimeout(1000); in folder.spec.ts with event-driven waits: use locator.waitFor(), page.waitForSelector(), expect(locator).toHaveText()/toBeVisible(), or page.waitForResponse() that matches the UI/network event you care about; if a fixed delay truly is required for background flushing, keep the timeout but add a comment explaining why 1000ms is necessary and consider extracting it to a named constant (e.g., FLUSH_DELAY_MS) so intent is clear.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/utils/snapshot.ts`:
- Line 34: The function findSnapshotCollectionTab currently declares
collectionPath as required but checks it as optional; change the signature to
make collectionPath optional (collectionPath?: string) so the type matches the
runtime check in findSnapshotCollectionTab, and update any callers if they
relied on it being required or add non-null assertions where callers must pass a
string.
- Around line 12-16: The readSnapshot function currently calls JSON.parse on
fs.readFileSync which will throw on malformed ui-state-snapshot.json; update
readSnapshot (and keep getSnapshotPath usage) to wrap the fs.readFileSync +
JSON.parse in a try-catch, and on parse errors return null (or rethrow a new
Error with a descriptive message), ensuring malformed snapshot files do not
crash tests and that the error path is clear.
---
Nitpick comments:
In `@tests/snapshots/collection.spec.ts`:
- Line 32: Replace the hardcoded delays using page.waitForTimeout(2000) in the
test file by waiting for an observable event or state change instead: identify
the operation that requires waiting (e.g., snapshot flush/response/update) and
use Playwright's event-driven waits such as page.waitForResponse,
page.waitForSelector, or page.waitForFunction to detect completion; if the sleep
is truly unavoidable, add a clear comment above each page.waitForTimeout call
explaining why the timeout is required (background snapshot flushing) and
consider creating a helper (e.g., waitForSnapshotFlush) that polls the
application state via page.evaluate or an API endpoint so tests are
deterministic.
In `@tests/snapshots/folder.spec.ts`:
- Line 33: Replace the three instances of the hardcoded await
page.waitForTimeout(1000); in folder.spec.ts with event-driven waits: use
locator.waitFor(), page.waitForSelector(),
expect(locator).toHaveText()/toBeVisible(), or page.waitForResponse() that
matches the UI/network event you care about; if a fixed delay truly is required
for background flushing, keep the timeout but add a comment explaining why
1000ms is necessary and consider extracting it to a named constant (e.g.,
FLUSH_DELAY_MS) so intent is clear.
In `@tests/utils/snapshot.ts`:
- Around line 22-32: findSnapshotFolderTab currently uses
t.pathname.includes(folderName) which matches substrings and can return the
wrong tab; update the pathname check in findSnapshotFolderTab to a stricter
comparison (for example use t.pathname.endsWith(folderName) or compare the last
path segment: t.pathname.split('/').pop() === folderName) so only exact folder
matches are returned while keeping the existing null/array guards.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: a42ba347-ce61-45e4-aad6-841bb0021c7a
📒 Files selected for processing (9)
packages/bruno-app/src/components/FolderSettings/Script/index.jspackages/bruno-app/src/components/RequestTabs/RequestTab/index.jspackages/bruno-app/src/providers/ReduxStore/slices/tabs.jstests/snapshots/collection.spec.tstests/snapshots/folder.spec.tstests/utils/page/actions.tstests/utils/page/index.tstests/utils/page/locators.tstests/utils/snapshot.ts
|
Did local testing, ran folder specific tests. LGTM! @lohit-bruno can you take final look and merge if no concerns? |
* fix(snapshot): folder script interactivity * fix: add tests for collection scripts
…runo#8225) * fix(snapshot): folder script interactivity * fix: add tests for collection scripts
Description
JIRA
Contribution Checklist:
Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.
Publishing to New Package Managers
Please see here for more information.
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests