@thepalaceproject/circulation-admin 1.36.0-post.2 → 1.36.0-post.4

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 CHANGED
@@ -152,5 +152,5 @@
152
152
  "*.{js,jsx,ts,tsx,css,md}": "prettier --write",
153
153
  "*.{js,css,md}": "prettier --write"
154
154
  },
155
- "version": "1.36.0-post.2"
155
+ "version": "1.36.0-post.4"
156
156
  }
@@ -0,0 +1,81 @@
1
+ import * as React from "react";
2
+ import { render, fireEvent } from "@testing-library/react";
3
+ import PasswordInput from "../../../src/components/PasswordInput";
4
+
5
+ describe("PasswordInput", () => {
6
+ it("defaults to type='password'", () => {
7
+ const { getByLabelText } = render(
8
+ <label>
9
+ PIN
10
+ <PasswordInput />
11
+ </label>
12
+ );
13
+ expect(getByLabelText("PIN")).toHaveAttribute("type", "password");
14
+ });
15
+
16
+ it("toggles to type='text' when show button is clicked", () => {
17
+ const { getByLabelText } = render(
18
+ <label>
19
+ PIN
20
+ <PasswordInput />
21
+ </label>
22
+ );
23
+ const input = getByLabelText("PIN");
24
+ const toggleBtn = getByLabelText("Show password");
25
+
26
+ fireEvent.click(toggleBtn);
27
+ expect(input).toHaveAttribute("type", "text");
28
+
29
+ fireEvent.click(getByLabelText("Hide password"));
30
+ expect(input).toHaveAttribute("type", "password");
31
+ });
32
+
33
+ it("has correct aria-label on toggle button", () => {
34
+ const { getByLabelText, queryByLabelText } = render(
35
+ <label>
36
+ PIN
37
+ <PasswordInput />
38
+ </label>
39
+ );
40
+
41
+ expect(getByLabelText("Show password")).toBeInTheDocument();
42
+ expect(queryByLabelText("Hide password")).not.toBeInTheDocument();
43
+
44
+ fireEvent.click(getByLabelText("Show password"));
45
+
46
+ expect(getByLabelText("Hide password")).toBeInTheDocument();
47
+ expect(queryByLabelText("Show password")).not.toBeInTheDocument();
48
+ });
49
+
50
+ it("passes through standard input props", () => {
51
+ const handleChange = jest.fn();
52
+ const { getByLabelText } = render(
53
+ <label>
54
+ PIN
55
+ <PasswordInput
56
+ id="test-pw"
57
+ className="form-control"
58
+ value="secret"
59
+ onChange={handleChange}
60
+ autoComplete="off"
61
+ />
62
+ </label>
63
+ );
64
+
65
+ const input = getByLabelText("PIN");
66
+ expect(input).toHaveAttribute("id", "test-pw");
67
+ expect(input).toHaveClass("form-control");
68
+ expect(input).toHaveAttribute("value", "secret");
69
+ expect(input).toHaveAttribute("autoComplete", "off");
70
+
71
+ fireEvent.change(input, { target: { value: "new-value" } });
72
+ expect(handleChange).toHaveBeenCalled();
73
+ });
74
+
75
+ it("renders the wrapper div with password-input-wrapper class", () => {
76
+ const { container } = render(<PasswordInput />);
77
+ expect(
78
+ container.querySelector(".password-input-wrapper")
79
+ ).toBeInTheDocument();
80
+ });
81
+ });