@bevel-software/platform-core-frontend 0.9.1 → 0.11.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/CoreAppShell.tsx +6 -0
- package/src/core/__tests__/AppChrome.test.tsx +3 -0
- package/src/core/registry.ts +25 -0
- package/src/lib/email.ts +25 -0
- package/src/modules/access/__tests__/ManageAccessDialog.placement.test.tsx +1 -1
- package/src/modules/access/__tests__/ManageAccessDialog.test.tsx +280 -4
- package/src/modules/access/api.ts +47 -13
- package/src/modules/access/components/ManageAccessDialog.tsx +119 -49
- package/src/modules/admin/__tests__/AdminRolesPage.capabilities.test.tsx +281 -0
- package/src/modules/admin/__tests__/AdminRolesPage.suggest.test.tsx +4 -4
- package/src/modules/admin/__tests__/DirectoryGroupsPage.test.tsx +438 -0
- package/src/modules/admin/components/AdminRolesPage.tsx +203 -411
- package/src/modules/admin/components/DirectoryGroupsPage.tsx +610 -0
- package/src/modules/admin/hooks/useExclusiveRunner.ts +27 -0
- package/src/modules/admin/services/groups.api.ts +151 -0
- package/src/modules/admin/services/roles.api.ts +57 -31
- package/src/modules/library/__tests__/LibraryRoutes.test.tsx +42 -3
- package/src/modules/library/__tests__/PluginPage.test.tsx +29 -0
- package/src/modules/library/__tests__/ToolPage.test.tsx +22 -0
- package/src/modules/library/__tests__/WorkspaceItemRoute.test.tsx +90 -0
- package/src/modules/library/components/LibraryPage.tsx +2 -2
- package/src/modules/library/components/PersonalPluginPage.tsx +2 -2
- package/src/modules/library/components/PluginPage.tsx +2 -2
- package/src/modules/library/components/tool-page/ToolPage.tsx +7 -1
- package/src/modules/library/routes/LibraryRoutes.tsx +6 -4
- package/src/modules/library/routes/WorkspaceItemRoute.tsx +33 -5
- package/src/modules/library/routes/library-paths.ts +30 -0
- package/src/modules/onboarding/__tests__/onboarding.test.tsx +63 -17
- package/src/modules/onboarding/agent-clients.ts +21 -7
- package/src/modules/onboarding/components/WelcomePage.tsx +1 -1
- package/src/modules/settings/settings-nav-items.tsx +9 -1
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +135 -20
- package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +113 -14
- package/src/modules/update-check/__tests__/UpdateBanner.test.tsx +126 -0
- package/src/modules/update-check/components/UpdateBanner.tsx +92 -0
- package/src/modules/update-check/services/update-check.api.ts +24 -0
- package/src/shared/mcp/__tests__/connect-snippets.test.ts +66 -0
- package/src/shared/mcp/connect-snippets.ts +76 -0
- package/src/shared/mcp/index.ts +3 -0
|
@@ -13,9 +13,6 @@ vi.mock('../services/roles.api', async (importOriginal) => {
|
|
|
13
13
|
fetchRoles: vi.fn(),
|
|
14
14
|
addMember: vi.fn(),
|
|
15
15
|
removeMember: vi.fn(),
|
|
16
|
-
createRole: vi.fn(),
|
|
17
|
-
deleteRole: vi.fn(),
|
|
18
|
-
renameRole: vi.fn(),
|
|
19
16
|
};
|
|
20
17
|
});
|
|
21
18
|
vi.mock('../../access/api', async (importOriginal) => {
|
|
@@ -27,6 +24,8 @@ const ENGINEERING: RoleRosterEntry = {
|
|
|
27
24
|
canonical: 'engineering',
|
|
28
25
|
displayName: 'Engineering',
|
|
29
26
|
members: [],
|
|
27
|
+
groups: [],
|
|
28
|
+
capability: null,
|
|
30
29
|
isAdmin: false,
|
|
31
30
|
referencedBy: [],
|
|
32
31
|
};
|
|
@@ -55,7 +54,8 @@ beforeEach(() => {
|
|
|
55
54
|
vi.mocked(suggestPrincipals)
|
|
56
55
|
.mockReset()
|
|
57
56
|
.mockResolvedValue({
|
|
58
|
-
|
|
57
|
+
roles: [],
|
|
58
|
+
groups: [],
|
|
59
59
|
people: [{ name: 'Alice', email: 'alice@example.com' }],
|
|
60
60
|
peopleWithheld: false,
|
|
61
61
|
});
|
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { render, screen, waitFor, within } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import { DirectoryGroupsPage } from '../components/DirectoryGroupsPage';
|
|
5
|
+
import { AdminContext } from '../state/admin.context';
|
|
6
|
+
import {
|
|
7
|
+
AppRegistryContext,
|
|
8
|
+
EMPTY_REGISTRY,
|
|
9
|
+
type GroupsDirectoryPanelProps,
|
|
10
|
+
} from '../../../core/registry';
|
|
11
|
+
import {
|
|
12
|
+
addGroupMember,
|
|
13
|
+
createGroup,
|
|
14
|
+
deleteGroup,
|
|
15
|
+
getGroupsRoster,
|
|
16
|
+
GroupsApiError,
|
|
17
|
+
removeGroupMember,
|
|
18
|
+
renameGroup,
|
|
19
|
+
type GroupsRoster,
|
|
20
|
+
} from '../services/groups.api';
|
|
21
|
+
|
|
22
|
+
vi.mock('../services/groups.api', async (importOriginal) => {
|
|
23
|
+
const actual = await importOriginal<typeof import('../services/groups.api')>();
|
|
24
|
+
return {
|
|
25
|
+
...actual,
|
|
26
|
+
getGroupsRoster: vi.fn(),
|
|
27
|
+
createGroup: vi.fn(),
|
|
28
|
+
deleteGroup: vi.fn(),
|
|
29
|
+
addGroupMember: vi.fn(),
|
|
30
|
+
removeGroupMember: vi.fn(),
|
|
31
|
+
renameGroup: vi.fn(),
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const MANUAL_ROSTER: GroupsRoster = {
|
|
36
|
+
mode: 'manual',
|
|
37
|
+
groups: [
|
|
38
|
+
{
|
|
39
|
+
canonical: 'product',
|
|
40
|
+
displayName: 'Product',
|
|
41
|
+
members: ['pat@example.com'],
|
|
42
|
+
referencedBy: [{ path: 'docs/roadmap.md', verb: 'read' }],
|
|
43
|
+
assignedToRoles: [],
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
canonical: 'design',
|
|
47
|
+
displayName: 'Design',
|
|
48
|
+
members: [],
|
|
49
|
+
referencedBy: [],
|
|
50
|
+
assignedToRoles: [],
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
groupsHealth: { ok: true },
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const IDP_ROSTER: GroupsRoster = {
|
|
57
|
+
mode: 'idp',
|
|
58
|
+
groups: [
|
|
59
|
+
{
|
|
60
|
+
canonical: 'engineering',
|
|
61
|
+
displayName: 'Engineering',
|
|
62
|
+
members: ['ada@example.com', 'bo@example.com', 'cy@example.com'],
|
|
63
|
+
referencedBy: [],
|
|
64
|
+
assignedToRoles: [],
|
|
65
|
+
},
|
|
66
|
+
{ canonical: 'sales', displayName: 'Sales', members: [], referencedBy: [], assignedToRoles: [] },
|
|
67
|
+
],
|
|
68
|
+
groupsHealth: { ok: true },
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
function renderPage(opts: {
|
|
72
|
+
isAdmin?: boolean;
|
|
73
|
+
directoryPanel?: (props: GroupsDirectoryPanelProps) => React.ReactElement;
|
|
74
|
+
} = {}) {
|
|
75
|
+
const registry = opts.directoryPanel
|
|
76
|
+
? { ...EMPTY_REGISTRY, groupsDirectoryPanel: opts.directoryPanel }
|
|
77
|
+
: EMPTY_REGISTRY;
|
|
78
|
+
return render(
|
|
79
|
+
<AppRegistryContext.Provider value={registry}>
|
|
80
|
+
<AdminContext.Provider
|
|
81
|
+
value={{
|
|
82
|
+
isAdmin: opts.isAdmin ?? true,
|
|
83
|
+
unreadCount: 0,
|
|
84
|
+
lastSeen: null,
|
|
85
|
+
markSeen: () => {},
|
|
86
|
+
refresh: () => {},
|
|
87
|
+
rolesConfigCorrupted: false,
|
|
88
|
+
rolesConfigErrors: [],
|
|
89
|
+
runRolesRecovery: async () => {},
|
|
90
|
+
}}
|
|
91
|
+
>
|
|
92
|
+
<DirectoryGroupsPage />
|
|
93
|
+
</AdminContext.Provider>
|
|
94
|
+
</AppRegistryContext.Provider>,
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
beforeEach(() => {
|
|
99
|
+
vi.mocked(getGroupsRoster).mockReset().mockResolvedValue(MANUAL_ROSTER);
|
|
100
|
+
vi.mocked(createGroup).mockReset().mockResolvedValue(MANUAL_ROSTER);
|
|
101
|
+
vi.mocked(deleteGroup).mockReset().mockResolvedValue(MANUAL_ROSTER);
|
|
102
|
+
vi.mocked(addGroupMember).mockReset().mockResolvedValue(MANUAL_ROSTER);
|
|
103
|
+
vi.mocked(removeGroupMember).mockReset().mockResolvedValue(MANUAL_ROSTER);
|
|
104
|
+
vi.mocked(renameGroup).mockReset().mockResolvedValue(MANUAL_ROSTER);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe('DirectoryGroupsPage', () => {
|
|
108
|
+
it('shows the admins-only state (and never loads) for non-admins', () => {
|
|
109
|
+
renderPage({ isAdmin: false });
|
|
110
|
+
expect(screen.getByText(/Admins only/)).toBeInTheDocument();
|
|
111
|
+
expect(getGroupsRoster).not.toHaveBeenCalled();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('manual mode: renders the groups with members and CRUD controls', async () => {
|
|
115
|
+
renderPage();
|
|
116
|
+
expect(await screen.findByText('Product')).toBeInTheDocument();
|
|
117
|
+
expect(screen.getByText('pat@example.com')).toBeInTheDocument();
|
|
118
|
+
expect(screen.getByRole('textbox', { name: 'New group name' })).toBeInTheDocument();
|
|
119
|
+
expect(screen.getByRole('button', { name: 'Delete Product' })).toBeInTheDocument();
|
|
120
|
+
expect(screen.getByRole('textbox', { name: 'Add member to Product' })).toBeInTheDocument();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('manual mode: creating a group calls the api and applies the returned roster', async () => {
|
|
124
|
+
vi.mocked(createGroup).mockResolvedValue({
|
|
125
|
+
mode: 'manual',
|
|
126
|
+
groups: [
|
|
127
|
+
...MANUAL_ROSTER.groups,
|
|
128
|
+
{
|
|
129
|
+
canonical: 'support',
|
|
130
|
+
displayName: 'Support',
|
|
131
|
+
members: [],
|
|
132
|
+
referencedBy: [],
|
|
133
|
+
assignedToRoles: [],
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
groupsHealth: { ok: true },
|
|
137
|
+
});
|
|
138
|
+
renderPage();
|
|
139
|
+
await userEvent.type(await screen.findByRole('textbox', { name: 'New group name' }), 'Support');
|
|
140
|
+
await userEvent.click(screen.getByRole('button', { name: /Create group/ }));
|
|
141
|
+
await waitFor(() => expect(createGroup).toHaveBeenCalledWith('Support'));
|
|
142
|
+
expect(await screen.findByText('Support')).toBeInTheDocument();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('manual mode: adding and removing members hit the api', async () => {
|
|
146
|
+
renderPage();
|
|
147
|
+
const input = await screen.findByRole('textbox', { name: 'Add member to Design' });
|
|
148
|
+
await userEvent.type(input, 'dana@example.com');
|
|
149
|
+
// Scope to the input's row — each group card has its own Add button.
|
|
150
|
+
await userEvent.click(within(input.closest('div')!).getByRole('button', { name: 'Add' }));
|
|
151
|
+
await waitFor(() =>
|
|
152
|
+
expect(addGroupMember).toHaveBeenCalledWith('design', 'dana@example.com'),
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
await userEvent.click(screen.getByRole('button', { name: 'Remove pat@example.com' }));
|
|
156
|
+
await waitFor(() =>
|
|
157
|
+
expect(removeGroupMember).toHaveBeenCalledWith('product', 'pat@example.com'),
|
|
158
|
+
);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('manual mode: overlapping mutations are serialized — the second request waits for the first', async () => {
|
|
162
|
+
// Mutations are snapshot-based server-side, so the page must never have
|
|
163
|
+
// two in flight at once. Hold the first response open and check the second
|
|
164
|
+
// click doesn't issue its request until the first resolves.
|
|
165
|
+
const resolvers: ((r: GroupsRoster) => void)[] = [];
|
|
166
|
+
vi.mocked(addGroupMember).mockImplementation(
|
|
167
|
+
() => new Promise<GroupsRoster>((resolve) => resolvers.push(resolve)),
|
|
168
|
+
);
|
|
169
|
+
renderPage();
|
|
170
|
+
|
|
171
|
+
const productInput = await screen.findByRole('textbox', { name: 'Add member to Product' });
|
|
172
|
+
await userEvent.type(productInput, 'a@example.com');
|
|
173
|
+
await userEvent.click(within(productInput.closest('div')!).getByRole('button', { name: 'Add' }));
|
|
174
|
+
await waitFor(() => expect(addGroupMember).toHaveBeenCalledTimes(1));
|
|
175
|
+
|
|
176
|
+
// Second card: its own busy flag is free, so the click goes through — but
|
|
177
|
+
// the request must queue behind the unresolved first one.
|
|
178
|
+
const designInput = screen.getByRole('textbox', { name: 'Add member to Design' });
|
|
179
|
+
await userEvent.type(designInput, 'b@example.com');
|
|
180
|
+
await userEvent.click(within(designInput.closest('div')!).getByRole('button', { name: 'Add' }));
|
|
181
|
+
expect(addGroupMember).toHaveBeenCalledTimes(1);
|
|
182
|
+
|
|
183
|
+
resolvers[0](MANUAL_ROSTER);
|
|
184
|
+
await waitFor(() => expect(addGroupMember).toHaveBeenCalledTimes(2));
|
|
185
|
+
expect(addGroupMember).toHaveBeenNthCalledWith(2, 'design', 'b@example.com');
|
|
186
|
+
|
|
187
|
+
resolvers[1](MANUAL_ROSTER);
|
|
188
|
+
// Both cards settle back to idle.
|
|
189
|
+
await waitFor(() =>
|
|
190
|
+
expect(screen.getByRole('textbox', { name: 'Add member to Design' })).not.toBeDisabled(),
|
|
191
|
+
);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('manual mode: renaming a group inline calls the PATCH api and applies the returned roster', async () => {
|
|
195
|
+
vi.mocked(renameGroup).mockResolvedValue({
|
|
196
|
+
mode: 'manual',
|
|
197
|
+
groups: [
|
|
198
|
+
{
|
|
199
|
+
canonical: 'product & platform',
|
|
200
|
+
displayName: 'Product & Platform',
|
|
201
|
+
members: ['pat@example.com'],
|
|
202
|
+
referencedBy: [],
|
|
203
|
+
assignedToRoles: [],
|
|
204
|
+
},
|
|
205
|
+
MANUAL_ROSTER.groups[1],
|
|
206
|
+
],
|
|
207
|
+
groupsHealth: { ok: true },
|
|
208
|
+
});
|
|
209
|
+
renderPage();
|
|
210
|
+
await userEvent.click(await screen.findByRole('button', { name: 'Rename Product' }));
|
|
211
|
+
const input = screen.getByRole('textbox', { name: 'Rename Product' });
|
|
212
|
+
await userEvent.clear(input);
|
|
213
|
+
await userEvent.type(input, 'Product & Platform{Enter}');
|
|
214
|
+
await waitFor(() => expect(renameGroup).toHaveBeenCalledWith('product', 'Product & Platform'));
|
|
215
|
+
expect(await screen.findByText('Product & Platform')).toBeInTheDocument();
|
|
216
|
+
// The editor closed back into the heading view.
|
|
217
|
+
expect(screen.queryByRole('textbox', { name: /Rename/ })).not.toBeInTheDocument();
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it('manual mode: Escape cancels a rename without a request; an unchanged name is a local no-op', async () => {
|
|
221
|
+
renderPage();
|
|
222
|
+
await userEvent.click(await screen.findByRole('button', { name: 'Rename Product' }));
|
|
223
|
+
await userEvent.keyboard('{Escape}');
|
|
224
|
+
expect(screen.queryByRole('textbox', { name: /Rename/ })).not.toBeInTheDocument();
|
|
225
|
+
// Reopen and submit the SAME name — no request either.
|
|
226
|
+
await userEvent.click(screen.getByRole('button', { name: 'Rename Product' }));
|
|
227
|
+
await userEvent.keyboard('{Enter}');
|
|
228
|
+
expect(renameGroup).not.toHaveBeenCalled();
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('manual mode: deleting a group requires a confirm and warns about references', async () => {
|
|
232
|
+
renderPage();
|
|
233
|
+
await userEvent.click(await screen.findByRole('button', { name: 'Delete Product' }));
|
|
234
|
+
expect(deleteGroup).not.toHaveBeenCalled();
|
|
235
|
+
|
|
236
|
+
const dialog = within(screen.getByRole('dialog'));
|
|
237
|
+
// Product is referenced by one access rule — the dialog must say so.
|
|
238
|
+
expect(dialog.getByText(/1 access rule/)).toBeInTheDocument();
|
|
239
|
+
expect(dialog.getByText(/docs\/roadmap\.md/)).toBeInTheDocument();
|
|
240
|
+
await userEvent.click(dialog.getByRole('button', { name: 'Delete group' }));
|
|
241
|
+
await waitFor(() => expect(deleteGroup).toHaveBeenCalledWith('product'));
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it('idp mode: read-only roster, no mutation controls, membership note shown', async () => {
|
|
245
|
+
vi.mocked(getGroupsRoster).mockResolvedValue(IDP_ROSTER);
|
|
246
|
+
renderPage();
|
|
247
|
+
expect(await screen.findByText('Engineering')).toBeInTheDocument();
|
|
248
|
+
expect(screen.getByText(/3 members/)).toBeInTheDocument();
|
|
249
|
+
expect(
|
|
250
|
+
screen.getByText('Membership is managed in your identity provider.'),
|
|
251
|
+
).toBeInTheDocument();
|
|
252
|
+
// No manual CRUD anywhere: no create form, no add-member inputs, no deletes.
|
|
253
|
+
expect(screen.queryByRole('textbox', { name: 'New group name' })).not.toBeInTheDocument();
|
|
254
|
+
expect(screen.queryByRole('textbox', { name: /Add member/ })).not.toBeInTheDocument();
|
|
255
|
+
expect(screen.queryByRole('button', { name: /^Delete / })).not.toBeInTheDocument();
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it('renders the registry directory panel with the mode, and its callback refreshes', async () => {
|
|
259
|
+
const rosters = [MANUAL_ROSTER, IDP_ROSTER];
|
|
260
|
+
vi.mocked(getGroupsRoster).mockImplementation(async () => rosters.shift() ?? IDP_ROSTER);
|
|
261
|
+
renderPage({
|
|
262
|
+
directoryPanel: ({ mode, onDirectoryChanged }) => (
|
|
263
|
+
<button onClick={onDirectoryChanged}>panel:{mode}</button>
|
|
264
|
+
),
|
|
265
|
+
});
|
|
266
|
+
// The panel sees the roster's mode.
|
|
267
|
+
await userEvent.click(await screen.findByRole('button', { name: 'panel:manual' }));
|
|
268
|
+
// Its callback refetches: the second roster is idp, so the page flips.
|
|
269
|
+
expect(await screen.findByRole('button', { name: 'panel:idp' })).toBeInTheDocument();
|
|
270
|
+
expect(
|
|
271
|
+
await screen.findByText('Membership is managed in your identity provider.'),
|
|
272
|
+
).toBeInTheDocument();
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it('connected-but-not-materialized: the panel signal suppresses manual CRUD', async () => {
|
|
276
|
+
renderPage({
|
|
277
|
+
directoryPanel: ({ onConnectedChange }) => (
|
|
278
|
+
<button onClick={() => onConnectedChange(true)}>simulate-connect</button>
|
|
279
|
+
),
|
|
280
|
+
});
|
|
281
|
+
// Manual CRUD is up while disconnected.
|
|
282
|
+
expect(await screen.findByRole('textbox', { name: 'New group name' })).toBeInTheDocument();
|
|
283
|
+
// The panel reports a live connection (e.g. a token was just minted).
|
|
284
|
+
await userEvent.click(screen.getByRole('button', { name: 'simulate-connect' }));
|
|
285
|
+
// No create form, no member editing — the IdP owns groups now.
|
|
286
|
+
expect(screen.queryByRole('textbox', { name: 'New group name' })).not.toBeInTheDocument();
|
|
287
|
+
expect(screen.queryByRole('textbox', { name: /Add member/ })).not.toBeInTheDocument();
|
|
288
|
+
expect(
|
|
289
|
+
await screen.findByText(/Groups appear here after its first provisioning push/),
|
|
290
|
+
).toBeInTheDocument();
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it('a connection flipping true closes an open delete confirm (no delete against an IdP-owned roster)', async () => {
|
|
294
|
+
renderPage({
|
|
295
|
+
directoryPanel: ({ onConnectedChange }) => (
|
|
296
|
+
<button onClick={() => onConnectedChange(true)}>simulate-connect</button>
|
|
297
|
+
),
|
|
298
|
+
});
|
|
299
|
+
// Open the delete confirm against the manual roster…
|
|
300
|
+
await userEvent.click(await screen.findByRole('button', { name: 'Delete Product' }));
|
|
301
|
+
expect(screen.getByRole('dialog')).toBeInTheDocument();
|
|
302
|
+
// …then the directory connects. The manual view unmounts; the confirm
|
|
303
|
+
// must go with it — confirming now would delete from a roster the IdP owns.
|
|
304
|
+
await userEvent.click(screen.getByRole('button', { name: 'simulate-connect' }));
|
|
305
|
+
await waitFor(() => expect(screen.queryByRole('dialog')).not.toBeInTheDocument());
|
|
306
|
+
expect(deleteGroup).not.toHaveBeenCalled();
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it('no registry panel means the page never mentions a directory connection', async () => {
|
|
310
|
+
renderPage();
|
|
311
|
+
expect(await screen.findByText('Product')).toBeInTheDocument();
|
|
312
|
+
expect(screen.queryByText(/identity provider/i)).not.toBeInTheDocument();
|
|
313
|
+
expect(screen.queryByText(/SCIM/)).not.toBeInTheDocument();
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
it('a failed FIRST load reports the failure, not an empty manual page', async () => {
|
|
317
|
+
vi.mocked(getGroupsRoster).mockReset().mockRejectedValue(new Error('Backend unreachable'));
|
|
318
|
+
renderPage();
|
|
319
|
+
expect(await screen.findByRole('alert')).toHaveTextContent('Backend unreachable');
|
|
320
|
+
expect(screen.queryByRole('textbox', { name: 'New group name' })).not.toBeInTheDocument();
|
|
321
|
+
expect(screen.queryByText('Loading…')).not.toBeInTheDocument();
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
it('a roster whose groupsHealth is broken banners loudly: file, reason, "not being applied"', async () => {
|
|
325
|
+
// Broken IdP-synced file: the roster still answers 200 (mode stays idp,
|
|
326
|
+
// groups empty) but carries the health marker — resolution is degraded
|
|
327
|
+
// and the page must say so, not render a quietly empty list.
|
|
328
|
+
vi.mocked(getGroupsRoster).mockResolvedValue({
|
|
329
|
+
mode: 'idp',
|
|
330
|
+
groups: [],
|
|
331
|
+
groupsHealth: { ok: false, file: 'synced-groups.yaml', reason: 'bad indentation on line 3' },
|
|
332
|
+
});
|
|
333
|
+
renderPage();
|
|
334
|
+
const alert = await screen.findByRole('alert');
|
|
335
|
+
expect(alert).toHaveTextContent('synced-groups.yaml');
|
|
336
|
+
expect(alert).toHaveTextContent(/groups are\s+not being applied/i);
|
|
337
|
+
expect(alert).toHaveTextContent('bad indentation on line 3');
|
|
338
|
+
// The rest of the page stays alive (the idp view still renders).
|
|
339
|
+
expect(screen.getByText(/synced from your identity provider/i)).toBeInTheDocument();
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
it("the roster 422 (kind 'broken-groups') gets the same banner with the parse message", async () => {
|
|
343
|
+
// Broken MANUAL groups.yaml: the roster endpoint answers 422 with the
|
|
344
|
+
// parse message — the operator must see what to fix, never a dead page.
|
|
345
|
+
vi.mocked(getGroupsRoster)
|
|
346
|
+
.mockReset()
|
|
347
|
+
.mockRejectedValue(
|
|
348
|
+
new GroupsApiError('groups.yaml cannot be read: mapping values are not allowed', 422, 'broken-groups', {
|
|
349
|
+
file: 'groups.yaml',
|
|
350
|
+
reason: 'mapping values are not allowed',
|
|
351
|
+
}),
|
|
352
|
+
);
|
|
353
|
+
renderPage();
|
|
354
|
+
const alert = await screen.findByRole('alert');
|
|
355
|
+
expect(alert).toHaveTextContent('groups.yaml');
|
|
356
|
+
expect(alert).toHaveTextContent(/groups are\s+not being applied/i);
|
|
357
|
+
expect(alert).toHaveTextContent('mapping values are not allowed');
|
|
358
|
+
// Not the generic load-failure message, and not stuck on the spinner.
|
|
359
|
+
expect(screen.queryByText("Couldn't load groups.")).not.toBeInTheDocument();
|
|
360
|
+
expect(screen.queryByText('Loading…')).not.toBeInTheDocument();
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
it('a refresh-discovered broken-groups 422 clears the stale roster rows and any pending delete confirm', async () => {
|
|
364
|
+
// First load is healthy; a later refresh (directory panel callback) finds
|
|
365
|
+
// the manual groups.yaml broken. The stale rows must not keep offering
|
|
366
|
+
// CRUD against a file that can't be parsed, and a delete confirm opened
|
|
367
|
+
// against the stale roster must not survive; the banner takes over.
|
|
368
|
+
vi.mocked(getGroupsRoster)
|
|
369
|
+
.mockReset()
|
|
370
|
+
.mockResolvedValueOnce(MANUAL_ROSTER)
|
|
371
|
+
.mockRejectedValueOnce(
|
|
372
|
+
new GroupsApiError('groups.yaml cannot be read: bad indent', 422, 'broken-groups', {
|
|
373
|
+
file: 'groups.yaml',
|
|
374
|
+
reason: 'bad indent',
|
|
375
|
+
}),
|
|
376
|
+
);
|
|
377
|
+
renderPage({
|
|
378
|
+
directoryPanel: ({ onDirectoryChanged }) => (
|
|
379
|
+
<button onClick={onDirectoryChanged}>refresh-panel</button>
|
|
380
|
+
),
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
// Healthy roster rendered; open the delete confirm against it.
|
|
384
|
+
await userEvent.click(await screen.findByRole('button', { name: 'Delete Product' }));
|
|
385
|
+
expect(screen.getByRole('dialog')).toBeInTheDocument();
|
|
386
|
+
|
|
387
|
+
// The refresh discovers the broken file.
|
|
388
|
+
await userEvent.click(screen.getByRole('button', { name: 'refresh-panel' }));
|
|
389
|
+
|
|
390
|
+
const alert = await screen.findByRole('alert');
|
|
391
|
+
expect(alert).toHaveTextContent('groups.yaml');
|
|
392
|
+
expect(alert).toHaveTextContent(/groups are\s+not being applied/i);
|
|
393
|
+
// Stale rows + CRUD controls are gone.
|
|
394
|
+
await waitFor(() => expect(screen.queryByText('Product')).not.toBeInTheDocument());
|
|
395
|
+
expect(screen.queryByRole('textbox', { name: 'New group name' })).not.toBeInTheDocument();
|
|
396
|
+
expect(screen.queryByRole('textbox', { name: /Add member/ })).not.toBeInTheDocument();
|
|
397
|
+
expect(screen.queryByRole('button', { name: /^Delete / })).not.toBeInTheDocument();
|
|
398
|
+
// The pending delete confirm was dismissed — no dialog left to act on the
|
|
399
|
+
// unparseable file.
|
|
400
|
+
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
|
|
401
|
+
expect(deleteGroup).not.toHaveBeenCalled();
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
it('the delete confirm names the roles the group is assigned to', async () => {
|
|
405
|
+
vi.mocked(getGroupsRoster).mockResolvedValue({
|
|
406
|
+
mode: 'manual',
|
|
407
|
+
groups: [
|
|
408
|
+
{
|
|
409
|
+
canonical: 'gtm',
|
|
410
|
+
displayName: 'GTM',
|
|
411
|
+
members: ['pat@example.com'],
|
|
412
|
+
referencedBy: [],
|
|
413
|
+
assignedToRoles: ['editor', 'reviewer'],
|
|
414
|
+
},
|
|
415
|
+
],
|
|
416
|
+
groupsHealth: { ok: true },
|
|
417
|
+
});
|
|
418
|
+
renderPage();
|
|
419
|
+
await userEvent.click(await screen.findByRole('button', { name: 'Delete GTM' }));
|
|
420
|
+
const dialog = within(screen.getByRole('dialog'));
|
|
421
|
+
// Deleting also unassigns — the confirm names the affected roles.
|
|
422
|
+
expect(dialog.getByText(/unassigns this group from the roles/i)).toBeInTheDocument();
|
|
423
|
+
expect(dialog.getByText('editor, reviewer')).toBeInTheDocument();
|
|
424
|
+
// The "loses nothing else" reassurance would be a lie here.
|
|
425
|
+
expect(dialog.queryByText(/lose nothing else/i)).not.toBeInTheDocument();
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
it("a 'group:'-prefixed member value gets the inline hint and no request", async () => {
|
|
429
|
+
renderPage();
|
|
430
|
+
const input = await screen.findByRole('textbox', { name: 'Add member to Design' });
|
|
431
|
+
await userEvent.type(input, 'group:engineering');
|
|
432
|
+
await userEvent.click(within(input.closest('div')!).getByRole('button', { name: 'Add' }));
|
|
433
|
+
expect(
|
|
434
|
+
await screen.findByText(/Group members are emails — 'group:' references aren't allowed/),
|
|
435
|
+
).toBeInTheDocument();
|
|
436
|
+
expect(addGroupMember).not.toHaveBeenCalled();
|
|
437
|
+
});
|
|
438
|
+
});
|