@bevel-software/platform-core-frontend 0.27.0 → 0.28.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.
Files changed (42) hide show
  1. package/package.json +2 -2
  2. package/src/core/ProductName.tsx +4 -4
  3. package/src/core/__tests__/ProductName.test.tsx +46 -0
  4. package/src/core/maker-url.ts +30 -0
  5. package/src/core/registry.ts +27 -0
  6. package/src/lib/__tests__/latest-request.test.ts +48 -0
  7. package/src/lib/latest-request.ts +45 -0
  8. package/src/modules/access/__tests__/ManageAccessDialog.no-sso-invite.test.tsx +222 -0
  9. package/src/modules/access/api.ts +19 -3
  10. package/src/modules/access/components/ManageAccessDialog.tsx +60 -7
  11. package/src/modules/admin/__tests__/AdminRolesPage.fixed-admin.test.tsx +16 -1
  12. package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +284 -39
  13. package/src/modules/admin/components/AdminRolesPage.tsx +13 -14
  14. package/src/modules/admin/components/UserAccountsPage.tsx +91 -107
  15. package/src/modules/admin/services/roles.api.ts +14 -1
  16. package/src/modules/auth/__tests__/LoginScreen.test.tsx +80 -5
  17. package/src/modules/auth/__tests__/sso-strict-probe.test.ts +66 -0
  18. package/src/modules/auth/components/LoginScreen.tsx +100 -75
  19. package/src/modules/auth/services/account.api.ts +31 -2
  20. package/src/modules/auth/services/sso.ts +29 -8
  21. package/src/modules/auth/state/use-sign-in-methods.ts +41 -0
  22. package/src/modules/onboarding/__tests__/InviteButton.test.tsx +214 -0
  23. package/src/modules/onboarding/__tests__/first-page-prompt.test.ts +56 -1
  24. package/src/modules/onboarding/__tests__/get-started-column.test.tsx +538 -81
  25. package/src/modules/onboarding/__tests__/invite-dialog.test.tsx +543 -124
  26. package/src/modules/onboarding/__tests__/invite-emails.test.ts +247 -0
  27. package/src/modules/onboarding/components/GetStartedColumn.tsx +30 -11
  28. package/src/modules/onboarding/components/InviteButton.tsx +119 -15
  29. package/src/modules/onboarding/components/InviteDialog.tsx +392 -75
  30. package/src/modules/onboarding/first-page-prompt.ts +34 -0
  31. package/src/modules/onboarding/invite-emails.ts +171 -33
  32. package/src/modules/onboarding/state/invite-dialog.context.ts +7 -4
  33. package/src/modules/onboarding/state/invite-dialog.tsx +12 -4
  34. package/src/modules/toolbar/commands/actions.tsx +10 -4
  35. package/src/modules/toolbar/commands/useCommandActions.ts +5 -3
  36. package/src/modules/toolbar/components/AppSwitcher.tsx +19 -0
  37. package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +46 -1
  38. package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +34 -2
  39. package/src/modules/workspace/hooks/__tests__/useCreatePage.test.ts +137 -0
  40. package/src/modules/workspace/hooks/__tests__/useKnowledgeWriteTarget.test.ts +302 -0
  41. package/src/modules/workspace/hooks/useCreatePage.ts +118 -28
  42. package/src/modules/workspace/hooks/useKnowledgeWriteTarget.ts +238 -0
@@ -1,30 +1,46 @@
1
1
  import { beforeEach, describe, expect, it, vi } from 'vitest';
2
- import { fireEvent, render, screen, within } from '@testing-library/react';
2
+ import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
3
3
  import userEvent from '@testing-library/user-event';
4
4
  import { AuthContext } from '../../auth/state/auth.context';
5
5
  import { authValue } from '../../library/__tests__/auth-harness';
6
- import { AdminContext, type AdminContextValue } from '../../admin/state/admin.context';
7
6
  import { AppRegistryContext, makeRegistry } from '../../../core/registry';
8
7
  import { AccountRequestError, type AccountSummary } from '../../auth/services/account.api';
8
+ import type { LoginProviders } from '../../auth/services/sso';
9
9
  import { InviteDialog } from '../components/InviteDialog';
10
- import { InviteButton } from '../components/InviteButton';
11
10
  import { InviteDialogProvider } from '../state/invite-dialog';
11
+ import { useInviteDialog } from '../state/invite-dialog.context';
12
12
  import { splitEmails } from '../invite-emails';
13
13
 
14
+ /** Every invite promotion is sent `ifActive`: the server refuses a switched-off account at the write. */
15
+ const ACTIVE = { ifActive: true };
16
+
14
17
  /**
15
- * The invite dialog: addresses become chips the way people paste them,
16
- * sending creates one account per valid address (and makes the new ones
17
- * admins when asked), a refusal for want of a seat says so on its row, and
18
- * the result view hands the admin what to forward.
18
+ * The invite dialog: addresses become chips the way people paste them; the
19
+ * dialog asks how the deployment signs people in before it lets anything be
20
+ * sent, and asks for a starting password where one is needed; sending
21
+ * creates one account per valid address (and makes the new ones admins when
22
+ * asked); and the result view says how each person signs in and hands the
23
+ * admin what to forward — never the password.
19
24
  */
20
25
 
21
- const { listAccountsMock, createAccountMock, addMemberMock, fetchRolesMock, copyMock } = vi.hoisted(() => ({
22
- listAccountsMock: vi.fn<() => Promise<AccountSummary[]>>(),
23
- createAccountMock: vi.fn<(email: string, name: string) => Promise<void>>(),
24
- addMemberMock: vi.fn<(canonical: string, email: string) => Promise<unknown>>(),
25
- fetchRolesMock: vi.fn<() => Promise<{ canonical: string; members: string[]; fixedMembers?: string[] }[]>>(),
26
- copyMock: vi.fn<(text: string) => Promise<boolean>>(),
27
- }));
26
+ const { listAccountsMock, createAccountMock, addMemberMock, fetchRolesMock, copyMock, providersMock } = vi.hoisted(
27
+ () => ({
28
+ listAccountsMock: vi.fn<() => Promise<AccountSummary[]>>(),
29
+ createAccountMock:
30
+ vi.fn<
31
+ (
32
+ email: string,
33
+ name: string,
34
+ password?: string,
35
+ options?: { keepExistingPassword?: boolean },
36
+ ) => Promise<{ passwordSet?: boolean; notified?: string[] }>
37
+ >(),
38
+ addMemberMock: vi.fn<(canonical: string, email: string, options?: { ifActive?: boolean }) => Promise<unknown>>(),
39
+ fetchRolesMock: vi.fn<() => Promise<{ canonical: string; members: string[]; fixedMembers?: string[] }[]>>(),
40
+ copyMock: vi.fn<(text: string) => Promise<boolean>>(),
41
+ providersMock: vi.fn<() => Promise<LoginProviders>>(),
42
+ }),
43
+ );
28
44
 
29
45
  vi.mock('../../../lib/api', () => ({ authFetch: vi.fn() }));
