From 707fd405ff1b5e43c78fdef6362c071e76353648 Mon Sep 17 00:00:00 2001 From: gopu-bruno Date: Sat, 7 Mar 2026 00:23:01 +0530 Subject: [PATCH] Fix: resolve default location missing path (#7391) * fix: refocus collection name input on error and resolve missing default location folder * revert: remove focus refocus logic from InlineCollectionCreator Reverts the setTimeout focus change that was causing test failures. Keeps the preferences.js fix for default location validation. Made-with: Cursor * fix: update default-collection-location test to use project path Use {{projectRoot}} template variable for defaultLocation so the path exists when the app validates it with fs.existsSync. Made-with: Cursor * fix: improve save test to use alternate path and verify persistence Made-with: Cursor --------- Co-authored-by: naman-bruno --- .../bruno-electron/src/ipc/preferences.js | 3 +- .../default-collection-location.spec.js | 34 +++++++++++++++---- .../init-user-data/preferences.json | 2 +- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/packages/bruno-electron/src/ipc/preferences.js b/packages/bruno-electron/src/ipc/preferences.js index 8ec2f0fd2..315baad1a 100644 --- a/packages/bruno-electron/src/ipc/preferences.js +++ b/packages/bruno-electron/src/ipc/preferences.js @@ -1,3 +1,4 @@ +const fs = require('fs'); const { ipcMain, nativeTheme } = require('electron'); const { getPreferences, savePreferences } = require('../store/preferences'); const { getGitVersion } = require('../utils/git'); @@ -20,7 +21,7 @@ const registerPreferencesIpc = (mainWindow) => { const preferences = getPreferences(); // Set the default location if it hasn't been set by the user - if (!preferences.general?.defaultLocation) { + if (!preferences.general?.defaultLocation || !fs.existsSync(preferences.general.defaultLocation)) { preferences.general ??= {}; preferences.general.defaultLocation = resolveDefaultLocation(); await savePreferences(preferences); diff --git a/tests/preferences/default-collection-location/default-collection-location.spec.js b/tests/preferences/default-collection-location/default-collection-location.spec.js index 352b027c1..842369389 100644 --- a/tests/preferences/default-collection-location/default-collection-location.spec.js +++ b/tests/preferences/default-collection-location/default-collection-location.spec.js @@ -1,5 +1,7 @@ import { test, expect } from '../../../playwright'; +const EXPECTED_PATH_SUFFIX = 'tests/preferences/default-collection-location'; + test.describe('Default Location Feature', () => { test('Should hydrate the default location from preferences', async ({ pageWithUserData: page }) => { // open preferences tab @@ -11,9 +13,10 @@ test.describe('Default Location Feature', () => { // navigate to General tab await page.getByRole('tab', { name: 'General' }).click(); - // verify the default location is pre-filled + // verify the default location is pre-filled with the expected path suffix const defaultLocationInput = page.locator('.default-location-input'); - await expect(defaultLocationInput).toHaveValue('/tmp/bruno-collections'); + const value = await defaultLocationInput.inputValue(); + expect(value.endsWith(EXPECTED_PATH_SUFFIX)).toBe(true); }); test('Should save a valid default location', async ({ pageWithUserData: page }) => { @@ -26,17 +29,34 @@ test.describe('Default Location Feature', () => { // navigate to General tab await page.getByRole('tab', { name: 'General' }).click(); - // set a default location (readonly input, remove readonly then fill) + // get the current default location and compute a different valid path const defaultLocationInput = page.locator('.default-location-input'); + const currentValue = await defaultLocationInput.inputValue(); + // Use parent directory as alternate path (guaranteed to exist and differ) + const alternateExistingPath = currentValue.split('/').slice(0, -1).join('/'); + + // set a different default location (readonly input, remove readonly then fill) await defaultLocationInput.evaluate((el) => { const input = el; input.removeAttribute('readonly'); input.readOnly = false; }); - await defaultLocationInput.fill('/tmp/bruno-collections'); + await defaultLocationInput.fill(alternateExistingPath); // wait for auto-save to complete (debounce is 500ms) await page.waitForTimeout(1000); + + // close preferences tab + await page.locator('.preferences-button').click(); + await page.waitForTimeout(300); + + // reopen preferences and verify persistence + await page.locator('.preferences-button').click(); + await page.waitForTimeout(500); + await page.getByRole('tab', { name: 'General' }).click(); + + const savedValue = await page.locator('.default-location-input').inputValue(); + expect(savedValue).toBe(alternateExistingPath); }); test('Should use default location in Create Collection modal', async ({ pageWithUserData: page }) => { @@ -58,8 +78,7 @@ test.describe('Default Location Feature', () => { await expect(collectionLocationInput).toBeVisible(); const inputValue = await collectionLocationInput.inputValue(); - - await expect(collectionLocationInput).toHaveValue('/tmp/bruno-collections', { timeout: 5000 }); + expect(inputValue.endsWith(EXPECTED_PATH_SUFFIX)).toBe(true); // cancel the collection creation await page.locator('.bruno-modal').getByRole('button', { name: 'Cancel' }).click(); @@ -79,7 +98,8 @@ test.describe('Default Location Feature', () => { // Scope to the modal to avoid conflict with preferences tab const cloneLocationInput = page.locator('.bruno-modal').getByLabel('Location', { exact: true }); await expect(cloneLocationInput).toBeVisible(); - await expect(cloneLocationInput).toHaveValue('/tmp/bruno-collections', { timeout: 5000 }); + const cloneValue = await cloneLocationInput.inputValue(); + expect(cloneValue.endsWith(EXPECTED_PATH_SUFFIX)).toBe(true); // cancel the clone operation await page.locator('.bruno-modal').getByRole('button', { name: 'Cancel' }).click(); diff --git a/tests/preferences/default-collection-location/init-user-data/preferences.json b/tests/preferences/default-collection-location/init-user-data/preferences.json index d2e9a7647..8e161910a 100644 --- a/tests/preferences/default-collection-location/init-user-data/preferences.json +++ b/tests/preferences/default-collection-location/init-user-data/preferences.json @@ -7,7 +7,7 @@ "hasSeenWelcomeModal": true }, "general": { - "defaultLocation": "/tmp/bruno-collections" + "defaultLocation": "{{projectRoot}}/tests/preferences/default-collection-location" } } }