@bevel-software/platform-core-frontend 0.20.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/core/registry.ts +57 -0
- package/src/modules/access/__tests__/ManageAccessDialog.request.test.tsx +376 -0
- package/src/modules/access/components/AccessRequestControl.tsx +155 -0
- package/src/modules/{library → access}/components/AccessRequestsBanner.tsx +62 -24
- package/src/modules/access/components/ManageAccessDialog.tsx +81 -4
- package/src/modules/access/hooks/useAccessRequests.ts +183 -0
- package/src/modules/access/hooks/useFileAccess.ts +2 -2
- package/src/modules/access/requests.api.ts +121 -0
- package/src/modules/auth/components/LoginScreen.tsx +6 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +171 -38
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +34 -19
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +173 -6
- package/src/modules/change-requests/components/ChangeRequestDialog.tsx +155 -98
- package/src/modules/git/components/BranchSwitcher.tsx +9 -3
- package/src/modules/git/components/FileComparisonPanel.tsx +10 -4
- package/src/modules/git/components/PullNeededBanner.tsx +2 -2
- package/src/modules/git/services/error-messages.ts +2 -2
- package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +110 -9
- package/src/modules/layout/components/SidebarFrame.tsx +26 -9
- package/src/modules/library/__tests__/DeleteToolDialog.test.tsx +11 -0
- package/src/modules/library/__tests__/LibraryRoutes.test.tsx +3 -0
- package/src/modules/library/__tests__/PluginIndexRow.test.tsx +146 -0
- package/src/modules/library/__tests__/PluginPage.test.tsx +110 -3
- package/src/modules/library/__tests__/SkillPage.test.tsx +15 -0
- package/src/modules/library/__tests__/ToolPage.test.tsx +34 -0
- package/src/modules/library/__tests__/name-with-badges.test.tsx +16 -3
- package/src/modules/library/__tests__/title-row-actions.ts +95 -0
- package/src/modules/library/components/PluginIndexRow.tsx +37 -20
- package/src/modules/library/components/PluginJoinRequests.tsx +2 -2
- package/src/modules/library/components/PluginPage.tsx +115 -3
- package/src/modules/library/components/skill-page/SkillPage.tsx +2 -2
- package/src/modules/library/components/tool-page/ToolPage.tsx +36 -18
- package/src/modules/library/hooks/useJoinRequests.ts +26 -101
- package/src/modules/library/routes/library-paths.ts +9 -2
- package/src/modules/library/services/plugins.api.ts +45 -0
- package/src/modules/library/utils/plugin-summary.ts +7 -2
- package/src/modules/onboarding/__tests__/onboarding.test.tsx +43 -0
- package/src/modules/onboarding/components/ConnectAgentPill.tsx +13 -2
- package/src/modules/pr/components/OpenChangeRequestDialog.tsx +3 -2
- package/src/modules/pr/services/pr-merge.api.ts +10 -2
- package/src/modules/review/components/ReviewPanel.tsx +2 -2
- package/src/modules/settings/components/DeploymentPage.tsx +22 -0
- package/src/modules/settings/components/__tests__/DeploymentPage.test.tsx +72 -4
- package/src/modules/setup/__tests__/setup.first-run.test.tsx +276 -0
- package/src/modules/setup/__tests__/setup.github.test.tsx +416 -0
- package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +275 -0
- package/src/modules/setup/__tests__/setup.repository.test.tsx +373 -0
- package/src/modules/setup/__tests__/setup.test.tsx +8 -14
- package/src/modules/setup/components/GitHubRepositoryPanel.tsx +369 -0
- package/src/modules/setup/components/SetupGate.tsx +1 -0
- package/src/modules/setup/components/SetupScreen.tsx +464 -38
- package/src/modules/setup/services/setup.api.ts +93 -0
- package/src/modules/setup/utils/kept-draft.ts +86 -0
- package/src/modules/workspace/components/FileExplorer.tsx +4 -2
- package/src/modules/workspace/components/FileViewer.tsx +8 -3
- package/src/modules/workspace/components/KbDocumentShell.tsx +50 -8
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +49 -0
- package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +49 -1
- package/src/modules/workspace/hooks/useWorkspaceState.ts +7 -2
- package/src/modules/workspace/utils/fileTree.ts +2 -1
- package/src/modules/workspace/utils/treeConfirm.ts +7 -3
- package/src/shared/components/SlotBoundary.tsx +51 -0
- package/src/shared/theme/measure.ts +23 -2
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_BRANCH,
|
|
3
|
+
PLUGINS_DIR,
|
|
4
|
+
SKILLS_DIR,
|
|
5
|
+
currentKbLayout,
|
|
6
|
+
pluginOfPath,
|
|
7
|
+
isPersonalPluginFolder,
|
|
8
|
+
} from '@bevel-software/platform-shared';
|
|
2
9
|
import { matchPath } from 'react-router-dom';
|
|
3
10
|
import { kbFileUrl } from '../../workspace/routing/kb-routes';
|
|
4
11
|
import type { LibraryFilter } from '../utils/status';
|
|
@@ -218,7 +225,7 @@ export function libraryHomeForItemPath(
|
|
|
218
225
|
label: string;
|
|
219
226
|
path: string;
|
|
220
227
|
} {
|
|
221
|
-
const folder = pluginOfPath(repoRelativePath);
|
|
228
|
+
const folder = pluginOfPath(repoRelativePath, currentKbLayout());
|
|
222
229
|
// A personal shelf is decided by the FOLDER, whatever identity the caller
|
|
223
230
|
// resolved (a personal item's identity is null: a shelf is not a plugin).
|
|
224
231
|
if (folder !== null && isPersonalPluginFolder(folder)) {
|
|
@@ -247,6 +247,51 @@ export async function repairSkillLink(plugin: string, skillPath: string): Promis
|
|
|
247
247
|
});
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
+
/** Who may edit a skill root's access file — who can repair its link. */
|
|
251
|
+
export interface LinkEditors {
|
|
252
|
+
roles: string[];
|
|
253
|
+
users: { name: string; email: string }[];
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** One link the page-open repair left alone, and why — mirrors the backend. */
|
|
257
|
+
export interface UnrepairedLink {
|
|
258
|
+
/** Repo-relative root, as the plugin's manifest declares it. */
|
|
259
|
+
root: string;
|
|
260
|
+
/**
|
|
261
|
+
* `needs-skill-write` — the viewer may not write its access file; `failed`
|
|
262
|
+
* — the write did not land; `denied` — the lines are there and a `deny` of
|
|
263
|
+
* the plugin beside them keeps the link broken, so there is nothing to
|
|
264
|
+
* write and only an editor removing the deny would change it.
|
|
265
|
+
*/
|
|
266
|
+
reason: 'needs-skill-write' | 'failed' | 'denied';
|
|
267
|
+
/** The skills the plugin's members still cannot read through it. */
|
|
268
|
+
skills: { path: string; name: string }[];
|
|
269
|
+
/** Who the banner names as able to repair it. */
|
|
270
|
+
editors: LinkEditors;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** What one page-open repair did, and what is still broken. */
|
|
274
|
+
export interface LinkRepairReport {
|
|
275
|
+
repaired: string[];
|
|
276
|
+
skipped: UnrepairedLink[];
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Repair every link of a plugin whose grants are missing — what the plugin
|
|
281
|
+
* page runs, once, on open, for someone who may write the plugin.
|
|
282
|
+
*
|
|
283
|
+
* Silent by design: a repaired link shows nothing, so the only thing the
|
|
284
|
+
* caller does with `repaired` is reload the catalog. `skipped` is the banner.
|
|
285
|
+
* Refused with the ordinary 404 for a caller who may not write the plugin,
|
|
286
|
+
* which is why the page asks only when its summary says they can.
|
|
287
|
+
*/
|
|
288
|
+
export async function repairPluginLinks(plugin: string): Promise<LinkRepairReport> {
|
|
289
|
+
const body = await linkCall(`/api/plugins/${encodeURIComponent(plugin)}/links/repair-all`, {
|
|
290
|
+
method: 'POST',
|
|
291
|
+
});
|
|
292
|
+
return body as unknown as LinkRepairReport;
|
|
293
|
+
}
|
|
294
|
+
|
|
250
295
|
/**
|
|
251
296
|
* Thrown when a join request is refused because access already landed —
|
|
252
297
|
* between the page load and the click. Not an error to show: the right
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
currentKbLayout,
|
|
3
|
+
isPersonalPluginFolder,
|
|
4
|
+
pluginOfPath,
|
|
5
|
+
skillUnderRoot,
|
|
6
|
+
} from '@bevel-software/platform-shared';
|
|
2
7
|
import type { PluginMembership } from '../services/library.api';
|
|
3
8
|
import type { PluginPrincipals, PluginSummary } from '../services/plugins.api';
|
|
4
9
|
|
|
@@ -14,7 +19,7 @@ export function pluginNameForPath(
|
|
|
14
19
|
repoPath: string,
|
|
15
20
|
summaries: readonly Pick<PluginSummary, 'name' | 'folders'>[],
|
|
16
21
|
): string | null {
|
|
17
|
-
const folder = pluginOfPath(repoPath);
|
|
22
|
+
const folder = pluginOfPath(repoPath, currentKbLayout());
|
|
18
23
|
if (folder === null) return null;
|
|
19
24
|
// The catalog is the authority: whatever folder it lists as holding the
|
|
20
25
|
// path names the plugin. Only a path no listed folder holds falls back to
|
|
@@ -14,6 +14,8 @@ import { WELCOME_PATH } from '../paths';
|
|
|
14
14
|
import { resetOnboardingForTests } from '../state/onboarding';
|
|
15
15
|
import { configureMcpUrl } from '../../../shared/mcp';
|
|
16
16
|
import { setSidebarCollapsed, useSidebar } from '../../layout/state/sidebar';
|
|
17
|
+
import { SidebarFrame } from '../../layout/components/SidebarFrame';
|
|
18
|
+
import { SIDEBAR_HEADER_TESTID } from '../../../shared/theme/header';
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
21
|
* The onboarding contract, end to end on the client:
|
|
@@ -835,6 +837,47 @@ describe('ConnectAgentPill', () => {
|
|
|
835
837
|
expect(JSON.parse(String(fetchInit()?.body))).toEqual({ userId: 'u1' });
|
|
836
838
|
});
|
|
837
839
|
|
|
840
|
+
/**
|
|
841
|
+
* The pill fills `SidebarFrame`'s header band, which is spent on a header
|
|
842
|
+
* that DRAWS and collapses (`empty:hidden`) for one that does not. "Does
|
|
843
|
+
* not" is read off the DOM — an element that renders null is still an
|
|
844
|
+
* element — so a pill with nothing to say has to leave the row literally
|
|
845
|
+
* empty, and its dismissal receipt goes to the body rather than sitting in
|
|
846
|
+
* the band invisibly holding 48px open above "Company Context".
|
|
847
|
+
*
|
|
848
|
+
* Both halves in one test on purpose: an empty row that had lost the
|
|
849
|
+
* announcement with it would pass the first assertion and be a regression.
|
|
850
|
+
*/
|
|
851
|
+
it('leaves the header band empty once onboarding is done, and still says so out loud', async () => {
|
|
852
|
+
mount(
|
|
853
|
+
<SidebarFrame label="Library navigation" header={<ConnectAgentPill />}>
|
|
854
|
+
<nav>Company Context</nav>
|
|
855
|
+
</SidebarFrame>,
|
|
856
|
+
newUser(),
|
|
857
|
+
'/skills-and-tools',
|
|
858
|
+
);
|
|
859
|
+
const band = screen.getByTestId(SIDEBAR_HEADER_TESTID);
|
|
860
|
+
expect(band).not.toBeEmptyDOMElement();
|
|
861
|
+
|
|
862
|
+
await userEvent.click(screen.getByRole('button', { name: /^Dismiss/ }));
|
|
863
|
+
|
|
864
|
+
expect(band).toBeEmptyDOMElement();
|
|
865
|
+
expect(
|
|
866
|
+
screen.getAllByRole('status').some((r) => /Reminder dismissed/.test(r.textContent ?? '')),
|
|
867
|
+
).toBe(true);
|
|
868
|
+
});
|
|
869
|
+
|
|
870
|
+
it('leaves it empty for an account that was already done', () => {
|
|
871
|
+
mount(
|
|
872
|
+
<SidebarFrame label="Library navigation" header={<ConnectAgentPill />}>
|
|
873
|
+
<nav>Company Context</nav>
|
|
874
|
+
</SidebarFrame>,
|
|
875
|
+
doneUser(),
|
|
876
|
+
'/skills-and-tools',
|
|
877
|
+
);
|
|
878
|
+
expect(screen.getByTestId(SIDEBAR_HEADER_TESTID)).toBeEmptyDOMElement();
|
|
879
|
+
});
|
|
880
|
+
|
|
838
881
|
/**
|
|
839
882
|
* A write that never landed must not leave the UI claiming it did. The pill
|
|
840
883
|
* comes back immediately, rather than mysteriously reappearing at the next
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
|
+
import { createPortal } from 'react-dom';
|
|
2
3
|
import { useInRouterContext, useLocation, useNavigate } from 'react-router-dom';
|
|
3
4
|
import { X } from 'lucide-react';
|
|
4
5
|
import { cn } from '../../../lib/utils';
|
|
@@ -71,11 +72,21 @@ function RoutedConnectAgentPill() {
|
|
|
71
72
|
// The live region is OUTSIDE the `showPill` guard so it is still mounted at
|
|
72
73
|
// the moment the pill disappears — a region that unmounts in the same commit
|
|
73
74
|
// as the thing it is announcing announces nothing.
|
|
75
|
+
//
|
|
76
|
+
// It goes to the BODY, though, not into the slot this component fills. That
|
|
77
|
+
// slot is `SidebarFrame`'s header band, which reserves its 48px for a header
|
|
78
|
+
// that draws and collapses (`empty:hidden`) for one that does not — and an
|
|
79
|
+
// `sr-only` span is a child like any other, so leaving it here would hold
|
|
80
|
+
// the whole band open, invisibly, for every account that has finished
|
|
81
|
+
// onboarding. That is precisely the empty strip above "Company Context"
|
|
82
|
+
// this file's half of the fix removes. A portal keeps the region mounted,
|
|
83
|
+
// keeps the announcement, and leaves the row with nothing in it.
|
|
74
84
|
if (!onboarding.showPill) {
|
|
75
|
-
return (
|
|
85
|
+
return createPortal(
|
|
76
86
|
<span role="status" aria-live="polite" className="sr-only">
|
|
77
87
|
{announcement}
|
|
78
|
-
</span
|
|
88
|
+
</span>,
|
|
89
|
+
document.body,
|
|
79
90
|
);
|
|
80
91
|
}
|
|
81
92
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import {
|
|
3
3
|
DEFAULT_BRANCH,
|
|
4
|
+
currentBranchModel,
|
|
4
5
|
protectedBranchDisplayName,
|
|
5
6
|
} from '@bevel-software/platform-shared';
|
|
6
7
|
import { Dialog } from '../../../shared/components/Dialog';
|
|
@@ -170,12 +171,12 @@ export function OpenChangeRequestDialog({
|
|
|
170
171
|
>
|
|
171
172
|
{targets.length === 0 && (
|
|
172
173
|
<option value={targetBranch}>
|
|
173
|
-
{protectedBranchDisplayName(targetBranch) ?? targetBranch}
|
|
174
|
+
{protectedBranchDisplayName(currentBranchModel(), targetBranch) ?? targetBranch}
|
|
174
175
|
</option>
|
|
175
176
|
)}
|
|
176
177
|
{targets.map((b) => (
|
|
177
178
|
<option key={b.name} value={b.name}>
|
|
178
|
-
{protectedBranchDisplayName(b.name) ?? b.name}
|
|
179
|
+
{protectedBranchDisplayName(currentBranchModel(), b.name) ?? b.name}
|
|
179
180
|
{b.name === DEFAULT_BRANCH ? ' (default)' : ''}
|
|
180
181
|
</option>
|
|
181
182
|
))}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ChangeRequestUpdateResult } from '@bevel-software/platform-shared';
|
|
1
2
|
import { authFetch } from '../../../lib/api';
|
|
2
3
|
import { handleApiResponse } from '../../git/services/git.api';
|
|
3
4
|
|
|
@@ -42,9 +43,16 @@ export async function mergePullRequest(
|
|
|
42
43
|
* `change-request-conflicts` error payload (status 409) listing the
|
|
43
44
|
* conflicting paths — the caller catches it via `GitApiError` and
|
|
44
45
|
* routes the agent into the resolution flow.
|
|
46
|
+
*
|
|
47
|
+
* Answers the refreshed detail itself, plus `updatedPaths` — which files the
|
|
48
|
+
* merge changed on the branch. A caller that is already showing the request's
|
|
49
|
+
* files replaces exactly those, and needs no further detail read: this one was
|
|
50
|
+
* assembled after the merge, with the carried approvals in it.
|
|
45
51
|
*/
|
|
46
|
-
export async function refreshChangeRequestFromTarget(
|
|
47
|
-
|
|
52
|
+
export async function refreshChangeRequestFromTarget(
|
|
53
|
+
prNumber: number,
|
|
54
|
+
): Promise<ChangeRequestUpdateResult> {
|
|
55
|
+
return handleApiResponse<ChangeRequestUpdateResult>(
|
|
48
56
|
await authFetch(`/api/workflow/change-requests/${prNumber}/update-from-target`, {
|
|
49
57
|
method: 'POST',
|
|
50
58
|
headers: { 'Content-Type': 'application/json' },
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
stripJunkBeforeKbDir,
|
|
10
10
|
} from '../../workspace/routing/kb-routes';
|
|
11
11
|
import { useWorkspaceImageResolver } from '../../workspace/hooks/useWorkspaceImageResolver';
|
|
12
|
-
import { pluginOfPath, DEFAULT_BRANCH } from '@bevel-software/platform-shared';
|
|
12
|
+
import { pluginOfPath, currentKbLayout, DEFAULT_BRANCH } from '@bevel-software/platform-shared';
|
|
13
13
|
import { cn } from '../../../lib/utils';
|
|
14
14
|
import { DOCUMENT_COLUMN, documentGutters } from '../../../shared/theme/measure';
|
|
15
15
|
import { ReviewFileRow } from './ReviewFileRow';
|
|
@@ -43,7 +43,7 @@ export function isPluginItemPath(path: string, kbDirName: string | null): boolea
|
|
|
43
43
|
kbDirName && withoutJunk.startsWith(`${kbDirName}/`)
|
|
44
44
|
? withoutJunk.slice(kbDirName.length + 1)
|
|
45
45
|
: withoutJunk;
|
|
46
|
-
return pluginOfPath(repoRelative) !== null;
|
|
46
|
+
return pluginOfPath(repoRelative, currentKbLayout()) !== null;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/**
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { PageShell } from '../../../shared/components/PageShell';
|
|
2
2
|
import { Banner, Button } from '../../../shared/components';
|
|
3
|
+
import { SlotBoundary } from '../../../shared/components/SlotBoundary';
|
|
3
4
|
import { useAdmin } from '../../admin/state/admin.context';
|
|
4
5
|
import { useSetupStatus } from '../../setup/hooks/useSetupStatus';
|
|
5
6
|
import { SetupScreen } from '../../setup/components/SetupScreen';
|
|
7
|
+
import { useAppRegistry } from '../../../core/registry';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Deployment settings, routed at `/deployment` — the first-run setup screen
|
|
@@ -27,6 +29,8 @@ import { SetupScreen } from '../../setup/components/SetupScreen';
|
|
|
27
29
|
*/
|
|
28
30
|
export function DeploymentPage() {
|
|
29
31
|
const { isAdmin } = useAdmin();
|
|
32
|
+
// What the distribution adds to this page, if anything — see the slot.
|
|
33
|
+
const { deploymentPanel: DeploymentPanel } = useAppRegistry();
|
|
30
34
|
// Read the shared way (`useSetupStatus`: latest read wins, a failed read
|
|
31
35
|
// keeps the last status). Non-admins never read: the endpoint would answer
|
|
32
36
|
// them safely (status without settings), but this page has already told them
|
|
@@ -73,12 +77,30 @@ export function DeploymentPage() {
|
|
|
73
77
|
settings={status.settings}
|
|
74
78
|
sync={status.sync}
|
|
75
79
|
oidcVerification={status.oidcVerification}
|
|
80
|
+
repository={status.repository}
|
|
76
81
|
kbInit={status.kbInit}
|
|
77
82
|
onSaved={refresh}
|
|
78
83
|
variant="settings"
|
|
79
84
|
/>
|
|
80
85
|
</div>
|
|
81
86
|
)}
|
|
87
|
+
|
|
88
|
+
{/* The distribution's panel, last on the page and outside every
|
|
89
|
+
condition above: it does not depend on the settings, so neither a
|
|
90
|
+
load in flight nor a failed one takes it away.
|
|
91
|
+
|
|
92
|
+
And the other way round: the panel is code core did not write, so
|
|
93
|
+
it renders inside a boundary. A throw in it costs its own place on
|
|
94
|
+
the page and not the form above — the form is where an admin fixes
|
|
95
|
+
the sign-in or the repository connection, and must not go down with
|
|
96
|
+
a panel it has nothing to do with. */}
|
|
97
|
+
{DeploymentPanel && (
|
|
98
|
+
<div className="mt-10" data-testid="deployment-panel">
|
|
99
|
+
<SlotBoundary label="workspace panel">
|
|
100
|
+
<DeploymentPanel />
|
|
101
|
+
</SlotBoundary>
|
|
102
|
+
</div>
|
|
103
|
+
)}
|
|
82
104
|
</PageShell>
|
|
83
105
|
);
|
|
84
106
|
}
|
|
@@ -2,6 +2,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
|
2
2
|
import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';
|
|
3
3
|
import { AdminContext, type AdminContextValue } from '../../../admin/state/admin.context';
|
|
4
4
|
import { KbInitFailed } from '../../../setup/services/setup.api';
|
|
5
|
+
import { AppRegistryContext, EMPTY_REGISTRY, type AppRegistry } from '../../../../core/registry';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* The deployment settings page — first-run setup with a permanent address.
|
|
@@ -50,14 +51,22 @@ const COMPLETE_STATUS = {
|
|
|
50
51
|
],
|
|
51
52
|
};
|
|
52
53
|
|
|
53
|
-
function renderPage(value: AdminContextValue) {
|
|
54
|
+
function renderPage(value: AdminContextValue, registry: AppRegistry = EMPTY_REGISTRY) {
|
|
54
55
|
return render(
|
|
55
|
-
<
|
|
56
|
-
<
|
|
57
|
-
|
|
56
|
+
<AppRegistryContext.Provider value={registry}>
|
|
57
|
+
<AdminContext.Provider value={value}>
|
|
58
|
+
<DeploymentPage />
|
|
59
|
+
</AdminContext.Provider>
|
|
60
|
+
</AppRegistryContext.Provider>,
|
|
58
61
|
);
|
|
59
62
|
}
|
|
60
63
|
|
|
64
|
+
/** What a distribution would put at the foot of the page. */
|
|
65
|
+
function WorkspacePanel() {
|
|
66
|
+
return <section aria-label="Workspace">Delete this workspace</section>;
|
|
67
|
+
}
|
|
68
|
+
const WITH_PANEL: AppRegistry = { ...EMPTY_REGISTRY, deploymentPanel: WorkspacePanel };
|
|
69
|
+
|
|
61
70
|
describe('DeploymentPage', () => {
|
|
62
71
|
beforeEach(() => {
|
|
63
72
|
apiMock.fetchSetupStatus.mockReset();
|
|
@@ -110,6 +119,65 @@ describe('DeploymentPage', () => {
|
|
|
110
119
|
expect(facadeMock.fetchGitHubFacade).not.toHaveBeenCalled();
|
|
111
120
|
});
|
|
112
121
|
|
|
122
|
+
/**
|
|
123
|
+
* The distribution's slot: what a deployment is beyond its settings (a
|
|
124
|
+
* hosted workspace's plan, its deletion) is not core's to know, so the page
|
|
125
|
+
* gives it a place and nothing more.
|
|
126
|
+
*/
|
|
127
|
+
it('renders the distribution panel last on the page, after the form and its save button', async () => {
|
|
128
|
+
renderPage(admin(true), WITH_PANEL);
|
|
129
|
+
const panel = await screen.findByRole('region', { name: 'Workspace' });
|
|
130
|
+
const save = await screen.findByRole('button', { name: 'Save and continue' });
|
|
131
|
+
expect(save.compareDocumentPosition(panel) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
|
132
|
+
expect(screen.getByTestId('deployment-panel')).toContainElement(panel);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('keeps the distribution panel when the settings cannot be loaded', async () => {
|
|
136
|
+
apiMock.fetchSetupStatus.mockRejectedValueOnce(new Error('down'));
|
|
137
|
+
renderPage(admin(true), WITH_PANEL);
|
|
138
|
+
expect(await screen.findByText(/Couldn't load the deployment settings/)).toBeInTheDocument();
|
|
139
|
+
// A way out of the deployment must not depend on its settings being readable.
|
|
140
|
+
expect(screen.getByRole('region', { name: 'Workspace' })).toBeInTheDocument();
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('shows the distribution panel to admins only, and nothing in its place without one', async () => {
|
|
144
|
+
renderPage(admin(false), WITH_PANEL);
|
|
145
|
+
expect(screen.getByText(/Admins only/)).toBeInTheDocument();
|
|
146
|
+
expect(screen.queryByRole('region', { name: 'Workspace' })).toBeNull();
|
|
147
|
+
expect(screen.queryByTestId('deployment-panel')).toBeNull();
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('ends with the form when no distribution panel is registered', async () => {
|
|
151
|
+
renderPage(admin(true));
|
|
152
|
+
await screen.findByText('Provider address');
|
|
153
|
+
expect(screen.queryByTestId('deployment-panel')).toBeNull();
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* The other direction of the same independence: the panel is code core did
|
|
158
|
+
* not write, and a throw in it must cost the panel's own place, not the
|
|
159
|
+
* form an admin came here to use.
|
|
160
|
+
*/
|
|
161
|
+
it('keeps the settings form when the distribution panel throws, and says so in its place', async () => {
|
|
162
|
+
function BrokenPanel(): never {
|
|
163
|
+
throw new Error('the distribution has a bug');
|
|
164
|
+
}
|
|
165
|
+
// React reports a caught render error on the console, and so does the
|
|
166
|
+
// boundary; both are expected here and neither belongs in the run's output.
|
|
167
|
+
const quiet = vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
168
|
+
try {
|
|
169
|
+
renderPage(admin(true), { ...EMPTY_REGISTRY, deploymentPanel: BrokenPanel });
|
|
170
|
+
expect(await screen.findByText('Provider address')).toBeInTheDocument();
|
|
171
|
+
expect(screen.getByRole('button', { name: 'Save and continue' })).toBeInTheDocument();
|
|
172
|
+
const slot = screen.getByTestId('deployment-panel');
|
|
173
|
+
expect(slot).toHaveTextContent(/workspace panel couldn.t be shown/);
|
|
174
|
+
expect(slot).toHaveTextContent(/rest of this page is unaffected/);
|
|
175
|
+
expect(quiet).toHaveBeenCalled();
|
|
176
|
+
} finally {
|
|
177
|
+
quiet.mockRestore();
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
|
|
113
181
|
it('tells a non-admin this is not theirs, and never fetches the settings', () => {
|
|
114
182
|
renderPage(admin(false));
|
|
115
183
|
expect(screen.getByText(/Admins only/)).toBeInTheDocument();
|