@madie/madie-design-system 1.2.103 → 1.2.105

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
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "name": "@madie/madie-design-system",
3
- "version": "1.2.103",
3
+ "version": "1.2.105",
4
4
  "description": "Shared style guide across the Madie program.",
5
5
  "main": "dist/index.js",
6
6
  "homepage": "https://github.com/MeasureAuthoringTool/madie-design-system",
7
+ "volta": {
8
+ "node": "20.20.2",
9
+ "npm": "10.9.9"
10
+ },
7
11
  "scripts": {
8
12
  "prepublishOnly": "npm run build",
9
13
  "build": "npm run clean && webpack-cli --progress --color --env production && npm run build-react",
@@ -7,6 +7,30 @@ import { render, screen } from "@testing-library/react";
7
7
  import dayjs from "dayjs";
8
8
 
9
9
  describe("DateField", () => {
10
+ it.each([true, false])(
11
+ "places required state on the native input when required is %s",
12
+ (required) => {
13
+ render(
14
+ <DateField
15
+ id="measurement-period-start"
16
+ label="Start Date"
17
+ required={required}
18
+ handleDateChange={jest.fn()}
19
+ inputProps={{ "aria-describedby": "date-help" }}
20
+ />
21
+ );
22
+
23
+ const input = screen.getByRole("textbox", { name: "Start Date" });
24
+ expect(input).toHaveAttribute("aria-required", String(required));
25
+ expect(input.required).toBe(required);
26
+ expect(input).toHaveAttribute("aria-describedby", "date-help");
27
+ expect(input).toHaveAttribute("placeholder", "MM/DD/YYYY");
28
+ expect(
29
+ screen.getByTestId("measurement-period-start")
30
+ ).not.toHaveAttribute("aria-required");
31
+ }
32
+ );
33
+
10
34
  it("DateField Exists", async () => {
11
35
  await act(async () => {
12
36
  const { findByText, getByDisplayValue } = render(
@@ -1,9 +1,105 @@
1
1
  import "@testing-library/jest-dom";
2
2
  import React from "react";
3
- import { render, fireEvent, waitFor, screen } from "@testing-library/react";
3
+ import { act, render, fireEvent, waitFor, screen } from "@testing-library/react";
4
+ import userEvent from "@testing-library/user-event";
4
5
  import MadieAlert from "../../components/MadieAlert";
6
+ import MinimizedAlert from "../../components/MinimizedAlert";
5
7
 
6
8
  describe("Madie Alert", () => {
9
+ it("supports minimizing and restoring alerts from a separate layout container", async () => {
10
+ const AlertLayout = () => {
11
+ const [minimizedAlerts, setMinimizedAlerts] = React.useState({});
12
+ const [errorCount, setErrorCount] = React.useState(0);
13
+
14
+ return (
15
+ <>
16
+ <header data-testid="page-header">
17
+ {Object.values(minimizedAlerts).some(Boolean) && (
18
+ <MinimizedAlert
19
+ errorCount={errorCount}
20
+ onClick={() => setMinimizedAlerts({})}
21
+ />
22
+ )}
23
+ </header>
24
+ <main data-testid="page-content">
25
+ <MadieAlert
26
+ minimizedAlerts={minimizedAlerts}
27
+ onMinimizedAlertsChange={(next, count) => {
28
+ setMinimizedAlerts(next);
29
+ setErrorCount(count);
30
+ }}
31
+ alerts={[
32
+ {
33
+ content: (
34
+ <ul>
35
+ <li>Error 1</li>
36
+ <li>Error 2</li>
37
+ </ul>
38
+ ),
39
+ alertProps: { "data-testid": "first-alert" },
40
+ },
41
+ {
42
+ content: (
43
+ <ul>
44
+ <li>Warning 1</li>
45
+ </ul>
46
+ ),
47
+ alertProps: { "data-testid": "second-alert" },
48
+ },
49
+ ]}
50
+ />
51
+ </main>
52
+ </>
53
+ );
54
+ };
55
+
56
+ render(<AlertLayout />);
57
+ expect(screen.queryByTestId("minimized-alert")).not.toBeInTheDocument();
58
+
59
+ fireEvent.click(screen.getByTestId("minimize-button-0"));
60
+ expect(screen.queryByTestId("first-alert")).not.toBeInTheDocument();
61
+ expect(screen.getByTestId("second-alert")).toBeInTheDocument();
62
+ expect(screen.getByTestId("page-header")).toContainElement(
63
+ screen.getByRole("button", { name: "Display Alerts (2)" })
64
+ );
65
+ expect(screen.getByTestId("page-content")).not.toContainElement(
66
+ screen.getByTestId("minimized-alert")
67
+ );
68
+
69
+ fireEvent.click(screen.getByTestId("minimize-button-1"));
70
+ expect(screen.queryByTestId("second-alert")).not.toBeInTheDocument();
71
+ const restoreButton = screen.getByRole("button", {
72
+ name: "Display Alerts (3)",
73
+ });
74
+ await act(async () => {
75
+ restoreButton.focus();
76
+ userEvent.keyboard("{Enter}");
77
+ });
78
+
79
+ expect(screen.getByTestId("first-alert")).toBeInTheDocument();
80
+ expect(screen.getByTestId("second-alert")).toBeInTheDocument();
81
+ expect(screen.queryByTestId("minimized-alert")).not.toBeInTheDocument();
82
+ });
83
+
84
+ it("renders the standalone restore control without a count or page positioning", async () => {
85
+ const onClick = jest.fn();
86
+ render(<MinimizedAlert onClick={onClick} />);
87
+
88
+ const restoreButton = screen.getByRole("button", {
89
+ name: "Display Alerts",
90
+ });
91
+ expect(restoreButton).toHaveAttribute("type", "button");
92
+ expect(restoreButton).not.toHaveStyle({ position: "absolute" });
93
+ expect(screen.getByTestId("minimized-alert-text")).not.toHaveTextContent(
94
+ "("
95
+ );
96
+ await act(async () => {
97
+ restoreButton.focus();
98
+ userEvent.keyboard(" ");
99
+ });
100
+ expect(onClick).toHaveBeenCalledTimes(1);
101
+ });
102
+
7
103
  it("It renders as expected with basic props and triggers on Close on click", async () => {
8
104
  const onClose = jest.fn();
9
105
  const { getByTestId } = render(
@@ -0,0 +1,33 @@
1
+ import React from "react";
2
+ import "@testing-library/jest-dom";
3
+ import { render, screen } from "@testing-library/react";
4
+ import MadieTooltip from "../../components/MadieTooltip";
5
+ import TooltipIcon from "../../components/MadieTooltipIcon";
6
+
7
+ describe("MadieTooltip sizing", () => {
8
+ it("scales the original artwork into a 24px SVG", () => {
9
+ const { container } = render(<TooltipIcon />);
10
+ const svg = container.querySelector("svg");
11
+ expect(svg).toHaveAttribute("width", "24");
12
+ expect(svg).toHaveAttribute("height", "24");
13
+ expect(svg).toHaveAttribute("viewBox", "0 0 14 14");
14
+ expect(svg.querySelector("clipPath rect")).toHaveAttribute("width", "14");
15
+ expect(svg.querySelector("clipPath rect")).toHaveAttribute("height", "14");
16
+ });
17
+
18
+ it("keeps the tooltip wrapper at 24px without flex shrinking", () => {
19
+ render(<MadieTooltip id="help-icon" title="Help" />);
20
+ expect(screen.getByRole("img", { name: "Help" })).toHaveStyle({
21
+ width: "24px",
22
+ height: "24px",
23
+ flexShrink: "0",
24
+ display: "inline-flex",
25
+ });
26
+ });
27
+
28
+ it("preserves explicit icon size overrides", () => {
29
+ const { container } = render(<TooltipIcon width={14} height={14} />);
30
+ expect(container.querySelector("svg")).toHaveAttribute("width", "14");
31
+ expect(container.querySelector("svg")).toHaveAttribute("height", "14");
32
+ });
33
+ });
@@ -42,6 +42,60 @@ beforeAll(() => {
42
42
  describe("RichTextEditor Component", () => {
43
43
  const mockOnChange = jest.fn();
44
44
 
45
+ it("renders valid default ARIA states without undefined attributes", () => {
46
+ render(
47
+ <RichTextEditor
48
+ id="test-editor"
49
+ label="Description"
50
+ content=""
51
+ onChange={mockOnChange}
52
+ />
53
+ );
54
+
55
+ const editor = screen.getByRole("textbox", { name: "Description" });
56
+ expect(editor).toHaveAttribute("aria-invalid", "false");
57
+ expect(editor).toHaveAttribute("aria-required", "false");
58
+ expect(editor).not.toHaveAttribute("aria-describedby");
59
+ });
60
+
61
+ it("updates ARIA states and helper text references when validation changes", async () => {
62
+ const props = {
63
+ id: "test-editor",
64
+ label: "Description",
65
+ content: "",
66
+ onChange: mockOnChange,
67
+ };
68
+ const { rerender } = render(<RichTextEditor {...props} />);
69
+
70
+ rerender(
71
+ <RichTextEditor
72
+ {...props}
73
+ required
74
+ error
75
+ helperText="This field is required."
76
+ />
77
+ );
78
+ const editor = screen.getByRole("textbox", { name: "Description" });
79
+ await waitFor(() => {
80
+ expect(editor).toHaveAttribute("aria-invalid", "true");
81
+ expect(editor).toHaveAttribute("aria-required", "true");
82
+ expect(editor).toHaveAttribute(
83
+ "aria-describedby",
84
+ "test-editor-helper-text"
85
+ );
86
+ });
87
+ expect(
88
+ document.getElementById("test-editor-helper-text")
89
+ ).toHaveTextContent("This field is required.");
90
+
91
+ rerender(<RichTextEditor {...props} error={false} required={false} />);
92
+ await waitFor(() => {
93
+ expect(editor).toHaveAttribute("aria-invalid", "false");
94
+ expect(editor).toHaveAttribute("aria-required", "false");
95
+ expect(editor).not.toHaveAttribute("aria-describedby");
96
+ });
97
+ });
98
+
45
99
  it("renders the RichTextEditor with label and content", () => {
46
100
  render(
47
101
  <RichTextEditor