@exegia/corpora-ui 0.6.0 → 0.8.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/dist-lib/components/blocks/auth/__tests__/linked-accounts-block.test.d.ts +1 -0
- package/dist-lib/components/blocks/auth/__tests__/onboarding-block.test.d.ts +1 -0
- package/dist-lib/components/blocks/auth/__tests__/passkey-manager-block.test.d.ts +1 -0
- package/dist-lib/components/blocks/auth/__tests__/passkey-sign-in-block.test.d.ts +1 -0
- package/dist-lib/components/blocks/auth/__tests__/signup-block.test.d.ts +1 -0
- package/dist-lib/components/blocks/auth/__tests__/update-password-block.test.d.ts +1 -0
- package/dist-lib/components/blocks/auth/linked-accounts-block.d.ts +30 -0
- package/dist-lib/components/blocks/auth/onboarding/profile-step.d.ts +19 -0
- package/dist-lib/components/blocks/auth/onboarding-block.d.ts +69 -0
- package/dist-lib/components/blocks/auth/passkey-manager-block.d.ts +38 -0
- package/dist-lib/components/blocks/auth/passkey-sign-in-block.d.ts +27 -0
- package/dist-lib/components/blocks/auth/signup-block.d.ts +16 -1
- package/dist-lib/components/blocks/auth/update-password-block.d.ts +28 -0
- package/dist-lib/components/composed/social-providers.d.ts +7 -0
- package/dist-lib/index.d.ts +5 -0
- package/dist-lib/index.js +1122 -392
- package/dist-lib/index.js.map +1 -1
- package/package.json +5 -1
- package/src/components/blocks/auth/__tests__/linked-accounts-block.test.tsx +110 -0
- package/src/components/blocks/auth/__tests__/onboarding-block.test.tsx +156 -0
- package/src/components/blocks/auth/__tests__/passkey-manager-block.test.tsx +131 -0
- package/src/components/blocks/auth/__tests__/passkey-sign-in-block.test.tsx +59 -0
- package/src/components/blocks/auth/__tests__/signup-block.test.tsx +176 -0
- package/src/components/blocks/auth/__tests__/update-password-block.test.tsx +95 -0
- package/src/components/blocks/auth/linked-accounts-block.tsx +223 -0
- package/src/components/blocks/auth/onboarding/profile-step.tsx +227 -0
- package/src/components/blocks/auth/onboarding-block.tsx +240 -0
- package/src/components/blocks/auth/passkey-manager-block.tsx +334 -0
- package/src/components/blocks/auth/passkey-sign-in-block.tsx +81 -0
- package/src/components/blocks/auth/signup-block.tsx +43 -10
- package/src/components/blocks/auth/update-password-block.tsx +157 -0
- package/src/components/composed/social-providers.tsx +3 -2
- package/src/index.ts +5 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exegia/corpora-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "shadcn-ready React UI library for the corpora manuscript-research apps.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -54,7 +54,11 @@
|
|
|
54
54
|
"@eslint/js": "^10",
|
|
55
55
|
"@fontsource-variable/figtree": "^5.3.0",
|
|
56
56
|
"@fontsource-variable/inter": "^5.3.0",
|
|
57
|
+
"@happy-dom/global-registrator": "^20.11.1",
|
|
57
58
|
"@tailwindcss/vite": "^4",
|
|
59
|
+
"@testing-library/dom": "^10.4.1",
|
|
60
|
+
"@testing-library/react": "^16.3.2",
|
|
61
|
+
"@testing-library/user-event": "^14.6.1",
|
|
58
62
|
"@types/bun": "^1.3.14",
|
|
59
63
|
"@types/node": "^24",
|
|
60
64
|
"@types/react": "^19",
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { describe, expect, mock, test } from "bun:test";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
LinkedAccountsBlock,
|
|
7
|
+
type LinkedIdentity,
|
|
8
|
+
} from "../linked-accounts-block";
|
|
9
|
+
|
|
10
|
+
const IDENTITIES: LinkedIdentity[] = [
|
|
11
|
+
{ id: "id-1", provider: "google", email: "reader@example.com" },
|
|
12
|
+
{ id: "id-2", provider: "github" },
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
describe("LinkedAccountsBlock", () => {
|
|
16
|
+
test("shows the loading row", () => {
|
|
17
|
+
render(<LinkedAccountsBlock loading />);
|
|
18
|
+
expect(screen.getByText("Loading connected accounts…")).toBeDefined();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("shows the empty state when nothing is connected", () => {
|
|
22
|
+
render(<LinkedAccountsBlock identities={[]} />);
|
|
23
|
+
expect(screen.getByText("No sign-in methods connected yet.")).toBeDefined();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("lists connected identities with their addresses", () => {
|
|
27
|
+
render(<LinkedAccountsBlock identities={IDENTITIES} />);
|
|
28
|
+
|
|
29
|
+
const list = screen.getByRole("list", { name: "Connected accounts" });
|
|
30
|
+
expect(list.querySelectorAll("li")).toHaveLength(2);
|
|
31
|
+
expect(screen.getByText("reader@example.com")).toBeDefined();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("offers only the providers that are not connected yet", () => {
|
|
35
|
+
render(
|
|
36
|
+
<LinkedAccountsBlock
|
|
37
|
+
identities={IDENTITIES}
|
|
38
|
+
providers={["google", "apple", "github"]}
|
|
39
|
+
/>,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
expect(screen.getByRole("button", { name: "Connect Apple" })).toBeDefined();
|
|
43
|
+
expect(screen.queryByRole("button", { name: "Connect Google" })).toBeNull();
|
|
44
|
+
expect(screen.queryByRole("button", { name: "Connect GitHub" })).toBeNull();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("connects a provider through onLink", async () => {
|
|
48
|
+
const user = userEvent.setup();
|
|
49
|
+
const onLink = mock(async () => {});
|
|
50
|
+
render(
|
|
51
|
+
<LinkedAccountsBlock
|
|
52
|
+
identities={IDENTITIES}
|
|
53
|
+
providers={["apple"]}
|
|
54
|
+
onLink={onLink}
|
|
55
|
+
/>,
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
await user.click(screen.getByRole("button", { name: "Connect Apple" }));
|
|
59
|
+
|
|
60
|
+
expect(onLink).toHaveBeenCalledWith("apple");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("disconnects an identity through onUnlink", async () => {
|
|
64
|
+
const user = userEvent.setup();
|
|
65
|
+
const onUnlink = mock(async () => {});
|
|
66
|
+
render(<LinkedAccountsBlock identities={IDENTITIES} onUnlink={onUnlink} />);
|
|
67
|
+
|
|
68
|
+
await user.click(screen.getByRole("button", { name: "Disconnect Google" }));
|
|
69
|
+
|
|
70
|
+
expect(onUnlink).toHaveBeenCalledWith("id-1");
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("guards the last remaining sign-in method", async () => {
|
|
74
|
+
const user = userEvent.setup();
|
|
75
|
+
const onUnlink = mock(async () => {});
|
|
76
|
+
render(
|
|
77
|
+
<LinkedAccountsBlock identities={[IDENTITIES[0]!]} onUnlink={onUnlink} />,
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const button = screen.getByRole("button", { name: "Disconnect Google" });
|
|
81
|
+
expect(button.hasAttribute("disabled")).toBe(true);
|
|
82
|
+
|
|
83
|
+
const note = screen.getByText(
|
|
84
|
+
"This is your only way to sign in, so it can't be disconnected.",
|
|
85
|
+
);
|
|
86
|
+
expect(button.getAttribute("aria-describedby")).toBe(note.id);
|
|
87
|
+
|
|
88
|
+
await user.click(button);
|
|
89
|
+
expect(onUnlink).not.toHaveBeenCalled();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test("surfaces a failing link as an error", async () => {
|
|
93
|
+
const user = userEvent.setup();
|
|
94
|
+
render(
|
|
95
|
+
<LinkedAccountsBlock
|
|
96
|
+
identities={IDENTITIES}
|
|
97
|
+
providers={["apple"]}
|
|
98
|
+
onLink={async () => {
|
|
99
|
+
throw new Error("That account is already linked elsewhere.");
|
|
100
|
+
}}
|
|
101
|
+
/>,
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
await user.click(screen.getByRole("button", { name: "Connect Apple" }));
|
|
105
|
+
|
|
106
|
+
expect((await screen.findByRole("alert")).textContent).toBe(
|
|
107
|
+
"That account is already linked elsewhere.",
|
|
108
|
+
);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { describe, expect, mock, test } from "bun:test";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
OnboardingBlock,
|
|
7
|
+
type OnboardingBlockProps,
|
|
8
|
+
type OnboardingStepConfig,
|
|
9
|
+
} from "../onboarding-block";
|
|
10
|
+
|
|
11
|
+
const STEPS: OnboardingStepConfig[] = [
|
|
12
|
+
{
|
|
13
|
+
id: "profile",
|
|
14
|
+
title: "Your profile",
|
|
15
|
+
fields: [
|
|
16
|
+
{ kind: "text", name: "display_name", label: "Display name", required: true },
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
id: "links",
|
|
21
|
+
title: "Your links",
|
|
22
|
+
fields: [
|
|
23
|
+
{ kind: "url", name: "website", label: "Website" },
|
|
24
|
+
{ kind: "checkbox", name: "newsletter", label: "Send me the newsletter" },
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
describe("OnboardingBlock", () => {
|
|
30
|
+
test("renders the declared steps as progress", () => {
|
|
31
|
+
render(<OnboardingBlock steps={STEPS} />);
|
|
32
|
+
|
|
33
|
+
const items = screen
|
|
34
|
+
.getByRole("navigation", { name: "Onboarding progress" })
|
|
35
|
+
.querySelectorAll("li");
|
|
36
|
+
expect(items).toHaveLength(2);
|
|
37
|
+
expect(items[0]?.getAttribute("aria-current")).toBe("step");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("blocks advance on a missing required field", async () => {
|
|
41
|
+
const user = userEvent.setup();
|
|
42
|
+
const onStepSubmit = mock(async () => {});
|
|
43
|
+
render(<OnboardingBlock steps={STEPS} onStepSubmit={onStepSubmit} />);
|
|
44
|
+
|
|
45
|
+
await user.click(screen.getByRole("button", { name: "Continue" }));
|
|
46
|
+
|
|
47
|
+
expect(await screen.findByText("Display name is required")).toBeDefined();
|
|
48
|
+
expect(onStepSubmit).not.toHaveBeenCalled();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("rejects a malformed URL", async () => {
|
|
52
|
+
const user = userEvent.setup();
|
|
53
|
+
render(<OnboardingBlock steps={STEPS} />);
|
|
54
|
+
|
|
55
|
+
await user.type(screen.getByLabelText("Display name"), "Ada");
|
|
56
|
+
await user.click(screen.getByRole("button", { name: "Continue" }));
|
|
57
|
+
|
|
58
|
+
await user.type(await screen.findByLabelText("Website"), "not-a-url");
|
|
59
|
+
await user.click(screen.getByRole("button", { name: "Finish" }));
|
|
60
|
+
|
|
61
|
+
expect(await screen.findByText("Enter a valid URL")).toBeDefined();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("walks the steps and reports the merged profile once", async () => {
|
|
65
|
+
const user = userEvent.setup();
|
|
66
|
+
const onStepSubmit =
|
|
67
|
+
mock<NonNullable<OnboardingBlockProps["onStepSubmit"]>>(async () => {});
|
|
68
|
+
const onComplete =
|
|
69
|
+
mock<NonNullable<OnboardingBlockProps["onComplete"]>>(async () => {});
|
|
70
|
+
render(
|
|
71
|
+
<OnboardingBlock
|
|
72
|
+
steps={STEPS}
|
|
73
|
+
onStepSubmit={onStepSubmit}
|
|
74
|
+
onComplete={onComplete}
|
|
75
|
+
/>,
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
await user.type(screen.getByLabelText("Display name"), "Ada");
|
|
79
|
+
await user.click(screen.getByRole("button", { name: "Continue" }));
|
|
80
|
+
|
|
81
|
+
await user.type(
|
|
82
|
+
await screen.findByLabelText("Website"),
|
|
83
|
+
"https://example.com",
|
|
84
|
+
);
|
|
85
|
+
await user.click(
|
|
86
|
+
screen.getByRole("checkbox", { name: "Send me the newsletter" }),
|
|
87
|
+
);
|
|
88
|
+
await user.click(screen.getByRole("button", { name: "Finish" }));
|
|
89
|
+
|
|
90
|
+
expect(onStepSubmit).toHaveBeenCalledTimes(2);
|
|
91
|
+
expect(onStepSubmit.mock.calls[0]).toEqual([
|
|
92
|
+
"profile",
|
|
93
|
+
{ display_name: "Ada" },
|
|
94
|
+
]);
|
|
95
|
+
expect(onComplete).toHaveBeenCalledTimes(1);
|
|
96
|
+
expect(onComplete.mock.calls[0]?.[0]).toEqual({
|
|
97
|
+
display_name: "Ada",
|
|
98
|
+
website: "https://example.com",
|
|
99
|
+
newsletter: true,
|
|
100
|
+
});
|
|
101
|
+
expect(await screen.findByText("You're all set")).toBeDefined();
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("restores drafts when navigating back", async () => {
|
|
105
|
+
const user = userEvent.setup();
|
|
106
|
+
render(<OnboardingBlock steps={STEPS} />);
|
|
107
|
+
|
|
108
|
+
await user.type(screen.getByLabelText("Display name"), "Ada");
|
|
109
|
+
await user.click(screen.getByRole("button", { name: "Continue" }));
|
|
110
|
+
|
|
111
|
+
const website = await screen.findByLabelText("Website");
|
|
112
|
+
await user.type(website, "https://example.com");
|
|
113
|
+
await user.click(screen.getByRole("button", { name: "Back" }));
|
|
114
|
+
|
|
115
|
+
expect(
|
|
116
|
+
((await screen.findByLabelText("Display name")) as HTMLInputElement).value,
|
|
117
|
+
).toBe("Ada");
|
|
118
|
+
|
|
119
|
+
await user.click(screen.getByRole("button", { name: "Continue" }));
|
|
120
|
+
expect(
|
|
121
|
+
((await screen.findByLabelText("Website")) as HTMLInputElement).value,
|
|
122
|
+
).toBe("https://example.com");
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test("keeps the user on the step when onStepSubmit rejects", async () => {
|
|
126
|
+
const user = userEvent.setup();
|
|
127
|
+
render(
|
|
128
|
+
<OnboardingBlock
|
|
129
|
+
steps={STEPS}
|
|
130
|
+
onStepSubmit={async () => {
|
|
131
|
+
throw new Error("Saving your profile was rejected.");
|
|
132
|
+
}}
|
|
133
|
+
/>,
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
await user.type(screen.getByLabelText("Display name"), "Ada");
|
|
137
|
+
await user.click(screen.getByRole("button", { name: "Continue" }));
|
|
138
|
+
|
|
139
|
+
expect((await screen.findByRole("alert")).textContent).toBe(
|
|
140
|
+
"Saving your profile was rejected.",
|
|
141
|
+
);
|
|
142
|
+
expect(screen.getByLabelText("Display name")).toBeDefined();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test("renders nothing after completion when the success screen is off", async () => {
|
|
146
|
+
const user = userEvent.setup();
|
|
147
|
+
const { container } = render(
|
|
148
|
+
<OnboardingBlock steps={[STEPS[0]!]} showCompleteScreen={false} />,
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
await user.type(screen.getByLabelText("Display name"), "Ada");
|
|
152
|
+
await user.click(screen.getByRole("button", { name: "Finish" }));
|
|
153
|
+
|
|
154
|
+
expect(container.innerHTML).toBe("");
|
|
155
|
+
});
|
|
156
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { describe, expect, mock, test } from "bun:test";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
PasskeyManagerBlock,
|
|
7
|
+
type PasskeyRecord,
|
|
8
|
+
} from "../passkey-manager-block";
|
|
9
|
+
|
|
10
|
+
const PASSKEYS: PasskeyRecord[] = [
|
|
11
|
+
{ id: "pk-1", name: "MacBook", createdAt: "2026-01-05T00:00:00.000Z" },
|
|
12
|
+
{ id: "pk-2", name: "iPhone", lastUsedAt: "2026-02-01T00:00:00.000Z" },
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
describe("PasskeyManagerBlock", () => {
|
|
16
|
+
test("explains itself when the device cannot use passkeys", () => {
|
|
17
|
+
render(<PasskeyManagerBlock available={false} passkeys={PASSKEYS} />);
|
|
18
|
+
|
|
19
|
+
expect(screen.getByText(/aren't available on this device/i)).toBeDefined();
|
|
20
|
+
expect(screen.queryByRole("list", { name: "Passkeys" })).toBeNull();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("shows the loading row", () => {
|
|
24
|
+
render(<PasskeyManagerBlock loading />);
|
|
25
|
+
expect(screen.getByText("Loading passkeys…")).toBeDefined();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("shows the empty state when nothing is registered", () => {
|
|
29
|
+
render(<PasskeyManagerBlock />);
|
|
30
|
+
expect(screen.getByText(/No passkeys registered yet/i)).toBeDefined();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("lists every passkey", () => {
|
|
34
|
+
render(<PasskeyManagerBlock passkeys={PASSKEYS} />);
|
|
35
|
+
|
|
36
|
+
const list = screen.getByRole("list", { name: "Passkeys" });
|
|
37
|
+
expect(list.querySelectorAll("li")).toHaveLength(2);
|
|
38
|
+
expect(screen.getByText("MacBook")).toBeDefined();
|
|
39
|
+
expect(screen.getByText("iPhone")).toBeDefined();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("registers a passkey through onRegister", async () => {
|
|
43
|
+
const user = userEvent.setup();
|
|
44
|
+
const onRegister = mock(async () => {});
|
|
45
|
+
render(<PasskeyManagerBlock onRegister={onRegister} />);
|
|
46
|
+
|
|
47
|
+
await user.click(screen.getByRole("button", { name: "Add a passkey" }));
|
|
48
|
+
|
|
49
|
+
expect(onRegister).toHaveBeenCalledTimes(1);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("rejects a rename outside 1-120 characters without calling onRename", async () => {
|
|
53
|
+
const user = userEvent.setup();
|
|
54
|
+
const onRename = mock(async () => {});
|
|
55
|
+
render(<PasskeyManagerBlock passkeys={PASSKEYS} onRename={onRename} />);
|
|
56
|
+
|
|
57
|
+
await user.click(screen.getByRole("button", { name: "Rename MacBook" }));
|
|
58
|
+
const input = await screen.findByLabelText("Passkey name");
|
|
59
|
+
await user.clear(input);
|
|
60
|
+
await user.click(screen.getByRole("button", { name: "Save" }));
|
|
61
|
+
|
|
62
|
+
expect(
|
|
63
|
+
await screen.findByText("Name must be between 1 and 120 characters."),
|
|
64
|
+
).toBeDefined();
|
|
65
|
+
expect(onRename).not.toHaveBeenCalled();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("submits a trimmed rename", async () => {
|
|
69
|
+
const user = userEvent.setup();
|
|
70
|
+
const onRename = mock(async () => {});
|
|
71
|
+
render(<PasskeyManagerBlock passkeys={PASSKEYS} onRename={onRename} />);
|
|
72
|
+
|
|
73
|
+
await user.click(screen.getByRole("button", { name: "Rename MacBook" }));
|
|
74
|
+
const input = await screen.findByLabelText("Passkey name");
|
|
75
|
+
await user.clear(input);
|
|
76
|
+
await user.type(input, " Work laptop ");
|
|
77
|
+
await user.click(screen.getByRole("button", { name: "Save" }));
|
|
78
|
+
|
|
79
|
+
expect(onRename).toHaveBeenCalledWith("pk-1", "Work laptop");
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("deletes only after confirmation", async () => {
|
|
83
|
+
const user = userEvent.setup();
|
|
84
|
+
const onDelete = mock(async () => {});
|
|
85
|
+
render(<PasskeyManagerBlock passkeys={PASSKEYS} onDelete={onDelete} />);
|
|
86
|
+
|
|
87
|
+
await user.click(screen.getByRole("button", { name: "Delete MacBook" }));
|
|
88
|
+
expect(onDelete).not.toHaveBeenCalled();
|
|
89
|
+
|
|
90
|
+
await user.click(
|
|
91
|
+
await screen.findByRole("button", { name: "Delete passkey" }),
|
|
92
|
+
);
|
|
93
|
+
expect(onDelete).toHaveBeenCalledWith("pk-1");
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("warns before deleting the last remaining passkey", async () => {
|
|
97
|
+
const user = userEvent.setup();
|
|
98
|
+
render(<PasskeyManagerBlock passkeys={[PASSKEYS[0]!]} />);
|
|
99
|
+
|
|
100
|
+
await user.click(screen.getByRole("button", { name: "Delete MacBook" }));
|
|
101
|
+
|
|
102
|
+
expect(await screen.findByText(/This is your last passkey/i)).toBeDefined();
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("does not warn while other passkeys remain", async () => {
|
|
106
|
+
const user = userEvent.setup();
|
|
107
|
+
render(<PasskeyManagerBlock passkeys={PASSKEYS} />);
|
|
108
|
+
|
|
109
|
+
await user.click(screen.getByRole("button", { name: "Delete MacBook" }));
|
|
110
|
+
await screen.findByRole("button", { name: "Delete passkey" });
|
|
111
|
+
|
|
112
|
+
expect(screen.queryByText(/This is your last passkey/i)).toBeNull();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test("surfaces a failing action as an error", async () => {
|
|
116
|
+
const user = userEvent.setup();
|
|
117
|
+
render(
|
|
118
|
+
<PasskeyManagerBlock
|
|
119
|
+
onRegister={async () => {
|
|
120
|
+
throw new Error("Passkey registration is disabled.");
|
|
121
|
+
}}
|
|
122
|
+
/>,
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
await user.click(screen.getByRole("button", { name: "Add a passkey" }));
|
|
126
|
+
|
|
127
|
+
expect((await screen.findByRole("alert")).textContent).toBe(
|
|
128
|
+
"Passkey registration is disabled.",
|
|
129
|
+
);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { describe, expect, mock, test } from "bun:test";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
|
|
5
|
+
import { PasskeySignInBlock } from "../passkey-sign-in-block";
|
|
6
|
+
|
|
7
|
+
describe("PasskeySignInBlock", () => {
|
|
8
|
+
test("renders nothing when passkeys are unavailable", () => {
|
|
9
|
+
const { container } = render(<PasskeySignInBlock available={false} />);
|
|
10
|
+
expect(container.innerHTML).toBe("");
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test("signs in through onSignIn", async () => {
|
|
14
|
+
const user = userEvent.setup();
|
|
15
|
+
const onSignIn = mock(async () => {});
|
|
16
|
+
render(<PasskeySignInBlock onSignIn={onSignIn} />);
|
|
17
|
+
|
|
18
|
+
await user.click(screen.getByRole("button", { name: /passkey/i }));
|
|
19
|
+
|
|
20
|
+
expect(onSignIn).toHaveBeenCalledTimes(1);
|
|
21
|
+
expect(screen.queryByRole("alert")).toBeNull();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("treats a cancelled prompt as a silent return to idle", async () => {
|
|
25
|
+
const user = userEvent.setup();
|
|
26
|
+
render(<PasskeySignInBlock onSignIn={async () => ({ cancelled: true })} />);
|
|
27
|
+
|
|
28
|
+
await user.click(screen.getByRole("button", { name: /passkey/i }));
|
|
29
|
+
|
|
30
|
+
expect(screen.queryByRole("alert")).toBeNull();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test("shows the error and the fallback hint on failure", async () => {
|
|
34
|
+
const user = userEvent.setup();
|
|
35
|
+
render(
|
|
36
|
+
<PasskeySignInBlock
|
|
37
|
+
onSignIn={async () => {
|
|
38
|
+
throw new Error("No passkey found for this account.");
|
|
39
|
+
}}
|
|
40
|
+
/>,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
await user.click(screen.getByRole("button", { name: /passkey/i }));
|
|
44
|
+
|
|
45
|
+
expect((await screen.findByRole("alert")).textContent).toBe(
|
|
46
|
+
"No passkey found for this account.",
|
|
47
|
+
);
|
|
48
|
+
expect(
|
|
49
|
+
await screen.findByText(
|
|
50
|
+
"You can still sign in with your other methods below.",
|
|
51
|
+
),
|
|
52
|
+
).toBeDefined();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("uses a custom label", () => {
|
|
56
|
+
render(<PasskeySignInBlock label="Use Face ID" />);
|
|
57
|
+
expect(screen.getByRole("button", { name: "Use Face ID" })).toBeDefined();
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { describe, expect, mock, test } from "bun:test";
|
|
2
|
+
import { render, screen, waitFor } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
|
|
6
|
+
import { SignupBlock } from "../signup-block";
|
|
7
|
+
|
|
8
|
+
const STRONG = "Str0ngPassword";
|
|
9
|
+
|
|
10
|
+
/** Fills every field, so only the terms checkbox stands between us and submit. */
|
|
11
|
+
async function fillForm(user: ReturnType<typeof userEvent.setup>) {
|
|
12
|
+
await user.type(screen.getByLabelText("Name"), "Ada Researcher");
|
|
13
|
+
await user.type(screen.getByLabelText("Email"), "ada@corpora.local");
|
|
14
|
+
await user.type(await screen.findByLabelText("Password"), STRONG);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Base UI renders a hidden native input beside the Checkbox root, so the box is
|
|
18
|
+
// queried by role and read from aria-checked (see CLAUDE.md).
|
|
19
|
+
const checkbox = () => screen.getByRole("checkbox");
|
|
20
|
+
|
|
21
|
+
describe("SignupBlock terms checkbox", () => {
|
|
22
|
+
test("owns the box when uncontrolled", async () => {
|
|
23
|
+
const user = userEvent.setup();
|
|
24
|
+
render(<SignupBlock />);
|
|
25
|
+
|
|
26
|
+
expect(checkbox().getAttribute("aria-checked")).toBe("false");
|
|
27
|
+
|
|
28
|
+
await user.click(checkbox());
|
|
29
|
+
await waitFor(() =>
|
|
30
|
+
expect(checkbox().getAttribute("aria-checked")).toBe("true"),
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("starts from defaultTermsChecked", () => {
|
|
35
|
+
render(<SignupBlock defaultTermsChecked />);
|
|
36
|
+
expect(checkbox().getAttribute("aria-checked")).toBe("true");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("reports changes through onTermsCheckedChange while uncontrolled", async () => {
|
|
40
|
+
const user = userEvent.setup();
|
|
41
|
+
const onChange = mock((checked: boolean) => checked);
|
|
42
|
+
render(<SignupBlock onTermsCheckedChange={onChange} />);
|
|
43
|
+
|
|
44
|
+
await user.click(checkbox());
|
|
45
|
+
expect(onChange).toHaveBeenCalledWith(true);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("defers to the owner when controlled", async () => {
|
|
49
|
+
const user = userEvent.setup();
|
|
50
|
+
const onChange = mock((checked: boolean) => checked);
|
|
51
|
+
render(<SignupBlock termsChecked={false} onTermsCheckedChange={onChange} />);
|
|
52
|
+
|
|
53
|
+
await user.click(checkbox());
|
|
54
|
+
|
|
55
|
+
// The click is reported, but the box only moves if the owner says so.
|
|
56
|
+
expect(onChange).toHaveBeenCalledWith(true);
|
|
57
|
+
expect(checkbox().getAttribute("aria-checked")).toBe("false");
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("lets an outside action tick the box and unblock submit", async () => {
|
|
61
|
+
const user = userEvent.setup();
|
|
62
|
+
const onSubmit = mock(async () => {});
|
|
63
|
+
|
|
64
|
+
// Stands in for a consumer's terms dialog: an "I agree" action that ticks
|
|
65
|
+
// the block's checkbox from outside it.
|
|
66
|
+
function Host() {
|
|
67
|
+
const [accepted, setAccepted] = React.useState(false);
|
|
68
|
+
return (
|
|
69
|
+
<>
|
|
70
|
+
<button type="button" onClick={() => setAccepted(true)}>
|
|
71
|
+
I agree
|
|
72
|
+
</button>
|
|
73
|
+
<SignupBlock
|
|
74
|
+
termsChecked={accepted}
|
|
75
|
+
onTermsCheckedChange={setAccepted}
|
|
76
|
+
onSubmit={onSubmit}
|
|
77
|
+
/>
|
|
78
|
+
</>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
render(<Host />);
|
|
82
|
+
|
|
83
|
+
await fillForm(user);
|
|
84
|
+
await user.click(await screen.findByRole("button", { name: "I agree" }));
|
|
85
|
+
await waitFor(() =>
|
|
86
|
+
expect(checkbox().getAttribute("aria-checked")).toBe("true"),
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
await user.click(screen.getByRole("button", { name: "Create account" }));
|
|
90
|
+
await waitFor(() => expect(onSubmit).toHaveBeenCalled());
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("still blocks submission while the controlled box is unticked", async () => {
|
|
94
|
+
const user = userEvent.setup();
|
|
95
|
+
const onSubmit = mock(async () => {});
|
|
96
|
+
render(<SignupBlock termsChecked={false} onSubmit={onSubmit} />);
|
|
97
|
+
|
|
98
|
+
await fillForm(user);
|
|
99
|
+
await user.click(screen.getByRole("button", { name: "Create account" }));
|
|
100
|
+
|
|
101
|
+
expect(await screen.findByRole("alert")).toHaveProperty(
|
|
102
|
+
"textContent",
|
|
103
|
+
"Please accept the terms to continue.",
|
|
104
|
+
);
|
|
105
|
+
expect(onSubmit).not.toHaveBeenCalled();
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe("SignupBlock field labelling", () => {
|
|
110
|
+
test("names every field, including the revealed password", async () => {
|
|
111
|
+
const user = userEvent.setup();
|
|
112
|
+
render(<SignupBlock />);
|
|
113
|
+
|
|
114
|
+
expect(screen.getByLabelText("Name")).toBeDefined();
|
|
115
|
+
expect(screen.getByLabelText("Email")).toBeDefined();
|
|
116
|
+
|
|
117
|
+
// The password field only appears once the email validates.
|
|
118
|
+
await user.type(screen.getByLabelText("Email"), "ada@corpora.local");
|
|
119
|
+
expect(await screen.findByLabelText("Password")).toBeDefined();
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test("gives each instance its own password id", async () => {
|
|
123
|
+
const user = userEvent.setup();
|
|
124
|
+
render(
|
|
125
|
+
<>
|
|
126
|
+
<SignupBlock showNameField={false} />
|
|
127
|
+
<SignupBlock showNameField={false} />
|
|
128
|
+
</>,
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
const emails = screen.getAllByLabelText("Email");
|
|
132
|
+
await user.type(emails[0], "ada@corpora.local");
|
|
133
|
+
await user.type(emails[1], "ben@corpora.local");
|
|
134
|
+
|
|
135
|
+
// Two blocks on one page must not collide on a hard-coded id, or the
|
|
136
|
+
// second label would point at the first block's input.
|
|
137
|
+
const passwords = await screen.findAllByLabelText("Password");
|
|
138
|
+
expect(passwords).toHaveLength(2);
|
|
139
|
+
expect(passwords[0].id).not.toBe(passwords[1].id);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// The terms link sits inside the consent <label>, and under happy-dom that
|
|
144
|
+
// nesting computes an empty accessible name — so it is queried by text rather
|
|
145
|
+
// than by role + name. It resolves normally in a browser.
|
|
146
|
+
const termsLink = () => screen.getByText("terms");
|
|
147
|
+
|
|
148
|
+
describe("SignupBlock termsComponent", () => {
|
|
149
|
+
test("renders the built-in terms link by default", async () => {
|
|
150
|
+
const user = userEvent.setup();
|
|
151
|
+
const onTerms = mock(() => {});
|
|
152
|
+
render(<SignupBlock onTerms={onTerms} />);
|
|
153
|
+
|
|
154
|
+
expect(termsLink().tagName).toBe("BUTTON");
|
|
155
|
+
await user.click(termsLink());
|
|
156
|
+
expect(onTerms).toHaveBeenCalled();
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test("swaps the link for the consumer's own node", () => {
|
|
160
|
+
render(
|
|
161
|
+
<SignupBlock
|
|
162
|
+
termsComponent={<button type="button">read the terms</button>}
|
|
163
|
+
/>,
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
expect(screen.getByText("read the terms")).toBeDefined();
|
|
167
|
+
expect(screen.queryByText("terms")).toBeNull();
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test("keeps the consent label around the replacement", () => {
|
|
171
|
+
render(<SignupBlock termsComponent={<span>our terms of use</span>} />);
|
|
172
|
+
|
|
173
|
+
expect(screen.getByText(/I agree to the/)).toBeDefined();
|
|
174
|
+
expect(screen.getByRole("checkbox")).toBeDefined();
|
|
175
|
+
});
|
|
176
|
+
});
|