@asnewyla/form 0.2.1 → 0.2.2

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.
@@ -0,0 +1,10 @@
1
+ import { UserEvent } from '@testing-library/user-event';
2
+
3
+ type FieldRole = 'textbox' | 'spinbutton';
4
+ declare function getFieldInput(name: string | RegExp, role?: FieldRole): HTMLElement;
5
+ declare function getSubmitButton(name?: string | RegExp): HTMLElement;
6
+ declare function submitForm(user: UserEvent, name?: string | RegExp): Promise<void>;
7
+ declare function getErrorSummary(): HTMLElement;
8
+ declare function queryErrorSummary(): HTMLElement | null;
9
+
10
+ export { getErrorSummary, getFieldInput, getSubmitButton, queryErrorSummary, submitForm };
@@ -0,0 +1,10 @@
1
+ import { UserEvent } from '@testing-library/user-event';
2
+
3
+ type FieldRole = 'textbox' | 'spinbutton';
4
+ declare function getFieldInput(name: string | RegExp, role?: FieldRole): HTMLElement;
5
+ declare function getSubmitButton(name?: string | RegExp): HTMLElement;
6
+ declare function submitForm(user: UserEvent, name?: string | RegExp): Promise<void>;
7
+ declare function getErrorSummary(): HTMLElement;
8
+ declare function queryErrorSummary(): HTMLElement | null;
9
+
10
+ export { getErrorSummary, getFieldInput, getSubmitButton, queryErrorSummary, submitForm };
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ var react = require('@testing-library/react');
4
+
5
+ // src/test-utils.ts
6
+ function getFieldInput(name, role = "textbox") {
7
+ return react.screen.getByRole(role, { name });
8
+ }
9
+ function getSubmitButton(name = "Save") {
10
+ return react.screen.getByRole("button", { name });
11
+ }
12
+ function submitForm(user, name = "Save") {
13
+ return user.click(getSubmitButton(name));
14
+ }
15
+ function getErrorSummary() {
16
+ return react.screen.getByRole("alert");
17
+ }
18
+ function queryErrorSummary() {
19
+ return react.screen.queryByRole("alert");
20
+ }
21
+
22
+ exports.getErrorSummary = getErrorSummary;
23
+ exports.getFieldInput = getFieldInput;
24
+ exports.getSubmitButton = getSubmitButton;
25
+ exports.queryErrorSummary = queryErrorSummary;
26
+ exports.submitForm = submitForm;
27
+ //# sourceMappingURL=test-utils.js.map
28
+ //# sourceMappingURL=test-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/test-utils.ts"],"names":["screen"],"mappings":";;;;;AAKO,SAAS,aAAA,CACd,IAAA,EACA,IAAA,GAAkB,SAAA,EACL;AACb,EAAA,OAAOA,YAAA,CAAO,SAAA,CAAU,IAAA,EAAM,EAAE,MAAM,CAAA;AACxC;AAEO,SAAS,eAAA,CAAgB,OAAwB,MAAA,EAAqB;AAC3E,EAAA,OAAOA,YAAA,CAAO,SAAA,CAAU,QAAA,EAAU,EAAE,MAAM,CAAA;AAC5C;AAEO,SAAS,UAAA,CACd,IAAA,EACA,IAAA,GAAwB,MAAA,EACT;AACf,EAAA,OAAO,IAAA,CAAK,KAAA,CAAM,eAAA,CAAgB,IAAI,CAAC,CAAA;AACzC;AAEO,SAAS,eAAA,GAA+B;AAC7C,EAAA,OAAOA,YAAA,CAAO,UAAU,OAAO,CAAA;AACjC;AAEO,SAAS,iBAAA,GAAwC;AACtD,EAAA,OAAOA,YAAA,CAAO,YAAY,OAAO,CAAA;AACnC","file":"test-utils.js","sourcesContent":["import { screen } from '@testing-library/react';\nimport type { UserEvent } from '@testing-library/user-event';\n\ntype FieldRole = 'textbox' | 'spinbutton';\n\nexport function getFieldInput(\n name: string | RegExp,\n role: FieldRole = 'textbox',\n): HTMLElement {\n return screen.getByRole(role, { name });\n}\n\nexport function getSubmitButton(name: string | RegExp = 'Save'): HTMLElement {\n return screen.getByRole('button', { name });\n}\n\nexport function submitForm(\n user: UserEvent,\n name: string | RegExp = 'Save',\n): Promise<void> {\n return user.click(getSubmitButton(name));\n}\n\nexport function getErrorSummary(): HTMLElement {\n return screen.getByRole('alert');\n}\n\nexport function queryErrorSummary(): HTMLElement | null {\n return screen.queryByRole('alert');\n}\n"]}
@@ -0,0 +1,22 @@
1
+ import { screen } from '@testing-library/react';
2
+
3
+ // src/test-utils.ts
4
+ function getFieldInput(name, role = "textbox") {
5
+ return screen.getByRole(role, { name });
6
+ }
7
+ function getSubmitButton(name = "Save") {
8
+ return screen.getByRole("button", { name });
9
+ }
10
+ function submitForm(user, name = "Save") {
11
+ return user.click(getSubmitButton(name));
12
+ }
13
+ function getErrorSummary() {
14
+ return screen.getByRole("alert");
15
+ }
16
+ function queryErrorSummary() {
17
+ return screen.queryByRole("alert");
18
+ }
19
+
20
+ export { getErrorSummary, getFieldInput, getSubmitButton, queryErrorSummary, submitForm };
21
+ //# sourceMappingURL=test-utils.mjs.map
22
+ //# sourceMappingURL=test-utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/test-utils.ts"],"names":[],"mappings":";;;AAKO,SAAS,aAAA,CACd,IAAA,EACA,IAAA,GAAkB,SAAA,EACL;AACb,EAAA,OAAO,MAAA,CAAO,SAAA,CAAU,IAAA,EAAM,EAAE,MAAM,CAAA;AACxC;AAEO,SAAS,eAAA,CAAgB,OAAwB,MAAA,EAAqB;AAC3E,EAAA,OAAO,MAAA,CAAO,SAAA,CAAU,QAAA,EAAU,EAAE,MAAM,CAAA;AAC5C;AAEO,SAAS,UAAA,CACd,IAAA,EACA,IAAA,GAAwB,MAAA,EACT;AACf,EAAA,OAAO,IAAA,CAAK,KAAA,CAAM,eAAA,CAAgB,IAAI,CAAC,CAAA;AACzC;AAEO,SAAS,eAAA,GAA+B;AAC7C,EAAA,OAAO,MAAA,CAAO,UAAU,OAAO,CAAA;AACjC;AAEO,SAAS,iBAAA,GAAwC;AACtD,EAAA,OAAO,MAAA,CAAO,YAAY,OAAO,CAAA;AACnC","file":"test-utils.mjs","sourcesContent":["import { screen } from '@testing-library/react';\nimport type { UserEvent } from '@testing-library/user-event';\n\ntype FieldRole = 'textbox' | 'spinbutton';\n\nexport function getFieldInput(\n name: string | RegExp,\n role: FieldRole = 'textbox',\n): HTMLElement {\n return screen.getByRole(role, { name });\n}\n\nexport function getSubmitButton(name: string | RegExp = 'Save'): HTMLElement {\n return screen.getByRole('button', { name });\n}\n\nexport function submitForm(\n user: UserEvent,\n name: string | RegExp = 'Save',\n): Promise<void> {\n return user.click(getSubmitButton(name));\n}\n\nexport function getErrorSummary(): HTMLElement {\n return screen.getByRole('alert');\n}\n\nexport function queryErrorSummary(): HTMLElement | null {\n return screen.queryByRole('alert');\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asnewyla/form",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Form wrapper with real validation and an accessible error summary",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -16,11 +16,16 @@
16
16
  "types": "dist/index.d.ts",
