@@ -2,11 +2,17 @@ import { describe, expect, it, vi } from "vite-plus/test"; |
2 | 2 | import { page, userEvent } from "vite-plus/test/browser"; |
3 | 3 | import { DEFAULT_RESOLVED_KEYBINDINGS } from "@t3tools/shared/keybindings"; |
4 | 4 | import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings"; |
| 5 | +import { AuthOrchestrationOperateScope, AuthSourceControlWriteScope } from "@t3tools/contracts"; |
5 | 6 | import { act, render } from "../../test/render"; |
6 | 7 | import { CommandPalette } from "./CommandPalette"; |
7 | 8 | import { openCommandPalette } from "../commandPaletteBus"; |
8 | 9 | import { primaryServerKeybindingsAtom } from "../state/server"; |
9 | 10 |
|
| 11 | +const scopes = vi.hoisted(() => ({ denied: undefined as string | undefined })); |
| 12 | +const setup = (deniedScope?: string) => { |
| 13 | + scopes.denied = deniedScope; |
| 14 | +}; |
| 15 | + |
10 | 16 | vi.mock("@effect/atom-react", async (original) => ({ |
11 | 17 | ...(await original<typeof import("@effect/atom-react")>()), |
12 | 18 | useAtomValue: (atom: unknown) => |
@@ -85,7 +91,7 @@ vi.mock("../state/queries", async (original) => ({ |
85 | 91 | })); |
86 | 92 | vi.mock("../state/session", async (original) => ({ |
87 | 93 | ...(await original<typeof import("../state/session")>()), |
88 | | - useEnvironmentScope: () => true, |
| 94 | + useEnvironmentScope: (_environmentId: unknown, scope: string) => scope !== scopes.denied, |
89 | 95 | readEnvironmentScope: () => true, |
90 | 96 | })); |
91 | 97 | vi.mock("../state/filesystem", async (original) => ({ |
@@ -145,13 +151,31 @@ it.each([ |
145 | 151 | }, |
146 | 152 | { step: "repository", source: "Git URL", keys: "", description: /Continue.*Enter/ }, |
147 | 153 | { step: "new project", source: "New project", keys: "", description: /Create.*Enter/ }, |
148 | | -])("tells screen readers how to submit the $step step", async ({ source, keys, description }) => { |
149 | | - await using _screen = await render(<CommandPalette>{null}</CommandPalette>); |
150 | | - await act(() => openCommandPalette({ open: "add-project" })); |
151 | | - await page.getByText(source, { exact: true }).click(); |
152 | | - if (keys) await userEvent.keyboard(keys); |
153 | | - await expect.element(page.getByRole("combobox")).toHaveAccessibleDescription(description); |
154 | | -}); |
| 154 | + { |
| 155 | + step: "permission-blocked folder", |
| 156 | + source: "Local folder", |
| 157 | + keys: "", |
| 158 | + deniedScope: AuthOrchestrationOperateScope, |
| 159 | + description: "This connection cannot add projects.", |
| 160 | + }, |
| 161 | + { |
| 162 | + step: "permission-blocked destination", |
| 163 | + source: "Git URL", |
| 164 | + keys: "https://example.com/team/project.git{Enter}", |
| 165 | + deniedScope: AuthSourceControlWriteScope, |
| 166 | + description: "This connection needs permission to write source control and add projects.", |
| 167 | + }, |
| 168 | +])( |
| 169 | + "tells screen readers how to submit the $step step", |
| 170 | + async ({ source, keys, deniedScope, description }) => { |
| 171 | + setup(deniedScope); |
| 172 | + await using _screen = await render(<CommandPalette>{null}</CommandPalette>); |
| 173 | + await act(() => openCommandPalette({ open: "add-project" })); |
| 174 | + await page.getByText(source, { exact: true }).click(); |
| 175 | + if (keys) await userEvent.keyboard(keys); |
| 176 | + await expect.element(page.getByRole("combobox")).toHaveAccessibleDescription(description); |
| 177 | + }, |
| 178 | +); |
155 | 179 |
|
156 | 180 | it("keeps the caret in place when an edit briefly makes the folder path not a path", async () => { |
157 | 181 | await using _screen = await render(<CommandPalette>{null}</CommandPalette>); |
|