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 <naman@usebruno.com>
This commit is contained in:
gopu-bruno
2026-03-07 00:23:01 +05:30
committed by GitHub
parent 12ebfee9c6
commit 707fd405ff
3 changed files with 30 additions and 9 deletions

View File

@@ -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);

View File

@@ -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();

View File

@@ -7,7 +7,7 @@
"hasSeenWelcomeModal": true
},
"general": {
"defaultLocation": "/tmp/bruno-collections"
"defaultLocation": "{{projectRoot}}/tests/preferences/default-collection-location"
}
}
}