17
17
  "exports": {
18
18
  ".": {
19
+ "types": "./dist/index.d.ts",
19
20
  "import": "./dist/index.mjs",
20
- "require": "./dist/index.js",
21
- "types": "./dist/index.d.ts"
21
+ "require": "./dist/index.js"
22
22
  },
23
- "./styles.css": "./dist/index.css"
23
+ "./styles.css": "./dist/index.css",
24
+ "./test-utils": {
25
+ "types": "./dist/test-utils.d.ts",
26
+ "import": "./dist/test-utils.mjs",
27
+ "require": "./dist/test-utils.js"
28
+ }
24
29
  },
25
30
  "files": [
26
31
  "dist"
@@ -36,10 +41,20 @@
36
41
  ],
37
42
  "peerDependencies": {
38
43
  "react": "^18.0.0 || ^19.0.0",
39
- "react-dom": "^18.0.0 || ^19.0.0"
44
+ "react-dom": "^18.0.0 || ^19.0.0",
45
+ "@testing-library/react": "^16.0.0",
46
+ "@testing-library/user-event": "^14.5.0"
47
+ },
48
+ "peerDependenciesMeta": {
49
+ "@testing-library/react": {
50
+ "optional": true
51
+ },
52
+ "@testing-library/user-event": {
53
+ "optional": true
54
+ }
40
55
  },
41
56
  "dependencies": {
42
- "@asnewyla/input": "0.2.0"
57
+ "@asnewyla/input": "0.2.1"
43
58
  },
44
59
  "devDependencies": {
45
60
  "@testing-library/jest-dom": "^6.4.0",