30
46
  vi.mock('../../auth/services/account.api', async (importOriginal) => ({
@@ -37,46 +53,59 @@ vi.mock('../../admin/services/roles.api', async (importOriginal) => ({
37
53
  addMember: addMemberMock,
38
54
  fetchRoles: fetchRolesMock,
39
55
  }));
56
+ vi.mock('../../auth/services/sso', async (importOriginal) => ({
57
+ ...(await importOriginal<typeof import('../../auth/services/sso')>()),
58
+ fetchLoginProvidersStrict: providersMock,
59
+ }));
40
60
  vi.mock('../../library/utils/clipboard', () => ({ copyToClipboard: copyMock }));
41
61
 
42
- function account(email: string): AccountSummary {
62
+ const DUENDE = { key: 'oidc', label: 'Duende Demo', startPath: '/api/auth/oidc/start' };
63
+ /** Password sign-in, no single sign-on (knowledge.bevel.software). */
64
+ const PASSWORD_ONLY: LoginProviders = { password: true, sso: [] };
65
+ /** Single sign-on and password sign-in (core-staging). */
66
+ const SSO_AND_PASSWORD: LoginProviders = { password: true, sso: [DUENDE] };
67
+ /** Single sign-on only: password sign-in is off. */
68
+ const SSO_ONLY: LoginProviders = { password: false, sso: [DUENDE] };
69
+
70
+ const SECRET = 'welcome-to-acme';
71
+ /** How a starting password is sent: the server never writes it over one of the account's own. */
72
+ const KEEP = { keepExistingPassword: true };
73
+
74
+ function account(email: string, over: Partial<AccountSummary> = {}): AccountSummary {
43
75
  return {
44
76
  id: email,
45
77
  email,
46
78
  name: email,
47
79
  hasPassword: false,
48
80
  isEnvAdmin: false,
81
+ isOwner: false,
82
+ ownerCanBeDeleted: false,
49
83
  deactivatedAt: null,
50
84
  isSystem: false,
51
85
  createdAt: '2026-01-01T00:00:00Z',
86
+ ...over,
52
87
  };
53
88
  }
54
89
 
55
- function adminValue(isAdmin: boolean): AdminContextValue {
56
- return {
57
- isAdmin,
58
- isAdminLoading: false,
59
- unreadCount: 0,
60
- lastSeen: null,
61
- markSeen: () => {},
62
- refresh: () => {},
63
- rolesConfigCorrupted: false,
64
- rolesConfigErrors: [],
65
- runRolesRecovery: async () => {},
66
- };
67
- }
68
-
69
- function mountDialog(registry = makeRegistry({})) {
90
+ /** Mount the dialog and wait until it knows how people sign in (or that it can't). */
91
+ async function mountDialog(
92
+ opts: { registry?: ReturnType<typeof makeRegistry>; initialEmails?: string[]; settle?: boolean } = {},
93
+ ) {
70
94
  const onInvited = vi.fn();
71
95
  const onClose = vi.fn();
72
96
  render(
73
- <AppRegistryContext.Provider value={registry}>
97
+ <AppRegistryContext.Provider value={opts.registry ?? makeRegistry({})}>
74
98
  <AuthContext.Provider value={authValue()}>
75
- <InviteDialog open onClose={onClose} onInvited={onInvited} />
99
+ <InviteDialog open onClose={onClose} onInvited={onInvited} initialEmails={opts.initialEmails} />
76
100
  </AuthContext.Provider>
77
101
  </AppRegistryContext.Provider>,
78
102
  );
79
- return { onInvited, onClose, input: screen.getByLabelText('Work emails') };
103
+ if (opts.settle !== false) {
104
+ await waitFor(() => expect(providersMock).toHaveBeenCalled());
105
+ // One turn for the answer to land.
106
+ await waitFor(() => expect(screen.queryByText(/^They sign in with|Couldn’t check/)).toBeInTheDocument());
107
+ }
108
+ return { onInvited, onClose, input: screen.getByLabelText('Emails') };
80
109
  }
81
110
 
82
111
  /** The chips on screen, by the address each holds. */
@@ -86,12 +115,25 @@ function chips(): string[] {
86
115
  );
87
116
  }
88
117
 
118
+ function passwordField(): HTMLInputElement {
119
+ return screen.getByLabelText('Starting password') as HTMLInputElement;
120
+ }
121
+
122
+ function rowOf(email: string): HTMLElement {
123
+ return within(screen.getByRole('list', { name: 'People' })).getByText(email).closest('li')!;
124
+ }
125
+
89
126
  beforeEach(() => {
90
- listAccountsMock.mockReset().mockResolvedValue([account('juan@bevel.software')]);
91
- createAccountMock.mockReset().mockResolvedValue(undefined);
127
+ listAccountsMock.mockReset().mockResolvedValue([account('juan@bevel.software', { hasPassword: true })]);
128
+ createAccountMock.mockReset().mockResolvedValue({});
92
129
  addMemberMock.mockReset().mockResolvedValue([]);
93
130
  fetchRolesMock.mockReset().mockResolvedValue([{ canonical: 'admin', members: ['juan@bevel.software'] }]);
94
131
  copyMock.mockReset().mockResolvedValue(true);
132
+ // The address-field and plain sending tests run as today's dialog did: no
133
+ // password involved, because the deployment has single sign-on.
134
+ providersMock.mockReset().mockResolvedValue(SSO_AND_PASSWORD);
135
+ localStorage.clear();
136
+ sessionStorage.clear();
95
137
  });
96
138
 
97
139
  describe('splitEmails', () => {
@@ -120,15 +162,15 @@ describe('splitEmails', () => {
120
162
 
121
163
  describe('InviteDialog: the address field', () => {
122
164
  it('makes a chip on Enter and on a comma', async () => {
123
- const { input } = mountDialog();
165
+ const { input } = await mountDialog();
124
166
  await userEvent.type(input, 'ana@bevel.software{Enter}');
125
167
  await userEvent.type(input, 'bo@bevel.software,');
126
168
  expect(chips()).toEqual(['ana@bevel.software', 'bo@bevel.software']);
127
169
  expect(input).toHaveValue('');
128
170
  });
129
171
 
130
- it('turns a pasted list into chips at once, without duplicates', () => {
131
- const { input } = mountDialog();
172
+ it('turns a pasted list into chips at once, without duplicates', async () => {
173
+ const { input } = await mountDialog();
132
174
  fireEvent.paste(input, {
133
175
  clipboardData: { getData: () => 'ana@bevel.software, bo@bevel.software\nANA@bevel.software' },
134
176
  });
@@ -136,14 +178,14 @@ describe('InviteDialog: the address field', () => {
136
178
  });
137
179
 
138
180
  it('takes the last chip back on Backspace in an empty field', async () => {
139
- const { input } = mountDialog();
181
+ const { input } = await mountDialog();
140
182
  await userEvent.type(input, 'ana@bevel.software{Enter}bo@bevel.software{Enter}');
141
183
  await userEvent.type(input, '{Backspace}');
142
184
  expect(chips()).toEqual(['ana@bevel.software']);
143
185
  });
144
186
 
145
187
  it('keeps an invalid address on screen in the danger tone, and does not count it', async () => {
146
- const { input } = mountDialog();
188
+ const { input } = await mountDialog();
147
189
  await userEvent.type(input, 'ana@bevel.software{Enter}not-an-address{Enter}');
148
190
  const bad = screen.getByTitle('not-an-address is not an email address');
149
191
  expect(bad).toHaveClass('text-danger');
@@ -152,15 +194,15 @@ describe('InviteDialog: the address field', () => {
152
194
  });
153
195
 
154
196
  it('counts an invalid address still in the field, which a send would clear unsent', async () => {
155
- const { input } = mountDialog();
197
+ const { input } = await mountDialog();
156
198
  await userEvent.type(input, 'ana@bevel.software{Enter}not-an-address');
157
199
  expect(chips()).toEqual(['ana@bevel.software']);
158
200
  expect(screen.getByText('One address isn’t valid and won’t be invited.')).toBeInTheDocument();
159
201
  expect(screen.getByRole('button', { name: 'Invite 1 person' })).toBeEnabled();
160
202
  });
161
203
 
162
- it('turns a pasted Outlook recipient list into one chip per person', () => {
163
- const { input } = mountDialog();
204
+ it('turns a pasted Outlook recipient list into one chip per person', async () => {
205
+ const { input } = await mountDialog();
164
206
  fireEvent.paste(input, {
165
207
  clipboardData: { getData: () => 'Doe, Jane <jane@bevel.software>; Roe, Rick <rick@bevel.software>' },
166
208
  });
@@ -168,81 +210,244 @@ describe('InviteDialog: the address field', () => {
168
210
  });
169
211
 
170
212
  it('can remove a chip with its button', async () => {
171
- const { input } = mountDialog();
213
+ const { input } = await mountDialog();
172
214
  await userEvent.type(input, 'ana@bevel.software{Enter}');
173
215
  await userEvent.click(screen.getByRole('button', { name: 'Remove ana@bevel.software' }));
174
216
  expect(chips()).toEqual([]);
175
217
  });
176
218
 
177
219
  it('cannot send with no valid address', async () => {
178
- const { input } = mountDialog();
220
+ const { input } = await mountDialog();
179
221
  expect(screen.getByRole('button', { name: 'Invite people' })).toBeDisabled();
180
222
  await userEvent.type(input, 'nope{Enter}');
181
223
  expect(screen.getByRole('button', { name: 'Invite people' })).toBeDisabled();
182
224
  });
225
+
226
+ it('opens through the shared controller with the addresses it is given', async () => {
227
+ function Opener() {
228
+ const invite = useInviteDialog();
229
+ return (
230
+ <button type="button" onClick={() => invite?.open({ emails: ['new.hire@bevel.software'] })}>
231
+ Open
232
+ </button>
233
+ );
234
+ }
235
+ render(
236
+ <AppRegistryContext.Provider value={makeRegistry({})}>
237
+ <AuthContext.Provider value={authValue()}>
238
+ <InviteDialogProvider>
239
+ <Opener />
240
+ </InviteDialogProvider>
241
+ </AuthContext.Provider>
242
+ </AppRegistryContext.Provider>,
243
+ );
244
+ await userEvent.click(screen.getByRole('button', { name: 'Open' }));
245
+ expect(await screen.findByRole('dialog', { name: 'Invite your team' })).toBeInTheDocument();
246
+ expect(chips()).toEqual(['new.hire@bevel.software']);
247
+ });
248
+
249
+ it('starts with the addresses it was opened with', async () => {
250
+ await mountDialog({ initialEmails: ['new.hire@bevel.software'] });
251
+ expect(chips()).toEqual(['new.hire@bevel.software']);
252
+ });
253
+ });
254
+
255
+ describe('InviteDialog: the form shows only what it needs', () => {
256
+ it('has no intro line, paste hint, role description or footer note', async () => {
257
+ await mountDialog();
258
+ for (const gone of [
259
+ 'They sign in with the account for the address you add.',
260
+ 'Paste a list, or press Enter or comma after each address.',
261
+ 'Sees everything shared with the whole workspace.',
262
+ 'Can also change settings and who has access.',
263
+ 'Uses the same access rules as Share → Manage access.',
264
+ ]) {
265
+ expect(screen.queryByText(gone)).not.toBeInTheDocument();
266
+ }
267
+ expect(screen.getByLabelText('Role')).toBeInTheDocument();
268
+ });
269
+ });
270
+
271
+ describe('InviteDialog: how people sign in here', () => {
272
+ it('stays disabled while it is still asking', async () => {
273
+ providersMock.mockReturnValue(new Promise(() => {}));
274
+ await mountDialog({ initialEmails: ['ana@bevel.software'], settle: false });
275
+ expect(screen.getByRole('button', { name: 'Invite 1 person' })).toBeDisabled();
276
+ });
277
+
278
+ it('without single sign-on, requires a starting password of at least 8 characters', async () => {
279
+ providersMock.mockResolvedValue(PASSWORD_ONLY);
280
+ const { input } = await mountDialog();
281
+ expect(screen.getByText('They sign in with their email and the password you set.')).toBeInTheDocument();
282
+ expect(screen.queryByLabelText('Also give them a password')).not.toBeInTheDocument();
283
+ const field = passwordField();
284
+ expect(field).toBeRequired();
285
+ expect(field).toHaveAttribute('type', 'password');
286
+ expect(field).toHaveAttribute('autocomplete', 'new-password');
287
+
288
+ // A valid address alone is not enough.
289
+ await userEvent.type(input, 'ana@bevel.software{Enter}');
290
+ expect(screen.getByRole('button', { name: 'Invite 1 person' })).toBeDisabled();
291
+
292
+ // A short password says why and stays disabled.
293
+ await userEvent.type(field, 'acme');
294
+ expect(screen.getByText('The password needs at least 8 characters.')).toBeInTheDocument();
295
+ expect(field).toHaveAttribute('aria-invalid', 'true');
296
+ expect(screen.getByRole('button', { name: 'Invite 1 person' })).toBeDisabled();
297
+
298
+ await userEvent.type(field, '-team');
299
+ expect(screen.queryByText('The password needs at least 8 characters.')).not.toBeInTheDocument();
300
+ expect(screen.getByRole('button', { name: 'Invite 1 person' })).toBeEnabled();
301
+ });
302
+
303
+ it('a password alone is not enough either', async () => {
304
+ providersMock.mockResolvedValue(PASSWORD_ONLY);
305
+ await mountDialog();
306
+ await userEvent.type(passwordField(), SECRET);
307
+ expect(screen.getByRole('button', { name: 'Invite people' })).toBeDisabled();
308
+ });
309
+
310
+ it('shows the password on the eye button, and hides it again', async () => {
311
+ providersMock.mockResolvedValue(PASSWORD_ONLY);
312
+ await mountDialog();
313
+ await userEvent.type(passwordField(), SECRET);
314
+ await userEvent.click(screen.getByRole('button', { name: 'Show password' }));
315
+ expect(passwordField()).toHaveAttribute('type', 'text');
316
+ await userEvent.click(screen.getByRole('button', { name: 'Hide password' }));
317
+ expect(passwordField()).toHaveAttribute('type', 'password');
318
+ });
319
+
320
+ it('with single sign-on, offers "Also give them a password", off, and requires the password once ticked', async () => {
321
+ const { input } = await mountDialog();
322
+ expect(screen.getByText('They sign in with Duende Demo.')).toBeInTheDocument();
323
+ const option = screen.getByLabelText('Also give them a password');
324
+ expect(option).not.toBeChecked();
325
+ expect(screen.queryByLabelText('Starting password')).not.toBeInTheDocument();
326
+ await userEvent.type(input, 'ana@bevel.software{Enter}');
327
+ expect(screen.getByRole('button', { name: 'Invite 1 person' })).toBeEnabled();
328
+
329
+ await userEvent.click(option);
330
+ expect(passwordField()).toBeRequired();
331
+ expect(
332
+ screen.getByText('They sign in with Duende Demo, or with their email and the password you set.'),
333
+ ).toBeInTheDocument();
334
+ expect(screen.getByRole('button', { name: 'Invite 1 person' })).toBeDisabled();
335
+ await userEvent.type(passwordField(), SECRET);
336
+ expect(screen.getByRole('button', { name: 'Invite 1 person' })).toBeEnabled();
337
+ });
338
+
339
+ it('names several single sign-on providers', async () => {
340
+ providersMock.mockResolvedValue({
341
+ password: true,
342
+ sso: [DUENDE, { key: 'ms', label: 'Microsoft', startPath: '/api/auth/ms/start' }],
343
+ });
344
+ await mountDialog();
345
+ expect(screen.getByText('They sign in with Duende Demo or Microsoft.')).toBeInTheDocument();
346
+ });
347
+
348
+ it('with password sign-in off, shows no password field and no option, and invites as today', async () => {
349
+ providersMock.mockResolvedValue(SSO_ONLY);
350
+ const { input } = await mountDialog();
351
+ expect(screen.queryByLabelText('Starting password')).not.toBeInTheDocument();
352
+ expect(screen.queryByLabelText('Also give them a password')).not.toBeInTheDocument();
353
+ await userEvent.type(input, 'ana@bevel.software{Enter}');
354
+ await userEvent.click(screen.getByRole('button', { name: 'Invite 1 person' }));
355
+ await screen.findByRole('dialog', { name: '1 person is invited' });
356
+ expect(createAccountMock).toHaveBeenCalledWith('ana@bevel.software', '');
357
+ });
358
+
359
+ it('with password sign-in off and no single sign-on either, sends nothing and says why', async () => {
360
+ providersMock.mockResolvedValue({ password: false, sso: [] });
361
+ await mountDialog({ initialEmails: ['ana@bevel.software'], settle: false });
362
+ expect(await screen.findByRole('alert')).toHaveTextContent(
363
+ 'Nobody could sign in: password sign-in is off here and no single sign-on is set up.',
364
+ );
365
+ expect(screen.getByRole('button', { name: 'Invite 1 person' })).toBeDisabled();
366
+ expect(screen.queryByLabelText('Starting password')).not.toBeInTheDocument();
367
+ });
368
+
369
+ it('when the check fails, keeps Invite disabled with Retry, and a successful Retry enables the form', async () => {
370
+ providersMock.mockRejectedValueOnce(new Error('offline')).mockResolvedValue(PASSWORD_ONLY);
371
+ await mountDialog({ initialEmails: ['ana@bevel.software'] });
372
+ expect(screen.getByRole('alert')).toHaveTextContent('Couldn’t check how people sign in here.');
373
+ expect(screen.getByRole('button', { name: 'Invite 1 person' })).toBeDisabled();
374
+ // Only the emails and the role while it doesn't know.
375
+ expect(screen.queryByLabelText('Starting password')).not.toBeInTheDocument();
376
+ expect(screen.queryByLabelText('Also give them a password')).not.toBeInTheDocument();
377
+ expect(screen.getByLabelText('Role')).toBeInTheDocument();
378
+
379
+ await userEvent.click(screen.getByRole('button', { name: 'Retry' }));
380
+ await screen.findByText('They sign in with their email and the password you set.');
381
+ expect(screen.queryByRole('alert')).not.toBeInTheDocument();
382
+ await userEvent.type(passwordField(), SECRET);
383
+ expect(screen.getByRole('button', { name: 'Invite 1 person' })).toBeEnabled();
384
+ });
183
385
  });
184
386
 
185
387
  describe('InviteDialog: sending', () => {
186
388
  it('creates one account per valid address, in order, and reports who was already here', async () => {
187
389
  listAccountsMock.mockResolvedValue([account('juan@bevel.software'), account('bo@bevel.software')]);
188
- const { input, onInvited } = mountDialog();
390
+ const { input, onInvited } = await mountDialog();
189
391
  await userEvent.type(input, 'ana@bevel.software{Enter}bo@bevel.software{Enter}cy@bevel.software');
190
392
  await userEvent.click(screen.getByRole('button', { name: 'Invite 3 people' }));
191
393
 
192
394
  expect(await screen.findByRole('dialog', { name: '3 people are invited' })).toBeInTheDocument();
193
- expect(createAccountMock.mock.calls.map((c) => c[0])).toEqual(['ana@bevel.software', 'cy@bevel.software']);
395
+ expect(createAccountMock.mock.calls).toEqual([
396
+ ['ana@bevel.software', ''],
397
+ ['cy@bevel.software', ''],
398
+ ]);
194
399
  expect(addMemberMock).not.toHaveBeenCalled();
195
400
  expect(onInvited).toHaveBeenCalledTimes(1);
196
401
 
197
402
  const people = within(screen.getByRole('list', { name: 'People' }));
198
403
  expect(people.getByText('Juan Viera (you)')).toBeInTheDocument();
199
- const bo = people.getByText('bo@bevel.software').closest('li')!;
200
- expect(within(bo).getByText('Already had an account')).toBeInTheDocument();
201
- const ana = people.getByText('ana@bevel.software').closest('li')!;
202
- expect(within(ana).getByText('Hasn’t signed in yet')).toBeInTheDocument();
404
+ expect(within(rowOf('bo@bevel.software')).getByText('Already had an account')).toBeInTheDocument();
405
+ expect(within(rowOf('bo@bevel.software')).getByText('Signs in with Duende Demo')).toBeInTheDocument();
406
+ expect(within(rowOf('ana@bevel.software')).getByText('Hasn’t signed in yet')).toBeInTheDocument();
407
+ expect(within(rowOf('ana@bevel.software')).getByText('Member · signs in with Duende Demo')).toBeInTheDocument();
408
+ expect(screen.getByText('They can sign in now with Duende Demo. Send them the link.')).toBeInTheDocument();
203
409
  });
204
410
 
205
411
  it('makes everyone invited as Admin an admin, new accounts and existing ones alike', async () => {
206
412
  listAccountsMock.mockResolvedValue([account('juan@bevel.software'), account('bo@bevel.software')]);
207
- const { input } = mountDialog();
413
+ const { input } = await mountDialog();
208
414
  await userEvent.type(input, 'ana@bevel.software{Enter}bo@bevel.software{Enter}');
209
- await userEvent.selectOptions(screen.getByLabelText('Invite as'), 'admin');
210
- expect(screen.getByText('Can also change settings and who has access.')).toBeInTheDocument();
415
+ await userEvent.selectOptions(screen.getByLabelText('Role'), 'admin');
211
416
  await userEvent.click(screen.getByRole('button', { name: 'Invite 2 people' }));
212
417
 
213
418
  await screen.findByRole('dialog', { name: '2 people are invited' });
214
419
  expect(createAccountMock.mock.calls.map((c) => c[0])).toEqual(['ana@bevel.software']);
215
420
  expect(addMemberMock.mock.calls).toEqual([
216
- ['admin', 'ana@bevel.software'],
217
- ['admin', 'bo@bevel.software'],
421
+ ['admin', 'ana@bevel.software', ACTIVE],
422
+ ['admin', 'bo@bevel.software', ACTIVE],
218
423
  ]);
219
- const bo = within(screen.getByRole('list', { name: 'People' })).getByText('bo@bevel.software').closest('li')!;
220
- expect(within(bo).getByText('Can sign in already, now an admin')).toBeInTheDocument();
424
+ expect(within(rowOf('bo@bevel.software')).getByText('Signs in with Duende Demo, now an admin')).toBeInTheDocument();
221
425
  });
222
426
 
223
427
  it('leaves an existing admin as they are when invited as Admin', async () => {
224
428
  listAccountsMock.mockResolvedValue([account('juan@bevel.software'), account('bo@bevel.software')]);
225
429
  fetchRolesMock.mockResolvedValue([{ canonical: 'admin', members: ['juan@bevel.software', 'bo@bevel.software'] }]);
226
- const { input } = mountDialog();
430
+ const { input } = await mountDialog();
227
431
  await userEvent.type(input, 'bo@bevel.software{Enter}');
228
- await userEvent.selectOptions(screen.getByLabelText('Invite as'), 'admin');
432
+ await userEvent.selectOptions(screen.getByLabelText('Role'), 'admin');
229
433
  await userEvent.click(screen.getByRole('button', { name: 'Invite 1 person' }));
230
434
 
231
435
  await screen.findByRole('dialog', { name: '1 person is invited' });
232
436
  expect(addMemberMock).not.toHaveBeenCalled();
233
- expect(screen.getByText('Can sign in already, already an admin')).toBeInTheDocument();
437
+ expect(screen.getByText('Signs in with Duende Demo, already an admin')).toBeInTheDocument();
234
438
  });
235
439
 
236
440
  it('says "no seat left" on the row the deployment refused for want of a place', async () => {
237
441
  createAccountMock.mockImplementation(async (email) => {
238
442
  if (email === 'bo@bevel.software') throw new AccountRequestError('No seat left on this plan', 403, 'admission');
443
+ return {};
239
444
  });
240
- const { input, onInvited } = mountDialog();
445
+ const { input, onInvited } = await mountDialog();
241
446
  await userEvent.type(input, 'ana@bevel.software{Enter}bo@bevel.software{Enter}');
242
447
  await userEvent.click(screen.getByRole('button', { name: 'Invite 2 people' }));
243
448
 
244
449
  await screen.findByRole('dialog', { name: '1 person is invited' });
245
- const bo = screen.getByText('bo@bevel.software').closest('li')!;
450
+ const bo = rowOf('bo@bevel.software');
246
451
  expect(within(bo).getByText('Not invited: no seat left')).toBeInTheDocument();
247
452
  expect(within(bo).getByText('No seat left on this plan')).toBeInTheDocument();
248
453
  expect(onInvited).toHaveBeenCalledTimes(1);
@@ -250,7 +455,7 @@ describe('InviteDialog: sending', () => {
250
455
 
251
456
  it('reads a 403 that is not an admission refusal (the admin check) as an error, not "no seat left"', async () => {
252
457
  createAccountMock.mockRejectedValue(new AccountRequestError('Admins only', 403));
253
- const { input } = mountDialog();
458
+ const { input } = await mountDialog();
254
459
  await userEvent.type(input, 'ana@bevel.software{Enter}');
255
460
  await userEvent.click(screen.getByRole('button', { name: 'Invite 1 person' }));
256
461
 
@@ -263,25 +468,24 @@ describe('InviteDialog: sending', () => {
263
468
  it('does not claim a switched-off account can sign in, or count it as invited', async () => {
264
469
  listAccountsMock.mockResolvedValue([
265
470
  account('juan@bevel.software'),
266
- { ...account('bo@bevel.software'), deactivatedAt: '2026-09-01T00:00:00Z' },
471
+ account('bo@bevel.software', { deactivatedAt: '2026-09-01T00:00:00Z' }),
267
472
  ]);
268
- const { input, onInvited } = mountDialog();
473
+ const { input, onInvited } = await mountDialog();
269
474
  await userEvent.type(input, 'bo@bevel.software{Enter}');
270
475
  await userEvent.click(screen.getByRole('button', { name: 'Invite 1 person' }));
271
476
 
272
477
  await screen.findByRole('dialog', { name: 'Nobody was invited' });
273
478
  expect(createAccountMock).not.toHaveBeenCalled();
274
- const bo = screen.getByText('bo@bevel.software').closest('li')!;
479
+ const bo = rowOf('bo@bevel.software');
275
480
  expect(within(bo).getByText('Account switched off')).toBeInTheDocument();
276
481
  expect(within(bo).getByText('Can’t sign in until it’s switched on in User accounts')).toBeInTheDocument();
277
- expect(screen.queryByText(/Their accounts are ready/)).not.toBeInTheDocument();
278
482
  expect(screen.queryByText('Where they sign in')).not.toBeInTheDocument();
279
483
  expect(onInvited).not.toHaveBeenCalled();
280
484
  });
281
485
 
282
486
  it('shows any other refusal in the server’s words', async () => {
283
487
  createAccountMock.mockRejectedValue(new AccountRequestError('Invalid email', 400));
284
- const { input, onInvited } = mountDialog();
488
+ const { input, onInvited } = await mountDialog();
285
489
  await userEvent.type(input, 'ana@bevel.software{Enter}');
286
490
  await userEvent.click(screen.getByRole('button', { name: 'Invite 1 person' }));
287
491
 
@@ -292,17 +496,18 @@ describe('InviteDialog: sending', () => {
292
496
  expect(onInvited).not.toHaveBeenCalled();
293
497
  });
294
498
 
295
- it('hands over the sign-in link and a message to forward, and copies them', async () => {
296
- const { input } = mountDialog();
499
+ it('with single sign-on and no password, names the provider in the message, with no password reminder', async () => {
500
+ const { input } = await mountDialog();
297
501
  await userEvent.type(input, 'ana@bevel.software{Enter}');
298
502
  await userEvent.click(screen.getByRole('button', { name: 'Invite 1 person' }));
299
503
  await screen.findByRole('dialog', { name: '1 person is invited' });
300
504
 
301
505
  const origin = window.location.origin;
302
506
  expect(screen.getByText(origin)).toBeInTheDocument();
303
- expect(screen.getByText(/Sign in with your work account at/)).toHaveTextContent(
304
- `Sign in with your work account at ${origin}, then connect your agent from the welcome page.`,
507
+ expect(screen.getByText(/^I’ve added you to/)).toHaveTextContent(
508
+ `Sign in at ${origin} with Duende Demo, then connect your agent from the welcome page.`,
305
509
  );
510
+ expect(screen.queryByText(/Send them the password you set/)).not.toBeInTheDocument();
306
511
 
307
512
  await userEvent.click(screen.getByRole('button', { name: 'Copy link' }));
308
513
  expect(copyMock).toHaveBeenCalledWith(origin);
@@ -315,7 +520,7 @@ describe('InviteDialog: sending', () => {
315
520
  });
316
521
 
317
522
  it('goes back to an empty form on "Invite more people"', async () => {
318
- const { input } = mountDialog();
523
+ const { input } = await mountDialog();
319
524
  await userEvent.type(input, 'ana@bevel.software{Enter}');
320
525
  await userEvent.click(screen.getByRole('button', { name: 'Invite 1 person' }));
321
526
  await userEvent.click(await screen.findByRole('button', { name: 'Invite more people' }));
@@ -324,69 +529,283 @@ describe('InviteDialog: sending', () => {
324
529
  });
325
530
  });
326
531
 
532
+ describe('InviteDialog: a starting password', () => {
533
+ /** The five cases of mock screen 05, on a deployment without single sign-on. */
534
+ async function sendFive(role: 'member' | 'admin' = 'member') {
535
+ providersMock.mockResolvedValue(PASSWORD_ONLY);
536
+ listAccountsMock.mockResolvedValue([
537
+ account('juan@bevel.software', { hasPassword: true }),
538
+ account('priya@acme.com'),
539
+ account('sam@acme.com', { hasPassword: true }),
540
+ account('olga@acme.com', { deactivatedAt: '2026-09-01T00:00:00Z' }),
541
+ ]);
542
+ const view = await mountDialog();
543
+ fireEvent.paste(view.input, {
544
+ clipboardData: { getData: () => 'lena@acme.com, tom@acme.com, priya@acme.com, sam@acme.com, olga@acme.com' },
545
+ });
546
+ if (role === 'admin') await userEvent.selectOptions(screen.getByLabelText('Role'), 'admin');
547
+ await userEvent.type(passwordField(), SECRET);
548
+ await userEvent.click(screen.getByRole('button', { name: 'Invite 5 people' }));
549
+ await screen.findByRole('dialog', { name: '4 people are invited' });
550
+ return view;
551
+ }
552
+
553
+ it('is given to every new account and to an existing one with none; never to one with its own or one switched off', async () => {
554
+ const { onInvited } = await sendFive();
555
+ expect(createAccountMock.mock.calls).toEqual([
556
+ ['lena@acme.com', '', SECRET, KEEP],
557
+ ['tom@acme.com', '', SECRET, KEEP],
558
+ ['priya@acme.com', '', SECRET, KEEP],
559
+ ]);
560
+ expect(onInvited).toHaveBeenCalledTimes(1);
561
+
562
+ expect(within(rowOf('lena@acme.com')).getByText('Member · signs in with the password you set')).toBeInTheDocument();
563
+ expect(within(rowOf('tom@acme.com')).getByText('Member · signs in with the password you set')).toBeInTheDocument();
564
+ expect(within(rowOf('priya@acme.com')).getByText('Had no password: now uses the one you set')).toBeInTheDocument();
565
+ expect(within(rowOf('sam@acme.com')).getByText('Signs in with their own password (unchanged)')).toBeInTheDocument();
566
+ expect(within(rowOf('olga@acme.com')).getByText('Account switched off')).toBeInTheDocument();
567
+ expect(screen.getByText('They can sign in now. Send them the link and the password.')).toBeInTheDocument();
568
+ });
569
+
570
+ it('is given to Admin invites alike, and they are made admins as before — the switched-off one left unchanged', async () => {
571
+ await sendFive('admin');
572
+ expect(createAccountMock.mock.calls.map((c) => c[2])).toEqual([SECRET, SECRET, SECRET]);
573
+ expect(addMemberMock.mock.calls.map((c) => c[1])).toEqual([
574
+ 'lena@acme.com',
575
+ 'tom@acme.com',
576
+ 'priya@acme.com',
577
+ 'sam@acme.com',
578
+ ]);
579
+ expect(within(rowOf('olga@acme.com')).getByText('Account switched off')).toBeInTheDocument();
580
+ expect(within(rowOf('lena@acme.com')).getByText('Admin · signs in with the password you set')).toBeInTheDocument();
581
+ });
582
+
583
+ it('says to send the password separately, and the message says to change it — without ever holding it', async () => {
584
+ await sendFive();
585
+ // Four were invited and three got the password (sam kept their own), so
586
+ // the reminder names who it is for rather than "them".
587
+ const reminder = screen.getByText('Send the password you set, separately, to the 3 people whose row says they use it.');
588
+ expect(reminder.parentElement).toHaveTextContent(
589
+ 'It isn’t in the message below, so the message is safe to post in a shared channel.',
590
+ );
591
+ const origin = window.location.origin;
592
+ const message = screen.getByText(/^I’ve added you to/);
593
+ // Above the message.
594
+ expect(reminder.compareDocumentPosition(message) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
595
+ expect(message).toHaveTextContent(
596
+ `Sign in at ${origin} with your work email and the password I’ll send you separately. Then change it on your Account page and connect your agent from the welcome page.`,
597
+ );
598
+
599
+ await userEvent.click(screen.getByRole('button', { name: 'Copy message' }));
600
+ await userEvent.click(screen.getByRole('button', { name: 'Copy link' }));
601
+ expect(copyMock).toHaveBeenCalledTimes(2);
602
+ for (const [text] of copyMock.mock.calls) expect(text).not.toContain(SECRET);
603
+
604
+ // Not shown again, and not kept in the browser.
605
+ expect(document.body.textContent).not.toContain(SECRET);
606
+ expect(screen.queryByLabelText('Starting password')).not.toBeInTheDocument();
607
+ expect(JSON.stringify({ ...localStorage })).not.toContain(SECRET);
608
+ expect(JSON.stringify({ ...sessionStorage })).not.toContain(SECRET);
609
+ });
610
+
611
+ it('is never logged', async () => {
612
+ const spies = (['log', 'info', 'warn', 'error', 'debug'] as const).map((m) =>
613
+ vi.spyOn(console, m).mockImplementation(() => {}),
614
+ );
615
+ await sendFive();
616
+ for (const spy of spies) {
617
+ for (const args of spy.mock.calls) expect(JSON.stringify(args)).not.toContain(SECRET);
618
+ spy.mockRestore();
619
+ }
620
+ });
621
+
622
+ it('"Invite more people" clears the password and the option', async () => {
623
+ const { input } = await mountDialog();
624
+ await userEvent.type(input, 'ana@bevel.software{Enter}');
625
+ await userEvent.click(screen.getByLabelText('Also give them a password'));
626
+ await userEvent.type(passwordField(), SECRET);
627
+ await userEvent.click(screen.getByRole('button', { name: 'Invite 1 person' }));
628
+ await userEvent.click(await screen.findByRole('button', { name: 'Invite more people' }));
629
+
630
+ expect(screen.getByLabelText('Also give them a password')).not.toBeChecked();
631
+ expect(screen.queryByLabelText('Starting password')).not.toBeInTheDocument();
632
+ await userEvent.click(screen.getByLabelText('Also give them a password'));
633
+ expect(passwordField()).toHaveValue('');
634
+ });
635
+
636
+ it('without single sign-on, "Invite more people" leaves the password field empty', async () => {
637
+ await sendFive();
638
+ await userEvent.click(screen.getByRole('button', { name: 'Invite more people' }));
639
+ expect(passwordField()).toHaveValue('');
640
+ });
641
+
642
+ it('with single sign-on, names both ways in on the rows, the reminder and the message', async () => {
643
+ const { input } = await mountDialog();
644
+ await userEvent.type(input, 'lena@acme.com{Enter}');
645
+ await userEvent.click(screen.getByLabelText('Also give them a password'));
646
+ await userEvent.type(passwordField(), SECRET);
647
+ await userEvent.click(screen.getByRole('button', { name: 'Invite 1 person' }));
648
+ await screen.findByRole('dialog', { name: '1 person is invited' });
649
+
650
+ expect(createAccountMock).toHaveBeenCalledWith('lena@acme.com', '', SECRET, KEEP);
651
+ expect(within(rowOf('lena@acme.com')).getByText('Member · signs in with Duende Demo or password')).toBeInTheDocument();
652
+ expect(screen.getByText('Send them the password you set, separately.')).toBeInTheDocument();
653
+ expect(screen.getByText(/^I’ve added you to/)).toHaveTextContent(
654
+ `Sign in at ${window.location.origin} with Duende Demo, or with your work email and the password I’ll send you separately (change it on your Account page). Then connect your agent from the welcome page.`,
655
+ );
656
+ expect(document.body.textContent).not.toContain(SECRET);
657
+ });
658
+
659
+ it('without a password, gives nobody one — new or existing', async () => {
660
+ listAccountsMock.mockResolvedValue([account('priya@acme.com')]);
661
+ const { input } = await mountDialog();
662
+ await userEvent.type(input, 'lena@acme.com{Enter}priya@acme.com{Enter}');
663
+ await userEvent.click(screen.getByRole('button', { name: 'Invite 2 people' }));
664
+ await screen.findByRole('dialog', { name: '2 people are invited' });
665
+ expect(createAccountMock.mock.calls).toEqual([['lena@acme.com', '']]);
666
+ expect(screen.queryByText(/password you set, separately/)).not.toBeInTheDocument();
667
+ });
668
+
669
+ it('when setting it on an existing account fails, leaves that account as it was and gives the server’s reason', async () => {
670
+ providersMock.mockResolvedValue(PASSWORD_ONLY);
671
+ listAccountsMock.mockResolvedValue([account('priya@acme.com')]);
672
+ createAccountMock.mockImplementation(async (email) => {
673
+ if (email === 'priya@acme.com') throw new AccountRequestError('Password too common', 400);
674
+ return {};
675
+ });
676
+ const { input } = await mountDialog();
677
+ await userEvent.type(input, 'lena@acme.com{Enter}priya@acme.com{Enter}');
678
+ await userEvent.selectOptions(screen.getByLabelText('Role'), 'admin');
679
+ await userEvent.type(passwordField(), SECRET);
680
+ await userEvent.click(screen.getByRole('button', { name: 'Invite 2 people' }));
681
+ await screen.findByRole('dialog', { name: '1 person is invited' });
682
+
683
+ const priya = rowOf('priya@acme.com');
684
+ expect(within(priya).getByText('Password not set')).toBeInTheDocument();
685
+ expect(within(priya).getByText('Couldn’t set the password: Password too common')).toBeInTheDocument();
686
+ // Left as it was: not made an admin either.
687
+ expect(addMemberMock.mock.calls).toEqual([['admin', 'lena@acme.com', ACTIVE]]);
688
+ });
689
+
690
+ it('when setting it fails on an account that has single sign-on, still counts it as invited and says how it signs in', async () => {
691
+ listAccountsMock.mockResolvedValue([account('priya@acme.com')]);
692
+ createAccountMock.mockRejectedValue(new AccountRequestError('Password too common', 400));
693
+ const { input } = await mountDialog();
694
+ await userEvent.type(input, 'priya@acme.com{Enter}');
695
+ await userEvent.click(screen.getByLabelText('Also give them a password'));
696
+ await userEvent.type(passwordField(), SECRET);
697
+ await userEvent.click(screen.getByRole('button', { name: 'Invite 1 person' }));
698
+ await screen.findByRole('dialog', { name: '1 person is invited' });
699
+ expect(
700
+ within(rowOf('priya@acme.com')).getByText('Couldn’t set the password: Password too common · signs in with Duende Demo'),
701
+ ).toBeInTheDocument();
702
+ });
703
+
704
+ it('reports an account that got its own password after the list was read as keeping it', async () => {
705
+ providersMock.mockResolvedValue(PASSWORD_ONLY);
706
+ listAccountsMock.mockResolvedValue([account('priya@acme.com')]);
707
+ createAccountMock.mockResolvedValue({ passwordSet: false });
708
+ const { input } = await mountDialog();
709
+ await userEvent.type(input, 'priya@acme.com{Enter}');
710
+ await userEvent.type(passwordField(), SECRET);
711
+ await userEvent.click(screen.getByRole('button', { name: 'Invite 1 person' }));
712
+ await screen.findByRole('dialog', { name: '1 person is invited' });
713
+ expect(createAccountMock).toHaveBeenCalledWith('priya@acme.com', '', SECRET, KEEP);
714
+ expect(within(rowOf('priya@acme.com')).getByText('Signs in with their own password (unchanged)')).toBeInTheDocument();
715
+ expect(screen.queryByText(/password you set, separately/)).not.toBeInTheDocument();
716
+ });
717
+
718
+ it('when the account list cannot be read, sends nothing and offers Retry, keeping what was typed', async () => {
719
+ providersMock.mockResolvedValue(PASSWORD_ONLY);
720
+ listAccountsMock.mockRejectedValueOnce(new Error('Could not load accounts'));
721
+ const { input, onInvited } = await mountDialog();
722
+ await userEvent.type(input, 'lena@acme.com{Enter}');
723
+ await userEvent.type(passwordField(), SECRET);
724
+ await userEvent.click(screen.getByRole('button', { name: 'Invite 1 person' }));
725
+
726
+ expect(await screen.findByRole('alert')).toHaveTextContent(
727
+ 'Nothing was sent: couldn’t check who already has an account.',
728
+ );
729
+ expect(createAccountMock).not.toHaveBeenCalled();
730
+ expect(addMemberMock).not.toHaveBeenCalled();
731
+ expect(onInvited).not.toHaveBeenCalled();
732
+ expect(chips()).toEqual(['lena@acme.com']);
733
+ expect(passwordField()).toHaveValue(SECRET);
734
+
735
+ await userEvent.click(screen.getByRole('button', { name: 'Retry' }));
736
+ await screen.findByRole('dialog', { name: '1 person is invited' });
737
+ expect(createAccountMock).toHaveBeenCalledWith('lena@acme.com', '', SECRET, KEEP);
738
+ });
739
+ });
740
+
741
+ describe('InviteDialog: when the deployment emails the invite itself', () => {
742
+ async function sendTwo(notified: (string[] | undefined)[]) {
743
+ providersMock.mockResolvedValue(PASSWORD_ONLY);
744
+ listAccountsMock.mockResolvedValue([]);
745
+ for (const channels of notified) {
746
+ createAccountMock.mockResolvedValueOnce(channels ? { passwordSet: true, notified: channels } : { passwordSet: true });
747
+ }
748
+ const { input } = await mountDialog();
749
+ fireEvent.paste(input, { clipboardData: { getData: () => 'lena@acme.com, tom@acme.com' } });
750
+ await userEvent.type(passwordField(), SECRET);
751
+ await userEvent.click(screen.getByRole('button', { name: 'Invite 2 people' }));
752
+ await screen.findByRole('dialog', { name: '2 people are invited' });
753
+ }
754
+
755
+ it('says so on each row, asks only for the password to be sent, and offers no message to forward', async () => {
756
+ await sendTwo([['email'], ['email']]);
757
+ expect(within(rowOf('lena@acme.com')).getByText('Emailed · Member · signs in with the password you set')).toBeInTheDocument();
758
+ expect(within(rowOf('tom@acme.com')).getByText('Emailed · Member · signs in with the password you set')).toBeInTheDocument();
759
+ expect(screen.getByText('They have been emailed the link. Send them the password separately.')).toBeInTheDocument();
760
+ expect(screen.getByText(/Send them the password you set, separately/).closest('[role="status"]')).toHaveTextContent(
761
+ 'Send them the password you set, separately. It isn’t in the email they were sent.',
762
+ );
763
+ // The link is still there to copy; the message is not, the mail was it.
764
+ expect(screen.getByRole('button', { name: 'Copy link' })).toBeInTheDocument();
765
+ expect(screen.queryByRole('button', { name: 'Copy message' })).not.toBeInTheDocument();
766
+ expect(screen.queryByText(/^I’ve added you to/)).not.toBeInTheDocument();
767
+ });
768
+
769
+ it('keeps the message when somebody was not emailed, and says who was', async () => {
770
+ await sendTwo([['email'], undefined]);
771
+ expect(within(rowOf('lena@acme.com')).getByText('Emailed · Member · signs in with the password you set')).toBeInTheDocument();
772
+ expect(within(rowOf('tom@acme.com')).getByText('Member · signs in with the password you set')).toBeInTheDocument();
773
+ expect(screen.getByText('They can sign in now. Send them the link and the password.')).toBeInTheDocument();
774
+ expect(screen.getByRole('button', { name: 'Copy message' })).toBeInTheDocument();
775
+ });
776
+
777
+ it('without a password, the intro says the mail carried how to sign in', async () => {
778
+ providersMock.mockResolvedValue(SSO_AND_PASSWORD);
779
+ listAccountsMock.mockResolvedValue([]);
780
+ createAccountMock.mockResolvedValue({ notified: ['email'] });
781
+ const { input } = await mountDialog();
782
+ await userEvent.type(input, 'ana@acme.com{Enter}');
783
+ await userEvent.click(screen.getByRole('button', { name: 'Invite 1 person' }));
784
+ await screen.findByRole('dialog', { name: '1 person is invited' });
785
+ expect(within(rowOf('ana@acme.com')).getByText('Emailed · Member · signs in with Duende Demo')).toBeInTheDocument();
786
+ expect(screen.getByText('They have been emailed the link and how to sign in.')).toBeInTheDocument();
787
+ expect(screen.queryByRole('button', { name: 'Copy message' })).not.toBeInTheDocument();
788
+ expect(screen.queryByText(/Send them the password you set/)).not.toBeInTheDocument();
789
+ });
790
+ });
791
+
327
792
  describe('InviteDialog: the registry slot', () => {
328
793
  it('renders inviteExtras with the number of valid addresses entered', async () => {
329
794
  const Extras = ({ inviting }: { inviting: number }) => <p>Seats after invites: {inviting}</p>;
330
- const { input } = mountDialog(makeRegistry({ inviteExtras: Extras }));
795
+ const { input } = await mountDialog({ registry: makeRegistry({ inviteExtras: Extras }) });
331
796
  expect(screen.getByText('Seats after invites: 0')).toBeInTheDocument();
332
797
  await userEvent.type(input, 'ana@bevel.software{Enter}nope{Enter}bo@bevel.software');
333
798
  expect(screen.getByText('Seats after invites: 2')).toBeInTheDocument();
334
799
  });
335
800
 
336
- it('keeps the form when the slot throws', () => {
801
+ it('keeps the form when the slot throws', async () => {
337
802
  const consoleError = vi.spyOn(console, 'error').mockImplementation(() => {});
338
803
  const Broken = () => {
339
804
  throw new Error('boom');
340
805
  };
341
- mountDialog(makeRegistry({ inviteExtras: Broken }));
806
+ await mountDialog({ registry: makeRegistry({ inviteExtras: Broken }) });
342
807
  expect(screen.getByRole('alert')).toHaveTextContent('The invite panel couldn’t be shown.');
343
- expect(screen.getByLabelText('Work emails')).toBeInTheDocument();
808
+ expect(screen.getByLabelText('Emails')).toBeInTheDocument();
344
809
  consoleError.mockRestore();
345
810
  });
346
811
  });
347
-
348
- describe('InviteButton (toolbar)', () => {
349
- function mountButton(isAdmin: boolean, withProvider = true) {
350
- const button = <InviteButton />;
351
- render(
352
- <AuthContext.Provider value={authValue()}>
353
- <AdminContext.Provider value={adminValue(isAdmin)}>
354
- {withProvider ? <InviteDialogProvider>{button}</InviteDialogProvider> : button}
355
- </AdminContext.Provider>
356
- </AuthContext.Provider>,
357
- );
358
- }
359
-
360
- it('is offered to admins and opens the invite dialog', async () => {
361
- mountButton(true);
362
- await userEvent.click(screen.getByRole('button', { name: 'Invite' }));
363
- expect(screen.getByRole('dialog', { name: 'Invite your team' })).toBeInTheDocument();
364
- });
365
-
366
- it('is not offered to members', () => {
367
- mountButton(false);
368
- expect(screen.queryByRole('button', { name: 'Invite' })).not.toBeInTheDocument();
369
- });
370
-
371
- it('is not offered without a dialog to open', () => {
372
- mountButton(true, false);
373
- expect(screen.queryByRole('button', { name: 'Invite' })).not.toBeInTheDocument();
374
- });
375
-
376
- it('drops its word on a compact toolbar but keeps its name, and still opens the dialog', async () => {
377
- render(
378
- <AuthContext.Provider value={authValue()}>
379
- <AdminContext.Provider value={adminValue(true)}>
380
- <InviteDialogProvider>
381
- <InviteButton compact />
382
- </InviteDialogProvider>
383
- </AdminContext.Provider>
384
- </AuthContext.Provider>,
385
- );
386
- const button = screen.getByRole('button', { name: 'Invite' });
387
- // Exactly empty: the word is the accessible name, never on screen.
388
- expect(button.textContent).toBe('');
389
- await userEvent.click(button);
390
- expect(screen.getByRole('dialog', { name: 'Invite your team' })).toBeInTheDocument();
391
- });
392
- });