chore(ui): the folder picker Tauri already had permission for
`tauri-plugin-dialog` has been registered in Rust since the shell was scaffolded and `dialog:allow-open` has been granted in `default.json` since then too — but `@tauri-apps/plugin-dialog` was never in `package.json`, so there was no JS binding to call. A permission with no way to exercise it, which is invisible until something tries. `pickProjectFolder` lives in `@/ipc` rather than in the component that calls it. `PdErrorRow` imports `plugin-opener` directly and that is fine, because `openUrl` is fire-and-forget and a test has nothing to assert about it. Here the return value *is* the interaction — which folder the user chose is what every screen test has to script — and TESTING §2 requires mocking at the typed wrapper layer. A component-level import would lint clean and be unmockable, which is the worst combination. `ipcMock` gains it, resolving to `null`: cancelled is the honest default, and a picker that silently produced a folder would let a test assert a run it never asked for. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
33e41f4a9f
commit
e4f1596d95
4 files changed
+40
No files matched your search
Generated
+10
@@ -12,6 +12,7 @@
|
||||
"@tanstack/react-virtual": "^3.14.9",
|
||||
"@tauri-apps/api": "^2.11.1",
|
||||
"@tauri-apps/plugin-clipboard-manager": "^2.3.2",
|
||||
"@tauri-apps/plugin-dialog": "^2.7.2",
|
||||
"@tauri-apps/plugin-opener": "^2.5.4",
|
||||
"i18next": "^26.3.6",
|
||||
"react": "^19.2.8",
|
||||
@@ -1649,6 +1650,15 @@
|
||||
"@tauri-apps/api": "^2.8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-dialog": {
|
||||
"version": "2.7.2",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-dialog/-/plugin-dialog-2.7.2.tgz",
|
||||
"integrity": "sha512-pX0IGm1I3I6wc+zeKYcq1GSqogK6okCNX5fOdaNU5ab1AjGS6l1E5wFNjEb7meg7ZFSp0JUs+0jQGQNyOvLrsg==",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"dependencies": {
|
||||
"@tauri-apps/api": "^2.11.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@tauri-apps/plugin-opener": {
|
||||
"version": "2.5.4",
|
||||
"resolved": "https://registry.npmjs.org/@tauri-apps/plugin-opener/-/plugin-opener-2.5.4.tgz",
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
"@tanstack/react-virtual": "^3.14.9",
|
||||
"@tauri-apps/api": "^2.11.1",
|
||||
"@tauri-apps/plugin-clipboard-manager": "^2.3.2",
|
||||
"@tauri-apps/plugin-dialog": "^2.7.2",
|
||||
"@tauri-apps/plugin-opener": "^2.5.4",
|
||||
"i18next": "^26.3.6",
|
||||
"react": "^19.2.8",
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
import { listen, type UnlistenFn } from '@tauri-apps/api/event'
|
||||
import { open } from '@tauri-apps/plugin-dialog'
|
||||
|
||||
import type {
|
||||
Decision,
|
||||
@@ -413,6 +414,30 @@ export const legalConsentGet = (): Promise<ConsentState> => invoke('legal_consen
|
||||
|
||||
export const legalConsentSet = (): Promise<Consent> => invoke('legal_consent_set')
|
||||
|
||||
/**
|
||||
* Ask the OS for a project folder. `null` when the user cancelled.
|
||||
*
|
||||
* **Here rather than in the component**, even though `PdErrorRow` imports `plugin-opener`
|
||||
* directly. The difference is the return value: `openUrl` is fire-and-forget and a test has
|
||||
* nothing to assert about it, whereas *which folder was chosen* is the whole interaction — and
|
||||
* TESTING §2 mocks at this layer. A component-level import would lint clean and be unmockable.
|
||||
*
|
||||
* `title` arrives already localized; `@/ipc` has no `t` and must not grow one.
|
||||
*/
|
||||
export const pickProjectFolder = async (
|
||||
title: string,
|
||||
defaultPath?: string,
|
||||
): Promise<string | null> => {
|
||||
const chosen = await open({
|
||||
directory: true,
|
||||
multiple: false,
|
||||
title,
|
||||
...(defaultPath === undefined ? {} : { defaultPath }),
|
||||
})
|
||||
// `open` widens to `string[] | string | null` for the multi-select case this never asks for.
|
||||
return typeof chosen === 'string' ? chosen : null
|
||||
}
|
||||
|
||||
/** Subscribe to discovery progress. Returns the unlisten function. */
|
||||
export const onScanProgress = (handler: (progress: ScanProgress) => void): Promise<UnlistenFn> =>
|
||||
listen<ScanProgress>('scan-progress', (event) => {
|
||||
|
||||
@@ -43,6 +43,7 @@ export interface IpcMock {
|
||||
pipUpgrade: ReturnType<typeof vi.fn>
|
||||
healthRun: ReturnType<typeof vi.fn>
|
||||
onHealthProgress: ReturnType<typeof vi.fn>
|
||||
pickProjectFolder: ReturnType<typeof vi.fn>
|
||||
isPdError: (value: unknown) => boolean
|
||||
}
|
||||
|
||||
@@ -72,6 +73,9 @@ export function ipcMock(): IpcMock {
|
||||
pipUpgrade: vi.fn().mockResolvedValue(undefined),
|
||||
healthRun: vi.fn(),
|
||||
onHealthProgress: vi.fn().mockResolvedValue(() => undefined),
|
||||
// Cancelled by default. A picker that silently returned a folder would let a test assert a
|
||||
// run it never actually asked for.
|
||||
pickProjectFolder: vi.fn().mockResolvedValue(null),
|
||||
// Real, not a spy: the stores decide whether a rejection carries a catalog code by asking it,
|
||||
// and a stub that always answered one way would make every error test agree with itself.
|
||||
isPdError: (value: unknown): boolean =>
|
||||
|
||||
Reference in new issue
Block a user