@proteinjs/user-ui 1.11.1 → 1.11.3

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 (59) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/index.d.ts +2 -0
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +3 -0
  5. package/dist/index.js.map +1 -1
  6. package/dist/src/auth/AuthApi.d.ts +5 -1
  7. package/dist/src/auth/AuthApi.d.ts.map +1 -1
  8. package/dist/src/auth/AuthApi.js +5 -1
  9. package/dist/src/auth/AuthApi.js.map +1 -1
  10. package/dist/src/auth/AuthFormFields.d.ts +18 -0
  11. package/dist/src/auth/AuthFormFields.d.ts.map +1 -0
  12. package/dist/src/auth/AuthFormFields.js +41 -0
  13. package/dist/src/auth/AuthFormFields.js.map +1 -0
  14. package/dist/src/auth/AuthTextField.d.ts +14 -2
  15. package/dist/src/auth/AuthTextField.d.ts.map +1 -1
  16. package/dist/src/auth/AuthTextField.js +5 -3
  17. package/dist/src/auth/AuthTextField.js.map +1 -1
  18. package/dist/src/auth/AuthValidation.d.ts +17 -4
  19. package/dist/src/auth/AuthValidation.d.ts.map +1 -1
  20. package/dist/src/auth/AuthValidation.js +41 -11
  21. package/dist/src/auth/AuthValidation.js.map +1 -1
  22. package/dist/src/pages/ForgotPassword.d.ts.map +1 -1
  23. package/dist/src/pages/ForgotPassword.js +26 -14
  24. package/dist/src/pages/ForgotPassword.js.map +1 -1
  25. package/dist/src/pages/Login.d.ts.map +1 -1
  26. package/dist/src/pages/Login.js +40 -14
  27. package/dist/src/pages/Login.js.map +1 -1
  28. package/dist/src/pages/PasswordReset.d.ts.map +1 -1
  29. package/dist/src/pages/PasswordReset.js +37 -17
  30. package/dist/src/pages/PasswordReset.js.map +1 -1
  31. package/dist/src/pages/Signup.d.ts.map +1 -1
  32. package/dist/src/pages/Signup.js +44 -21
  33. package/dist/src/pages/Signup.js.map +1 -1
  34. package/dist/test/authApi.test.js +12 -0
  35. package/dist/test/authApi.test.js.map +1 -1
  36. package/dist/test/authFormsReadTheirFields.test.d.ts +5 -0
  37. package/dist/test/authFormsReadTheirFields.test.d.ts.map +1 -0
  38. package/dist/test/authFormsReadTheirFields.test.js +595 -0
  39. package/dist/test/authFormsReadTheirFields.test.js.map +1 -0
  40. package/dist/test/authValidation.test.js +43 -8
  41. package/dist/test/authValidation.test.js.map +1 -1
  42. package/dist/test/forgotPasswordAnswer.test.d.ts +5 -0
  43. package/dist/test/forgotPasswordAnswer.test.d.ts.map +1 -0
  44. package/dist/test/forgotPasswordAnswer.test.js +143 -0
  45. package/dist/test/forgotPasswordAnswer.test.js.map +1 -0
  46. package/index.ts +4 -0
  47. package/package.json +2 -2
  48. package/src/auth/AuthApi.ts +7 -1
  49. package/src/auth/AuthFormFields.ts +35 -0
  50. package/src/auth/AuthTextField.tsx +23 -3
  51. package/src/auth/AuthValidation.ts +54 -15
  52. package/src/pages/ForgotPassword.tsx +23 -9
  53. package/src/pages/Login.tsx +27 -8
  54. package/src/pages/PasswordReset.tsx +22 -11
  55. package/src/pages/Signup.tsx +39 -16
  56. package/test/authApi.test.ts +7 -0
  57. package/test/authFormsReadTheirFields.test.tsx +369 -0
  58. package/test/authValidation.test.ts +49 -16
  59. package/test/forgotPasswordAnswer.test.tsx +69 -0
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @jest-environment jsdom
3
+ * @jest-environment-options {"customExportConditions": ["node", "node-addons"]}
4
+ *
5
+ * What a person sees after asking for a reset link: the door's own answer — the one sentence it
6
+ * gives for every address, with an account or without, throttled or not — never a claim that a
7
+ * mail was sent (the page cannot know, and must not seem to).
8
+ */
9
+ import React from 'react';
10
+ import { createRoot, Root } from 'react-dom/client';
11
+ import { act } from 'react-dom/test-utils';
12
+ import { forgotPasswordPage } from '../src/pages/ForgotPassword';
13
+
14
+ declare global {
15
+ // eslint-disable-next-line no-var
16
+ var IS_REACT_ACT_ENVIRONMENT: boolean;
17
+ }
18
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true;
19
+
20
+ const ONE_ANSWER = 'If that address has an account, a reset link is on its way.';
21
+
22
+ let container: HTMLDivElement;
23
+ let root: Root;
24
+
25
+ beforeEach(() => {
26
+ container = document.createElement('div');
27
+ document.body.appendChild(container);
28
+ root = createRoot(container);
29
+ });
30
+
31
+ afterEach(async () => {
32
+ await act(async () => root.unmount());
33
+ container.remove();
34
+ delete (global as any).fetch;
35
+ });
36
+
37
+ function type(input: HTMLInputElement, value: string) {
38
+ const setValue = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set;
39
+ setValue?.call(input, value);
40
+ input.dispatchEvent(new Event('input', { bubbles: true }));
41
+ }
42
+
43
+ async function askForALink(email: string) {
44
+ const ForgotPassword = forgotPasswordPage.component;
45
+ await act(async () => {
46
+ root.render(<ForgotPassword urlParams={{}} />);
47
+ });
48
+ await act(async () => {
49
+ type(document.getElementById('auth-field-Email') as HTMLInputElement, email);
50
+ });
51
+ await act(async () => {
52
+ container.querySelector('form')?.dispatchEvent(new Event('submit', { bubbles: true, cancelable: true }));
53
+ });
54
+ }
55
+
56
+ describe('forgot password — the answer shown', () => {
57
+ it("shows the door's one sentence, never a claim that a mail was sent", async () => {
58
+ (global as any).fetch = jest.fn().mockResolvedValue({
59
+ status: 200,
60
+ statusText: 'OK',
61
+ json: async () => ({ message: ONE_ANSWER }),
62
+ });
63
+
64
+ await askForALink('ada@example.com');
65
+
66
+ expect(document.body.textContent).toContain(ONE_ANSWER);
67
+ expect(document.body.textContent).not.toContain('We sent an email');
68
+ });
69
+ });