@@ -2,11 +2,17 @@ import { describe, expect, it, vi } from "vite-plus/test";
22import { page , userEvent } from "vite-plus/test/browser" ;
33import { DEFAULT_RESOLVED_KEYBINDINGS } from "@t3tools/shared/keybindings" ;
44import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings" ;
5+ import { AuthOrchestrationOperateScope , AuthSourceControlWriteScope } from "@t3tools/contracts" ;
56import { act , render } from "../../test/render" ;
67import { CommandPalette } from "./CommandPalette" ;
78import { openCommandPalette } from "../commandPaletteBus" ;
89import { primaryServerKeybindingsAtom } from "../state/server" ;
910
11+ const scopes = vi . hoisted ( ( ) => ( { denied : undefined as string | undefined } ) ) ;
12+ const setup = ( deniedScope ?: string ) => {
13+ scopes . denied = deniedScope ;
14+ } ;
15+
1016vi . mock ( "@effect/atom-react" , async ( original ) => ( {
1117 ...( await original < typeof import ( "@effect/atom-react" ) > ( ) ) ,
1218 useAtomValue : ( atom : unknown ) =>
@@ -85,7 +91,7 @@ vi.mock("../state/queries", async (original) => ({
8591} ) ) ;
8692vi . mock ( "../state/session" , async ( original ) => ( {
8793 ...( await original < typeof import ( "../state/session" ) > ( ) ) ,
88- useEnvironmentScope : ( ) => true ,
94+ useEnvironmentScope : ( _environmentId : unknown , scope : string ) => scope !== scopes . denied ,
8995 readEnvironmentScope : ( ) => true ,
9096} ) ) ;
9197vi . mock ( "../state/filesystem" , async ( original ) => ( {
@@ -106,6 +112,7 @@ describe.each(["repository", "folder", "destination"] as const)("add-project %s"
106112 { isComposing : true , keyCode : 13 } ,
107113 { isComposing : false , keyCode : 229 } ,
108114 ] ) ( "keeps Enter in the input during composition: %j" , async ( composition ) => {
115+ setup ( ) ;
109116 await using _screen = await render ( < CommandPalette > { null } </ CommandPalette > ) ;
110117 await act ( ( ) => openCommandPalette ( { open : "add-project" } ) ) ;
111118 await page . getByText ( step === "folder" ? "Local folder" : "Git URL" , { exact : true } ) . click ( ) ;
@@ -135,7 +142,44 @@ describe.each(["repository", "folder", "destination"] as const)("add-project %s"
135142 } ) ;
136143} ) ;
137144
145+ it . each ( [
146+ { step : "folder" , source : "Local folder" , keys : "" , description : / ^ (? ! .* ( C t r l | ⌘ ) ) .* A d d .* E n t e r / } ,
147+ {
148+ step : "highlighted folder" ,
149+ source : "Local folder" ,
150+ keys : "{ArrowDown}" ,
151+ description : / A d d .* ( C t r l | ⌘ ) E n t e r / ,
152+ } ,
153+ { step : "repository" , source : "Git URL" , keys : "" , description : / C o n t i n u e .* E n t e r / } ,
154+ { step : "new project" , source : "New project" , keys : "" , description : / C r e a t e .* E n t e r / } ,
155+ {
156+ step : "permission-blocked folder" ,
157+ source : "Local folder" ,
158+ keys : "" ,
159+ deniedScope : AuthOrchestrationOperateScope ,
160+ description : "This connection cannot add projects." ,
161+ } ,
162+ {
163+ step : "permission-blocked destination" ,
164+ source : "Git URL" ,
165+ keys : "https://example.com/team/project.git{Enter}" ,
166+ deniedScope : AuthSourceControlWriteScope ,
167+ description : "This connection needs permission to write source control and add projects." ,
168+ } ,
169+ ] ) (
170+ "tells screen readers how to submit the $step step" ,
171+ async ( { source, keys, deniedScope, description } ) => {
172+ setup ( deniedScope ) ;
173+ await using _screen = await render ( < CommandPalette > { null } </ CommandPalette > ) ;
174+ await act ( ( ) => openCommandPalette ( { open : "add-project" } ) ) ;
175+ await page . getByText ( source , { exact : true } ) . click ( ) ;
176+ if ( keys ) await userEvent . keyboard ( keys ) ;
177+ await expect . element ( page . getByRole ( "combobox" ) ) . toHaveAccessibleDescription ( description ) ;
178+ } ,
179+ ) ;
180+
138181it ( "keeps the caret in place when an edit briefly makes the folder path not a path" , async ( ) => {
182+ setup ( ) ;
139183 await using _screen = await render ( < CommandPalette > { null } </ CommandPalette > ) ;
140184 await act ( ( ) => openCommandPalette ( { open : "add-project" } ) ) ;
141185 await page . getByText ( "Local folder" , { exact : true } ) . click ( ) ;
0 commit comments