@exegia/corpora-ui 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/dist-lib/components/blocks/auth/__tests__/linked-accounts-block.test.d.ts +1 -0
  2. package/dist-lib/components/blocks/auth/__tests__/onboarding-block.test.d.ts +1 -0
  3. package/dist-lib/components/blocks/auth/__tests__/passkey-manager-block.test.d.ts +1 -0
  4. package/dist-lib/components/blocks/auth/__tests__/passkey-sign-in-block.test.d.ts +1 -0
  5. package/dist-lib/components/blocks/auth/__tests__/update-password-block.test.d.ts +1 -0
  6. package/dist-lib/components/blocks/auth/linked-accounts-block.d.ts +30 -0
  7. package/dist-lib/components/blocks/auth/onboarding/profile-step.d.ts +19 -0
  8. package/dist-lib/components/blocks/auth/onboarding-block.d.ts +69 -0
  9. package/dist-lib/components/blocks/auth/passkey-manager-block.d.ts +38 -0
  10. package/dist-lib/components/blocks/auth/passkey-sign-in-block.d.ts +27 -0
  11. package/dist-lib/components/blocks/auth/update-password-block.d.ts +28 -0
  12. package/dist-lib/components/composed/social-providers.d.ts +7 -0
  13. package/dist-lib/index.d.ts +5 -0
  14. package/dist-lib/index.js +1032 -312
  15. package/dist-lib/index.js.map +1 -1
  16. package/package.json +5 -1
  17. package/src/components/blocks/auth/__tests__/linked-accounts-block.test.tsx +110 -0
  18. package/src/components/blocks/auth/__tests__/onboarding-block.test.tsx +156 -0
  19. package/src/components/blocks/auth/__tests__/passkey-manager-block.test.tsx +131 -0
  20. package/src/components/blocks/auth/__tests__/passkey-sign-in-block.test.tsx +59 -0
  21. package/src/components/blocks/auth/__tests__/update-password-block.test.tsx +95 -0
  22. package/src/components/blocks/auth/linked-accounts-block.tsx +223 -0
  23. package/src/components/blocks/auth/onboarding/profile-step.tsx +227 -0
  24. package/src/components/blocks/auth/onboarding-block.tsx +240 -0
  25. package/src/components/blocks/auth/passkey-manager-block.tsx +334 -0
  26. package/src/components/blocks/auth/passkey-sign-in-block.tsx +81 -0
  27. package/src/components/blocks/auth/update-password-block.tsx +157 -0
  28. package/src/components/composed/social-providers.tsx +3 -2
  29. 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.6.0",
3
+ "version": "0.7.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,95 @@
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
+
5
+ import { UpdatePasswordBlock } from "../update-password-block";
6
+
7
+ const STRONG = "Str0ngPassword";
8
+
9
+ describe("UpdatePasswordBlock", () => {
10
+ test("gates the confirm field behind a strong new password", async () => {
11
+ const user = userEvent.setup();
12
+ render(<UpdatePasswordBlock />);
13
+
14
+ expect(screen.queryByLabelText("Confirm new password")).toBeNull();
15
+
16
+ await user.type(screen.getByLabelText("New password"), STRONG);
17
+
18
+ expect(
19
+ await screen.findByLabelText("Confirm new password"),
20
+ ).toBeDefined();
21
+ });
22
+
23
+ test("gates the submit button behind matching passwords", async () => {
24
+ const user = userEvent.setup();
25
+ render(<UpdatePasswordBlock />);
26
+
27
+ await user.type(screen.getByLabelText("New password"), STRONG);
28
+ await user.type(
29
+ await screen.findByLabelText("Confirm new password"),
30
+ "different",
31
+ );
32
+
33
+ expect(screen.queryByRole("button", { name: "Update password" })).toBeNull();
34
+ });
35
+
36
+ test("submits the new password and shows the success panel", async () => {
37
+ const user = userEvent.setup();
38
+ const onSubmit = mock(async () => {});
39
+ render(<UpdatePasswordBlock onSubmit={onSubmit} />);
40
+
41
+ await user.type(screen.getByLabelText("New password"), STRONG);
42
+ await user.type(
43
+ await screen.findByLabelText("Confirm new password"),
44
+ STRONG,
45
+ );
46
+ await user.click(
47
+ await screen.findByRole("button", { name: "Update password" }),
48
+ );
49
+
50
+ expect(onSubmit).toHaveBeenCalledWith({ password: STRONG });
51
+ expect(await screen.findByText("Password updated")).toBeDefined();
52
+ });
53
+
54
+ test("surfaces a rejection from onSubmit and stays on the form", async () => {
55
+ const user = userEvent.setup();
56
+ render(
57
+ <UpdatePasswordBlock
58
+ onSubmit={async () => {
59
+ throw new Error("Password was used recently.");
60
+ }}
61
+ />,
62
+ );
63
+
64
+ await user.type(screen.getByLabelText("New password"), STRONG);
65
+ await user.type(
66
+ await screen.findByLabelText("Confirm new password"),
67
+ STRONG,
68
+ );
69
+ await user.click(
70
+ await screen.findByRole("button", { name: "Update password" }),
71
+ );
72
+
73
+ const alert = await screen.findByRole("alert");
74
+ expect(alert.textContent).toBe("Password was used recently.");
75
+ expect(screen.queryByText("Password updated")).toBeNull();
76
+ });
77
+
78
+ test("flags a diverged confirmation, but not a prefix mid-typing", async () => {
79
+ const user = userEvent.setup();
80
+ render(<UpdatePasswordBlock />);
81
+
82
+ await user.type(screen.getByLabelText("New password"), STRONG);
83
+ const confirm = await screen.findByLabelText("Confirm new password");
84
+
85
+ await user.type(confirm, STRONG.slice(0, 4));
86
+ expect(screen.queryByRole("alert")).toBeNull();
87
+
88
+ await user.type(confirm, "X");
89
+ await waitFor(() => {
90
+ expect(screen.getByRole("alert").textContent).toBe(
91
+ "Passwords do not match.",
92
+ );
93
+ });
94
+ });
95
+ });