@bevel-software/platform-core-frontend 0.26.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.
- package/package.json +2 -2
- package/src/core/CoreAppShell.tsx +87 -25
- package/src/core/ProductName.tsx +49 -0
- package/src/core/__tests__/ProductName.test.tsx +46 -0
- package/src/core/__tests__/ShellRoutes.test.tsx +22 -0
- package/src/core/__tests__/core-contributions.test.ts +16 -0
- package/src/core/core-contributions.ts +17 -0
- package/src/core/maker-url.ts +30 -0
- package/src/core/registry.ts +78 -1
- package/src/index.css +23 -5
- package/src/index.ts +5 -0
- package/src/lib/__tests__/latest-request.test.ts +48 -0
- package/src/lib/latest-request.ts +45 -0
- package/src/modules/access/__tests__/ManageAccessDialog.no-sso-invite.test.tsx +222 -0
- package/src/modules/access/__tests__/ManageAccessDialog.proposal.test.tsx +1 -1
- package/src/modules/access/api.ts +19 -3
- package/src/modules/access/components/ManageAccessDialog.tsx +61 -8
- package/src/modules/admin/__tests__/AdminRolesPage.fixed-admin.test.tsx +16 -1
- package/src/modules/admin/__tests__/RolesCorruptedBanner.test.tsx +70 -0
- package/src/modules/admin/__tests__/UserAccountsPage.test.tsx +284 -39
- package/src/modules/admin/components/AdminRolesPage.tsx +13 -14
- package/src/modules/admin/components/RolesCorruptedBanner.tsx +9 -4
- package/src/modules/admin/components/UserAccountsPage.tsx +91 -107
- package/src/modules/admin/services/roles.api.ts +14 -1
- package/src/modules/auth/__tests__/LoginScreen.test.tsx +80 -5
- package/src/modules/auth/__tests__/sso-strict-probe.test.ts +66 -0
- package/src/modules/auth/components/LoginScreen.tsx +101 -73
- package/src/modules/auth/services/account.api.ts +59 -3
- package/src/modules/auth/services/sso.ts +30 -10
- package/src/modules/auth/state/use-sign-in-methods.ts +41 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +176 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +68 -0
- package/src/modules/change-requests/__tests__/ChangeRequestLink.test.tsx +182 -0
- package/src/modules/change-requests/__tests__/FileChangeBoxes.test.tsx +1 -1
- package/src/modules/change-requests/__tests__/readFileOnBranch.test.ts +79 -0
- package/src/modules/change-requests/components/ChangeBox.tsx +6 -1
- package/src/modules/change-requests/components/ChangeRequestDialog.tsx +45 -15
- package/src/modules/change-requests/components/ChangeRequestLink.tsx +151 -0
- package/src/modules/change-requests/components/CrFileTree.tsx +2 -1
- package/src/modules/change-requests/components/FileChangeBoxes.tsx +4 -2
- package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +6 -3
- package/src/modules/change-requests/services/change-requests.api.ts +15 -2
- package/src/modules/change-requests/utils/readFailure.ts +22 -0
- package/src/modules/embed/__tests__/EmbedLinkPage.test.tsx +74 -0
- package/src/modules/embed/__tests__/EmbedView.test.tsx +473 -0
- package/src/modules/embed/__tests__/embed-config.test.ts +128 -0
- package/src/modules/embed/__tests__/embed-host.test.ts +111 -0
- package/src/modules/embed/__tests__/mcp-app-view.test.ts +295 -0
- package/src/modules/embed/__tests__/mount.test.tsx +157 -0
- package/src/modules/embed/components/EmbedLinkPage.tsx +109 -0
- package/src/modules/embed/components/EmbedView.tsx +545 -0
- package/src/modules/embed/embed-config.ts +132 -0
- package/src/modules/embed/embed-host.ts +120 -0
- package/src/modules/embed/mount.tsx +80 -0
- package/src/modules/embed/services/embed-token.ts +22 -0
- package/src/modules/embed/services/embed.api.ts +158 -0
- package/src/modules/git/__tests__/BranchSwitcher.test.tsx +202 -4
- package/src/modules/git/__tests__/GitSyncFailedBanner.test.tsx +59 -1
- package/src/modules/git/__tests__/PullNeededBanner.test.tsx +39 -22
- package/src/modules/git/__tests__/useAutoPullUpdates.test.tsx +7 -2
- package/src/modules/git/branch-delete-menu-item.tsx +24 -0
- package/src/modules/git/components/BranchSwitcher.tsx +29 -5
- package/src/modules/git/components/GitSyncFailedBanner.tsx +53 -15
- package/src/modules/git/components/HistoryVersionPreview.tsx +5 -3
- package/src/modules/git/components/PullNeededBanner.tsx +15 -49
- package/src/modules/git/hooks/useAutoPullUpdates.ts +9 -5
- package/src/modules/git/index.ts +15 -0
- package/src/modules/git/services/__tests__/error-messages.test.ts +67 -0
- package/src/modules/git/services/__tests__/pull-failure.test.ts +36 -0
- package/src/modules/git/services/error-messages.ts +58 -1
- package/src/modules/git/services/pull-failure.ts +68 -0
- package/src/modules/git/state/branch-delete-confirm.ts +46 -0
- package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +1 -0
- package/src/modules/layout/__tests__/breakpoints.test.ts +7 -1
- package/src/modules/layout/breakpoints.ts +8 -0
- package/src/modules/library/__tests__/PluginExtras.test.tsx +9 -9
- package/src/modules/library/__tests__/PluginPage.test.tsx +8 -1
- package/src/modules/library/__tests__/SkillsTree.test.tsx +13 -4
- package/src/modules/library/components/LibraryPage.tsx +22 -0
- package/src/modules/library/components/PluginExtras.tsx +23 -6
- package/src/modules/library/components/PluginPage.tsx +6 -1
- package/src/modules/library/routes/LibraryRoutes.tsx +8 -7
- package/src/modules/library/services/plugins.api.ts +4 -1
- package/src/modules/library/state/plugins-revision.ts +28 -0
- package/src/modules/onboarding/__tests__/InviteButton.test.tsx +214 -0
- package/src/modules/onboarding/__tests__/agent-connection-api.test.ts +55 -0
- package/src/modules/onboarding/__tests__/creator-welcome.test.tsx +87 -82
- package/src/modules/onboarding/__tests__/first-page-prompt.test.ts +164 -0
- package/src/modules/onboarding/__tests__/get-started-column.test.tsx +1458 -0
- package/src/modules/onboarding/__tests__/invite-dialog.test.tsx +811 -0
- package/src/modules/onboarding/__tests__/invite-emails.test.ts +247 -0
- package/src/modules/onboarding/__tests__/onboarding.test.tsx +226 -193
- package/src/modules/onboarding/__tests__/starter-pack-card.test.tsx +136 -0
- package/src/modules/onboarding/components/CreatorWelcomePage.tsx +7 -11
- package/src/modules/onboarding/components/EmailChipsInput.tsx +138 -0
- package/src/modules/onboarding/components/GetStartedColumn.tsx +670 -0
- package/src/modules/onboarding/components/InviteButton.tsx +139 -0
- package/src/modules/onboarding/components/InviteDialog.tsx +741 -0
- package/src/modules/onboarding/components/RootLanding.tsx +8 -24
- package/src/modules/onboarding/components/StarterPackCard.tsx +98 -0
- package/src/modules/onboarding/components/WelcomePage.tsx +65 -154
- package/src/modules/onboarding/first-page-prompt.ts +123 -0
- package/src/modules/onboarding/invite-emails.ts +313 -0
- package/src/modules/onboarding/services/agent-connection.api.ts +53 -0
- package/src/modules/onboarding/services/starter-packs.api.ts +83 -0
- package/src/modules/onboarding/state/agent-connection.ts +167 -0
- package/src/modules/onboarding/state/invite-dialog.context.ts +35 -0
- package/src/modules/onboarding/state/invite-dialog.tsx +39 -0
- package/src/modules/onboarding/state/onboarding.ts +133 -59
- package/src/modules/onboarding/state/starter-packs.ts +169 -0
- package/src/modules/settings/settings-nav-items.tsx +8 -3
- package/src/modules/setup/__tests__/setup.first-run-storage.test.tsx +389 -0
- package/src/modules/setup/__tests__/setup.github.test.tsx +5 -5
- package/src/modules/setup/__tests__/setup.kept-draft.test.tsx +1 -1
- package/src/modules/setup/__tests__/setup.repository-change.test.tsx +1 -1
- package/src/modules/setup/__tests__/setup.repository.test.tsx +21 -21
- package/src/modules/setup/__tests__/setup.test.tsx +56 -15
- package/src/modules/setup/__tests__/useConnectionProbe.test.tsx +123 -0
- package/src/modules/setup/components/FirstRunStorage.tsx +560 -0
- package/src/modules/setup/components/SetupGate.tsx +46 -1
- package/src/modules/setup/components/SetupScreen.tsx +81 -84
- package/src/modules/setup/hooks/useConnectionProbe.ts +93 -0
- package/src/modules/setup/services/setup.api.ts +3 -3
- package/src/modules/setup/utils/suggested-branch.ts +27 -0
- package/src/modules/toolbar/commands/__tests__/actions.test.tsx +210 -0
- package/src/modules/toolbar/commands/actions.tsx +330 -0
- package/src/modules/toolbar/commands/command-menu.ts +44 -0
- package/src/modules/toolbar/commands/useCommandActions.ts +71 -0
- package/src/modules/toolbar/commands/useCommandShortcuts.ts +121 -0
- package/src/modules/toolbar/components/AppSwitcher.tsx +125 -22
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +1 -1
- package/src/modules/toolbar/components/ProfileMenu.tsx +9 -4
- package/src/modules/toolbar/components/SearchPalette.tsx +540 -0
- package/src/modules/toolbar/components/Toolbar.tsx +10 -0
- package/src/modules/toolbar/components/__tests__/AppSwitcher.test.tsx +230 -52
- package/src/modules/toolbar/components/__tests__/ProfileMenu.test.tsx +64 -0
- package/src/modules/toolbar/components/__tests__/SearchPalette.test.tsx +864 -0
- package/src/modules/toolbar/components/__tests__/Toolbar.test.tsx +57 -2
- package/src/modules/toolbar/search/__tests__/rank.test.ts +93 -0
- package/src/modules/toolbar/search/__tests__/sources.test.ts +131 -0
- package/src/modules/toolbar/search/rank.ts +111 -0
- package/src/modules/toolbar/search/sources.ts +169 -0
- package/src/modules/workflow/hooks/useFileLock.ts +10 -7
- package/src/modules/workflow/services/__tests__/lock.api.test.ts +41 -0
- package/src/modules/workflow/services/lock.api.ts +17 -2
- package/src/modules/workspace/__tests__/useWorkspaceState.test.ts +49 -1
- package/src/modules/workspace/components/EditorTabs.tsx +39 -15
- package/src/modules/workspace/components/FileExplorer.tsx +39 -6
- package/src/modules/workspace/components/FilePaneCard.tsx +6 -2
- package/src/modules/workspace/components/FileRoute.tsx +12 -7
- package/src/modules/workspace/components/FileViewer.tsx +271 -74
- package/src/modules/workspace/components/KbPageHeader.tsx +13 -6
- package/src/modules/workspace/components/__tests__/EditorTabs.test.tsx +88 -21
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +92 -4
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +23 -3
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +330 -6
- package/src/modules/workspace/components/__tests__/KbPageHeader.test.tsx +17 -2
- package/src/modules/workspace/components/renderers/DocxRenderer.tsx +11 -16
- package/src/modules/workspace/components/renderers/DownloadFileButton.tsx +6 -0
- package/src/modules/workspace/components/renderers/EmailRenderer.tsx +23 -21
- package/src/modules/workspace/components/renderers/ImageRenderer.tsx +13 -29
- package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +9 -2
- package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +8 -0
- package/src/modules/workspace/components/renderers/PdfRenderer.tsx +14 -19
- package/src/modules/workspace/components/renderers/PptxRenderer.tsx +11 -17
- package/src/modules/workspace/components/renderers/ToolRenderer.tsx +35 -7
- package/src/modules/workspace/components/renderers/XlsxRenderer.tsx +11 -17
- package/src/modules/workspace/components/renderers/__tests__/EmailRenderer.links.test.tsx +73 -0
- package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.scaffold.test.tsx +64 -0
- package/src/modules/workspace/components/renderers/__tests__/ToolRenderer.surface.test.tsx +82 -0
- package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +99 -0
- package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +129 -35
- package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +149 -0
- package/src/modules/workspace/components/renderers/__tests__/kbMarkdownLinkPolicy.test.tsx +100 -0
- package/src/modules/workspace/components/renderers/htmlSandbox.ts +76 -20
- package/src/modules/workspace/components/renderers/index.ts +26 -0
- package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +51 -1
- package/src/modules/workspace/components/renderers/rendererRawRead.ts +53 -0
- package/src/modules/workspace/components/renderers/rendererSurface.ts +109 -0
- package/src/modules/workspace/components/renderers/rendererWorkspace.ts +8 -2
- package/src/modules/workspace/hooks/__tests__/useCreatePage.test.ts +137 -0
- package/src/modules/workspace/hooks/__tests__/useKnowledgeWriteTarget.test.ts +302 -0
- package/src/modules/workspace/hooks/__tests__/useWorkspaceState.test.tsx +126 -21
- package/src/modules/workspace/hooks/useCreatePage.ts +206 -0
- package/src/modules/workspace/hooks/useKnowledgeWriteTarget.ts +238 -0
- package/src/modules/workspace/hooks/useWorkspaceImageResolver.ts +24 -7
- package/src/modules/workspace/hooks/useWorkspaceState.ts +42 -8
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +10 -0
- package/src/modules/workspace/routing/__tests__/md-links-parity.test.tsx +113 -0
- package/src/modules/workspace/routing/kb-routes.ts +66 -12
- package/src/modules/workspace/state/editable-page.ts +42 -0
- package/src/modules/workspace/state/workspace.context.ts +13 -4
- package/src/modules/workspace/utils/__tests__/display-file-name.test.ts +60 -0
- package/src/modules/workspace/utils/__tests__/fileTree.test.ts +75 -0
- package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +16 -0
- package/src/modules/workspace/utils/display-file-name.ts +102 -0
- package/src/modules/workspace/utils/fileTree.ts +49 -14
- package/src/modules/workspace/utils/treeConfirm.ts +15 -0
- package/src/shared/__tests__/no-builtin-confirm.test.ts +102 -0
- package/src/shared/components/ConfirmProvider.tsx +156 -0
- package/src/shared/components/Dialog.tsx +7 -0
- package/src/shared/components/__tests__/ConfirmProvider.test.tsx +198 -0
- package/src/shared/components/confirm-context.ts +94 -0
- package/src/shared/components/index.ts +3 -0
- package/src/modules/onboarding/components/WelcomeRoute.tsx +0 -57
- package/src/modules/onboarding/welcome-state.ts +0 -36
|
@@ -0,0 +1,811 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import { AuthContext } from '../../auth/state/auth.context';
|
|
5
|
+
import { authValue } from '../../library/__tests__/auth-harness';
|
|
6
|
+
import { AppRegistryContext, makeRegistry } from '../../../core/registry';
|
|
7
|
+
import { AccountRequestError, type AccountSummary } from '../../auth/services/account.api';
|
|
8
|
+
import type { LoginProviders } from '../../auth/services/sso';
|
|
9
|
+
import { InviteDialog } from '../components/InviteDialog';
|
|
10
|
+
import { InviteDialogProvider } from '../state/invite-dialog';
|
|
11
|
+
import { useInviteDialog } from '../state/invite-dialog.context';
|
|
12
|
+
import { splitEmails } from '../invite-emails';
|
|
13
|
+
|
|
14
|
+
/** Every invite promotion is sent `ifActive`: the server refuses a switched-off account at the write. */
|
|
15
|
+
const ACTIVE = { ifActive: true };
|
|
16
|
+
|
|
17
|
+
/**
|
|
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.
|
|
24
|
+
*/
|
|
25
|
+
|
|
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
|
+
);
|
|
44
|
+
|
|
45
|
+
vi.mock('../../../lib/api', () => ({ authFetch: vi.fn() }));
|
|
46
|
+
vi.mock('../../auth/services/account.api', async (importOriginal) => ({
|
|
47
|
+
...(await importOriginal<typeof import('../../auth/services/account.api')>()),
|
|
48
|
+
listAccounts: listAccountsMock,
|
|
49
|
+
createAccount: createAccountMock,
|
|
50
|
+
}));
|
|
51
|
+
vi.mock('../../admin/services/roles.api', async (importOriginal) => ({
|
|
52
|
+
...(await importOriginal<typeof import('../../admin/services/roles.api')>()),
|
|
53
|
+
addMember: addMemberMock,
|
|
54
|
+
fetchRoles: fetchRolesMock,
|
|
55
|
+
}));
|
|
56
|
+
vi.mock('../../auth/services/sso', async (importOriginal) => ({
|
|
57
|
+
...(await importOriginal<typeof import('../../auth/services/sso')>()),
|
|
58
|
+
fetchLoginProvidersStrict: providersMock,
|
|
59
|
+
}));
|
|
60
|
+
vi.mock('../../library/utils/clipboard', () => ({ copyToClipboard: copyMock }));
|
|
61
|
+
|
|
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 {
|
|
75
|
+
return {
|
|
76
|
+
id: email,
|
|
77
|
+
email,
|
|
78
|
+
name: email,
|
|
79
|
+
hasPassword: false,
|
|
80
|
+
isEnvAdmin: false,
|
|
81
|
+
isOwner: false,
|
|
82
|
+
ownerCanBeDeleted: false,
|
|
83
|
+
deactivatedAt: null,
|
|
84
|
+
isSystem: false,
|
|
85
|
+
createdAt: '2026-01-01T00:00:00Z',
|
|
86
|
+
...over,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
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
|
+
) {
|
|
94
|
+
const onInvited = vi.fn();
|
|
95
|
+
const onClose = vi.fn();
|
|
96
|
+
render(
|
|
97
|
+
<AppRegistryContext.Provider value={opts.registry ?? makeRegistry({})}>
|
|
98
|
+
<AuthContext.Provider value={authValue()}>
|
|
99
|
+
<InviteDialog open onClose={onClose} onInvited={onInvited} initialEmails={opts.initialEmails} />
|
|
100
|
+
</AuthContext.Provider>
|
|
101
|
+
</AppRegistryContext.Provider>,
|
|
102
|
+
);
|
|
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') };
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** The chips on screen, by the address each holds. */
|
|
112
|
+
function chips(): string[] {
|
|
113
|
+
return screen.queryAllByRole('button', { name: /^Remove / }).map((b) =>
|
|
114
|
+
b.getAttribute('aria-label')!.replace(/^Remove /, ''),
|
|
115
|
+
);
|
|
116
|
+
}
|
|
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
|
+
|
|
126
|
+
beforeEach(() => {
|
|
127
|
+
listAccountsMock.mockReset().mockResolvedValue([account('juan@bevel.software', { hasPassword: true })]);
|
|
128
|
+
createAccountMock.mockReset().mockResolvedValue({});
|
|
129
|
+
addMemberMock.mockReset().mockResolvedValue([]);
|
|
130
|
+
fetchRolesMock.mockReset().mockResolvedValue([{ canonical: 'admin', members: ['juan@bevel.software'] }]);
|
|
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();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
describe('splitEmails', () => {
|
|
140
|
+
it('splits on commas, semicolons and whitespace, lower-cases, and unwraps Name <address>', () => {
|
|
141
|
+
expect(splitEmails('A@x.io, b@x.io;c@x.io\nd@x.io')).toEqual(['a@x.io', 'b@x.io', 'c@x.io', 'd@x.io']);
|
|
142
|
+
expect(splitEmails('Ana Diaz <ana@x.io>; Bo <bo@x.io>')).toEqual(['ana@x.io', 'bo@x.io']);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('keeps a display name with a comma in it whole, quoted or not', () => {
|
|
146
|
+
expect(splitEmails('Doe, Jane <jane@example.com>')).toEqual(['jane@example.com']);
|
|
147
|
+
expect(splitEmails('Doe, Jane <jane@example.com>, Roe, Rick <rick@example.com>')).toEqual([
|
|
148
|
+
'jane@example.com',
|
|
149
|
+
'rick@example.com',
|
|
150
|
+
]);
|
|
151
|
+
expect(splitEmails('"Doe, Jane" <jane@example.com>; "Bo; Smith" <bo@example.com>')).toEqual([
|
|
152
|
+
'jane@example.com',
|
|
153
|
+
'bo@example.com',
|
|
154
|
+
]);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('keeps bare addresses beside named ones, and a mistyped one after the last of them', () => {
|
|
158
|
+
expect(splitEmails('ana@x.io, Doe, Jane <jane@x.io>, bo@x.io')).toEqual(['ana@x.io', 'jane@x.io', 'bo@x.io']);
|
|
159
|
+
expect(splitEmails('Doe, Jane <jane@x.io>, nope')).toEqual(['jane@x.io', 'nope']);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe('InviteDialog: the address field', () => {
|
|
164
|
+
it('makes a chip on Enter and on a comma', async () => {
|
|
165
|
+
const { input } = await mountDialog();
|
|
166
|
+
await userEvent.type(input, 'ana@bevel.software{Enter}');
|
|
167
|
+
await userEvent.type(input, 'bo@bevel.software,');
|
|
168
|
+
expect(chips()).toEqual(['ana@bevel.software', 'bo@bevel.software']);
|
|
169
|
+
expect(input).toHaveValue('');
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('turns a pasted list into chips at once, without duplicates', async () => {
|
|
173
|
+
const { input } = await mountDialog();
|
|
174
|
+
fireEvent.paste(input, {
|
|
175
|
+
clipboardData: { getData: () => 'ana@bevel.software, bo@bevel.software\nANA@bevel.software' },
|
|
176
|
+
});
|
|
177
|
+
expect(chips()).toEqual(['ana@bevel.software', 'bo@bevel.software']);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('takes the last chip back on Backspace in an empty field', async () => {
|
|
181
|
+
const { input } = await mountDialog();
|
|
182
|
+
await userEvent.type(input, 'ana@bevel.software{Enter}bo@bevel.software{Enter}');
|
|
183
|
+
await userEvent.type(input, '{Backspace}');
|
|
184
|
+
expect(chips()).toEqual(['ana@bevel.software']);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it('keeps an invalid address on screen in the danger tone, and does not count it', async () => {
|
|
188
|
+
const { input } = await mountDialog();
|
|
189
|
+
await userEvent.type(input, 'ana@bevel.software{Enter}not-an-address{Enter}');
|
|
190
|
+
const bad = screen.getByTitle('not-an-address is not an email address');
|
|
191
|
+
expect(bad).toHaveClass('text-danger');
|
|
192
|
+
expect(screen.getByText('One address isn’t valid and won’t be invited.')).toBeInTheDocument();
|
|
193
|
+
expect(screen.getByRole('button', { name: 'Invite 1 person' })).toBeEnabled();
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('counts an invalid address still in the field, which a send would clear unsent', async () => {
|
|
197
|
+
const { input } = await mountDialog();
|
|
198
|
+
await userEvent.type(input, 'ana@bevel.software{Enter}not-an-address');
|
|
199
|
+
expect(chips()).toEqual(['ana@bevel.software']);
|
|
200
|
+
expect(screen.getByText('One address isn’t valid and won’t be invited.')).toBeInTheDocument();
|
|
201
|
+
expect(screen.getByRole('button', { name: 'Invite 1 person' })).toBeEnabled();
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('turns a pasted Outlook recipient list into one chip per person', async () => {
|
|
205
|
+
const { input } = await mountDialog();
|
|
206
|
+
fireEvent.paste(input, {
|
|
207
|
+
clipboardData: { getData: () => 'Doe, Jane <jane@bevel.software>; Roe, Rick <rick@bevel.software>' },
|
|
208
|
+
});
|
|
209
|
+
expect(chips()).toEqual(['jane@bevel.software', 'rick@bevel.software']);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('can remove a chip with its button', async () => {
|
|
213
|
+
const { input } = await mountDialog();
|
|
214
|
+
await userEvent.type(input, 'ana@bevel.software{Enter}');
|
|
215
|
+
await userEvent.click(screen.getByRole('button', { name: 'Remove ana@bevel.software' }));
|
|
216
|
+
expect(chips()).toEqual([]);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('cannot send with no valid address', async () => {
|
|
220
|
+
const { input } = await mountDialog();
|
|
221
|
+
expect(screen.getByRole('button', { name: 'Invite people' })).toBeDisabled();
|
|
222
|
+
await userEvent.type(input, 'nope{Enter}');
|
|
223
|
+
expect(screen.getByRole('button', { name: 'Invite people' })).toBeDisabled();
|
|
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
|
+
});
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
describe('InviteDialog: sending', () => {
|
|
388
|
+
it('creates one account per valid address, in order, and reports who was already here', async () => {
|
|
389
|
+
listAccountsMock.mockResolvedValue([account('juan@bevel.software'), account('bo@bevel.software')]);
|
|
390
|
+
const { input, onInvited } = await mountDialog();
|
|
391
|
+
await userEvent.type(input, 'ana@bevel.software{Enter}bo@bevel.software{Enter}cy@bevel.software');
|
|
392
|
+
await userEvent.click(screen.getByRole('button', { name: 'Invite 3 people' }));
|
|
393
|
+
|
|
394
|
+
expect(await screen.findByRole('dialog', { name: '3 people are invited' })).toBeInTheDocument();
|
|
395
|
+
expect(createAccountMock.mock.calls).toEqual([
|
|
396
|
+
['ana@bevel.software', ''],
|
|
397
|
+
['cy@bevel.software', ''],
|
|
398
|
+
]);
|
|
399
|
+
expect(addMemberMock).not.toHaveBeenCalled();
|
|
400
|
+
expect(onInvited).toHaveBeenCalledTimes(1);
|
|
401
|
+
|
|
402
|
+
const people = within(screen.getByRole('list', { name: 'People' }));
|
|
403
|
+
expect(people.getByText('Juan Viera (you)')).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();
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
it('makes everyone invited as Admin an admin, new accounts and existing ones alike', async () => {
|
|
412
|
+
listAccountsMock.mockResolvedValue([account('juan@bevel.software'), account('bo@bevel.software')]);
|
|
413
|
+
const { input } = await mountDialog();
|
|
414
|
+
await userEvent.type(input, 'ana@bevel.software{Enter}bo@bevel.software{Enter}');
|
|
415
|
+
await userEvent.selectOptions(screen.getByLabelText('Role'), 'admin');
|
|
416
|
+
await userEvent.click(screen.getByRole('button', { name: 'Invite 2 people' }));
|
|
417
|
+
|
|
418
|
+
await screen.findByRole('dialog', { name: '2 people are invited' });
|
|
419
|
+
expect(createAccountMock.mock.calls.map((c) => c[0])).toEqual(['ana@bevel.software']);
|
|
420
|
+
expect(addMemberMock.mock.calls).toEqual([
|
|
421
|
+
['admin', 'ana@bevel.software', ACTIVE],
|
|
422
|
+
['admin', 'bo@bevel.software', ACTIVE],
|
|
423
|
+
]);
|
|
424
|
+
expect(within(rowOf('bo@bevel.software')).getByText('Signs in with Duende Demo, now an admin')).toBeInTheDocument();
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
it('leaves an existing admin as they are when invited as Admin', async () => {
|
|
428
|
+
listAccountsMock.mockResolvedValue([account('juan@bevel.software'), account('bo@bevel.software')]);
|
|
429
|
+
fetchRolesMock.mockResolvedValue([{ canonical: 'admin', members: ['juan@bevel.software', 'bo@bevel.software'] }]);
|
|
430
|
+
const { input } = await mountDialog();
|
|
431
|
+
await userEvent.type(input, 'bo@bevel.software{Enter}');
|
|
432
|
+
await userEvent.selectOptions(screen.getByLabelText('Role'), 'admin');
|
|
433
|
+
await userEvent.click(screen.getByRole('button', { name: 'Invite 1 person' }));
|
|
434
|
+
|
|
435
|
+
await screen.findByRole('dialog', { name: '1 person is invited' });
|
|
436
|
+
expect(addMemberMock).not.toHaveBeenCalled();
|
|
437
|
+
expect(screen.getByText('Signs in with Duende Demo, already an admin')).toBeInTheDocument();
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
it('says "no seat left" on the row the deployment refused for want of a place', async () => {
|
|
441
|
+
createAccountMock.mockImplementation(async (email) => {
|
|
442
|
+
if (email === 'bo@bevel.software') throw new AccountRequestError('No seat left on this plan', 403, 'admission');
|
|
443
|
+
return {};
|
|
444
|
+
});
|
|
445
|
+
const { input, onInvited } = await mountDialog();
|
|
446
|
+
await userEvent.type(input, 'ana@bevel.software{Enter}bo@bevel.software{Enter}');
|
|
447
|
+
await userEvent.click(screen.getByRole('button', { name: 'Invite 2 people' }));
|
|
448
|
+
|
|
449
|
+
await screen.findByRole('dialog', { name: '1 person is invited' });
|
|
450
|
+
const bo = rowOf('bo@bevel.software');
|
|
451
|
+
expect(within(bo).getByText('Not invited: no seat left')).toBeInTheDocument();
|
|
452
|
+
expect(within(bo).getByText('No seat left on this plan')).toBeInTheDocument();
|
|
453
|
+
expect(onInvited).toHaveBeenCalledTimes(1);
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
it('reads a 403 that is not an admission refusal (the admin check) as an error, not "no seat left"', async () => {
|
|
457
|
+
createAccountMock.mockRejectedValue(new AccountRequestError('Admins only', 403));
|
|
458
|
+
const { input } = await mountDialog();
|
|
459
|
+
await userEvent.type(input, 'ana@bevel.software{Enter}');
|
|
460
|
+
await userEvent.click(screen.getByRole('button', { name: 'Invite 1 person' }));
|
|
461
|
+
|
|
462
|
+
await screen.findByRole('dialog', { name: 'Nobody was invited' });
|
|
463
|
+
expect(screen.queryByText('Not invited: no seat left')).not.toBeInTheDocument();
|
|
464
|
+
expect(screen.getByText('Not invited')).toBeInTheDocument();
|
|
465
|
+
expect(screen.getByText('Admins only')).toBeInTheDocument();
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
it('does not claim a switched-off account can sign in, or count it as invited', async () => {
|
|
469
|
+
listAccountsMock.mockResolvedValue([
|
|
470
|
+
account('juan@bevel.software'),
|
|
471
|
+
account('bo@bevel.software', { deactivatedAt: '2026-09-01T00:00:00Z' }),
|
|
472
|
+
]);
|
|
473
|
+
const { input, onInvited } = await mountDialog();
|
|
474
|
+
await userEvent.type(input, 'bo@bevel.software{Enter}');
|
|
475
|
+
await userEvent.click(screen.getByRole('button', { name: 'Invite 1 person' }));
|
|
476
|
+
|
|
477
|
+
await screen.findByRole('dialog', { name: 'Nobody was invited' });
|
|
478
|
+
expect(createAccountMock).not.toHaveBeenCalled();
|
|
479
|
+
const bo = rowOf('bo@bevel.software');
|
|
480
|
+
expect(within(bo).getByText('Account switched off')).toBeInTheDocument();
|
|
481
|
+
expect(within(bo).getByText('Can’t sign in until it’s switched on in User accounts')).toBeInTheDocument();
|
|
482
|
+
expect(screen.queryByText('Where they sign in')).not.toBeInTheDocument();
|
|
483
|
+
expect(onInvited).not.toHaveBeenCalled();
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
it('shows any other refusal in the server’s words', async () => {
|
|
487
|
+
createAccountMock.mockRejectedValue(new AccountRequestError('Invalid email', 400));
|
|
488
|
+
const { input, onInvited } = await mountDialog();
|
|
489
|
+
await userEvent.type(input, 'ana@bevel.software{Enter}');
|
|
490
|
+
await userEvent.click(screen.getByRole('button', { name: 'Invite 1 person' }));
|
|
491
|
+
|
|
492
|
+
await screen.findByRole('dialog', { name: 'Nobody was invited' });
|
|
493
|
+
expect(screen.getByText('Not invited')).toBeInTheDocument();
|
|
494
|
+
expect(screen.getByText('Invalid email')).toBeInTheDocument();
|
|
495
|
+
expect(screen.queryByText('Where they sign in')).not.toBeInTheDocument();
|
|
496
|
+
expect(onInvited).not.toHaveBeenCalled();
|
|
497
|
+
});
|
|
498
|
+
|
|
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();
|
|
501
|
+
await userEvent.type(input, 'ana@bevel.software{Enter}');
|
|
502
|
+
await userEvent.click(screen.getByRole('button', { name: 'Invite 1 person' }));
|
|
503
|
+
await screen.findByRole('dialog', { name: '1 person is invited' });
|
|
504
|
+
|
|
505
|
+
const origin = window.location.origin;
|
|
506
|
+
expect(screen.getByText(origin)).toBeInTheDocument();
|
|
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.`,
|
|
509
|
+
);
|
|
510
|
+
expect(screen.queryByText(/Send them the password you set/)).not.toBeInTheDocument();
|
|
511
|
+
|
|
512
|
+
await userEvent.click(screen.getByRole('button', { name: 'Copy link' }));
|
|
513
|
+
expect(copyMock).toHaveBeenCalledWith(origin);
|
|
514
|
+
expect(await screen.findByRole('button', { name: 'Copied' })).toBeInTheDocument();
|
|
515
|
+
|
|
516
|
+
copyMock.mockResolvedValue(false);
|
|
517
|
+
await userEvent.click(screen.getByRole('button', { name: 'Copy message' }));
|
|
518
|
+
expect(copyMock).toHaveBeenLastCalledWith(expect.stringContaining('I’ve added you to'));
|
|
519
|
+
expect(await screen.findByText('Couldn’t copy: select the text and copy it yourself.')).toBeInTheDocument();
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
it('goes back to an empty form on "Invite more people"', async () => {
|
|
523
|
+
const { input } = await mountDialog();
|
|
524
|
+
await userEvent.type(input, 'ana@bevel.software{Enter}');
|
|
525
|
+
await userEvent.click(screen.getByRole('button', { name: 'Invite 1 person' }));
|
|
526
|
+
await userEvent.click(await screen.findByRole('button', { name: 'Invite more people' }));
|
|
527
|
+
expect(screen.getByRole('dialog', { name: 'Invite your team' })).toBeInTheDocument();
|
|
528
|
+
expect(chips()).toEqual([]);
|
|
529
|
+
});
|
|
530
|
+
});
|
|
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
|
+
|
|
792
|
+
describe('InviteDialog: the registry slot', () => {
|
|
793
|
+
it('renders inviteExtras with the number of valid addresses entered', async () => {
|
|
794
|
+
const Extras = ({ inviting }: { inviting: number }) => <p>Seats after invites: {inviting}</p>;
|
|
795
|
+
const { input } = await mountDialog({ registry: makeRegistry({ inviteExtras: Extras }) });
|
|
796
|
+
expect(screen.getByText('Seats after invites: 0')).toBeInTheDocument();
|
|
797
|
+
await userEvent.type(input, 'ana@bevel.software{Enter}nope{Enter}bo@bevel.software');
|
|
798
|
+
expect(screen.getByText('Seats after invites: 2')).toBeInTheDocument();
|
|
799
|
+
});
|
|
800
|
+
|
|
801
|
+
it('keeps the form when the slot throws', async () => {
|
|
802
|
+
const consoleError = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
803
|
+
const Broken = () => {
|
|
804
|
+
throw new Error('boom');
|
|
805
|
+
};
|
|
806
|
+
await mountDialog({ registry: makeRegistry({ inviteExtras: Broken }) });
|
|
807
|
+
expect(screen.getByRole('alert')).toHaveTextContent('The invite panel couldn’t be shown.');
|
|
808
|
+
expect(screen.getByLabelText('Emails')).toBeInTheDocument();
|
|
809
|
+
consoleError.mockRestore();
|
|
810
|
+
});
|
|
811
|
+
});
|