@redacto.io/consent-sdk-react 0.0.2 → 1.0.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.
- package/.turbo/turbo-build.log +8 -8
- package/CHANGELOG.md +11 -0
- package/dist/index.d.mts +58 -4
- package/dist/index.d.ts +58 -4
- package/dist/index.js +3125 -1014
- package/dist/index.mjs +3131 -1014
- package/package.json +2 -3
- package/src/RedactoNoticeConsent/RedactoNoticeConsent.test.tsx +504 -17
- package/src/RedactoNoticeConsent/RedactoNoticeConsent.tsx +1286 -269
- package/src/RedactoNoticeConsent/api/index.ts +267 -46
- package/src/RedactoNoticeConsent/api/types.ts +76 -0
- package/src/RedactoNoticeConsent/injectStyles.ts +102 -0
- package/src/RedactoNoticeConsent/styles.ts +13 -1
- package/src/RedactoNoticeConsent/types.ts +2 -0
- package/src/RedactoNoticeConsentInline/RedactoNoticeConsentInline.test.tsx +369 -0
- package/src/RedactoNoticeConsentInline/RedactoNoticeConsentInline.tsx +597 -0
- package/src/RedactoNoticeConsentInline/api/index.ts +159 -0
- package/src/RedactoNoticeConsentInline/api/types.ts +190 -0
- package/src/RedactoNoticeConsentInline/assets/redacto-logo.png +0 -0
- package/src/RedactoNoticeConsentInline/index.ts +1 -0
- package/src/RedactoNoticeConsentInline/injectStyles.ts +40 -0
- package/src/RedactoNoticeConsentInline/styles.ts +397 -0
- package/src/RedactoNoticeConsentInline/types.ts +45 -0
- package/src/RedactoNoticeConsentInline/useMediaQuery.ts +36 -0
- package/src/index.ts +1 -0
- package/tests/mocks.ts +98 -2
- package/tests/setup.ts +15 -0
- package/.changeset/README.md +0 -8
- package/.changeset/config.json +0 -11
- package/.changeset/fifty-candies-drop.md +0 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@redacto.io/consent-sdk-react",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"main": "dist/index.cjs",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
"react-dom": "^19.1.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@changesets/cli": "^2.29.4",
|
|
28
27
|
"@testing-library/jest-dom": "^6.6.3",
|
|
29
28
|
"@testing-library/react": "^16.3.0",
|
|
30
29
|
"@types/react": "^19.1.3",
|
|
@@ -40,7 +39,7 @@
|
|
|
40
39
|
"dev": "tsup --watch",
|
|
41
40
|
"test": "vitest",
|
|
42
41
|
"test:watch": "vitest watch",
|
|
43
|
-
"release": "pnpm run build
|
|
42
|
+
"release": "pnpm run build",
|
|
44
43
|
"coverage": "vitest run --coverage"
|
|
45
44
|
}
|
|
46
45
|
}
|
|
@@ -1,21 +1,32 @@
|
|
|
1
|
+
import "@testing-library/jest-dom";
|
|
1
2
|
import {
|
|
3
|
+
act,
|
|
4
|
+
fireEvent,
|
|
2
5
|
render,
|
|
3
6
|
screen,
|
|
4
|
-
fireEvent,
|
|
5
7
|
waitFor,
|
|
6
|
-
act,
|
|
7
8
|
} from "@testing-library/react";
|
|
8
|
-
import {
|
|
9
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
10
|
+
import { defaultProps, mockConsentContent, mockMinorConsentContent, mockReconsentContent } from "../../tests/mocks";
|
|
9
11
|
import { RedactoNoticeConsent } from "./RedactoNoticeConsent";
|
|
10
12
|
import * as api from "./api";
|
|
11
13
|
import type { ConsentContent } from "./api/types";
|
|
12
|
-
import { defaultProps, mockConsentContent } from "../../tests/mocks";
|
|
13
|
-
import "@testing-library/jest-dom";
|
|
14
14
|
|
|
15
15
|
// Mock the API functions
|
|
16
16
|
vi.mock("./api", () => ({
|
|
17
17
|
fetchConsentContent: vi.fn(),
|
|
18
18
|
submitConsentEvent: vi.fn(),
|
|
19
|
+
submitGuardianInfo: vi.fn(),
|
|
20
|
+
clearApiCache: vi.fn(),
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
// Mock jwt-decode
|
|
24
|
+
vi.mock("jwt-decode", () => ({
|
|
25
|
+
jwtDecode: vi.fn(() => ({
|
|
26
|
+
organisation_uuid: "org-123",
|
|
27
|
+
workspace_uuid: "workspace-123",
|
|
28
|
+
user_uuid: "user-123",
|
|
29
|
+
})),
|
|
19
30
|
}));
|
|
20
31
|
|
|
21
32
|
// Mock the logo import correctly for ES modules
|
|
@@ -23,12 +34,19 @@ vi.mock("./assets/redacto-logo.png", () => ({
|
|
|
23
34
|
default: "mocked-logo.png",
|
|
24
35
|
}));
|
|
25
36
|
|
|
37
|
+
// Mock injectCheckboxStyles to avoid DOM manipulation in tests
|
|
38
|
+
vi.mock("./injectStyles", () => ({
|
|
39
|
+
injectCheckboxStyles: vi.fn(),
|
|
40
|
+
}));
|
|
41
|
+
|
|
26
42
|
describe("RedactoNoticeConsent", () => {
|
|
27
43
|
const mockedApi = vi.mocked(api, { partial: true });
|
|
28
44
|
beforeEach(() => {
|
|
29
45
|
vi.clearAllMocks();
|
|
30
|
-
|
|
31
|
-
mockedApi.
|
|
46
|
+
// Mock API calls synchronously to avoid act() warnings
|
|
47
|
+
mockedApi.fetchConsentContent.mockReturnValue(Promise.resolve(mockConsentContent));
|
|
48
|
+
mockedApi.submitConsentEvent.mockReturnValue(Promise.resolve(undefined));
|
|
49
|
+
mockedApi.submitGuardianInfo.mockReturnValue(Promise.resolve(undefined));
|
|
32
50
|
});
|
|
33
51
|
|
|
34
52
|
afterEach(() => {
|
|
@@ -36,12 +54,16 @@ describe("RedactoNoticeConsent", () => {
|
|
|
36
54
|
});
|
|
37
55
|
|
|
38
56
|
it("renders loading state initially", () => {
|
|
39
|
-
|
|
57
|
+
act(() => {
|
|
58
|
+
render(<RedactoNoticeConsent {...defaultProps} />);
|
|
59
|
+
});
|
|
40
60
|
expect(screen.getByText("Loading...")).toBeInTheDocument();
|
|
41
61
|
});
|
|
42
62
|
|
|
43
63
|
it("renders consent content after loading", async () => {
|
|
44
|
-
|
|
64
|
+
act(() => {
|
|
65
|
+
render(<RedactoNoticeConsent {...defaultProps} />);
|
|
66
|
+
});
|
|
45
67
|
await waitFor(
|
|
46
68
|
() => {
|
|
47
69
|
expect(screen.getByText("Your Privacy Matters")).toBeInTheDocument();
|
|
@@ -51,9 +73,7 @@ describe("RedactoNoticeConsent", () => {
|
|
|
51
73
|
expect(
|
|
52
74
|
screen.getByRole("link", { name: /Privacy Policy/i })
|
|
53
75
|
).toBeInTheDocument();
|
|
54
|
-
expect(
|
|
55
|
-
screen.getByRole("link", { name: /Vendors List/i })
|
|
56
|
-
).toBeInTheDocument();
|
|
76
|
+
expect(screen.getByText("[Vendors List]")).toBeInTheDocument();
|
|
57
77
|
expect(screen.getByText("Manage What You Share")).toBeInTheDocument();
|
|
58
78
|
expect(screen.getByText("Marketing")).toBeInTheDocument();
|
|
59
79
|
},
|
|
@@ -65,7 +85,7 @@ describe("RedactoNoticeConsent", () => {
|
|
|
65
85
|
const { unmount } = render(<RedactoNoticeConsent {...defaultProps} />);
|
|
66
86
|
await waitFor(
|
|
67
87
|
() => {
|
|
68
|
-
const logo = screen.getByAltText("
|
|
88
|
+
const logo = screen.getByAltText("Redacto Logo");
|
|
69
89
|
expect(logo).toHaveAttribute("src", "https://example.com/logo.png");
|
|
70
90
|
},
|
|
71
91
|
{ timeout: 3000 }
|
|
@@ -88,7 +108,7 @@ describe("RedactoNoticeConsent", () => {
|
|
|
88
108
|
const { unmount } = render(<RedactoNoticeConsent {...defaultProps} />);
|
|
89
109
|
await waitFor(
|
|
90
110
|
() => {
|
|
91
|
-
const logo = screen.getByAltText("
|
|
111
|
+
const logo = screen.getByAltText("Redacto Logo");
|
|
92
112
|
expect(logo).toHaveAttribute("src", "mocked-logo.png");
|
|
93
113
|
},
|
|
94
114
|
{ timeout: 3000 }
|
|
@@ -123,9 +143,7 @@ describe("RedactoNoticeConsent", () => {
|
|
|
123
143
|
expect(
|
|
124
144
|
screen.getByText(/Nos importa tu privacidad/i)
|
|
125
145
|
).toBeInTheDocument();
|
|
126
|
-
expect(
|
|
127
|
-
screen.getByRole("link", { name: /Política de Privacidad/i })
|
|
128
|
-
).toBeInTheDocument();
|
|
146
|
+
expect(screen.getByText("[Política de Privacidad]")).toBeInTheDocument();
|
|
129
147
|
expect(
|
|
130
148
|
screen.getByText("Gestionar Consentimiento")
|
|
131
149
|
).toBeInTheDocument();
|
|
@@ -257,6 +275,7 @@ describe("RedactoNoticeConsent", () => {
|
|
|
257
275
|
() => {
|
|
258
276
|
expect(api.submitConsentEvent).toHaveBeenCalledWith({
|
|
259
277
|
accessToken: "mock-token",
|
|
278
|
+
baseUrl: undefined,
|
|
260
279
|
noticeUuid: "notice-123",
|
|
261
280
|
purposes: [
|
|
262
281
|
{
|
|
@@ -288,6 +307,8 @@ describe("RedactoNoticeConsent", () => {
|
|
|
288
307
|
},
|
|
289
308
|
],
|
|
290
309
|
declined: false,
|
|
310
|
+
meta_data: undefined,
|
|
311
|
+
signal: expect.any(AbortSignal),
|
|
291
312
|
});
|
|
292
313
|
expect(defaultProps.onAccept).toHaveBeenCalled();
|
|
293
314
|
},
|
|
@@ -365,4 +386,470 @@ describe("RedactoNoticeConsent", () => {
|
|
|
365
386
|
{ timeout: 3000 }
|
|
366
387
|
);
|
|
367
388
|
});
|
|
389
|
+
|
|
390
|
+
describe("reconsent functionality", () => {
|
|
391
|
+
beforeEach(() => {
|
|
392
|
+
mockedApi.fetchConsentContent.mockResolvedValue(mockReconsentContent);
|
|
393
|
+
mockedApi.submitConsentEvent.mockResolvedValue(undefined);
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
it("shows reconsent UI with visual indicators for different consent states", async () => {
|
|
397
|
+
render(<RedactoNoticeConsent {...defaultProps} />);
|
|
398
|
+
await waitFor(
|
|
399
|
+
() => {
|
|
400
|
+
expect(screen.getByText("Marketing")).toBeInTheDocument();
|
|
401
|
+
expect(screen.getByText("Analytics")).toBeInTheDocument();
|
|
402
|
+
},
|
|
403
|
+
{ timeout: 3000 }
|
|
404
|
+
);
|
|
405
|
+
|
|
406
|
+
// Check that both purposes are displayed in the reconsent UI
|
|
407
|
+
expect(screen.getByText("Marketing")).toBeInTheDocument();
|
|
408
|
+
expect(screen.getByText("Analytics")).toBeInTheDocument();
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
it("allows reconsent UI to render without errors", async () => {
|
|
412
|
+
render(<RedactoNoticeConsent {...defaultProps} />);
|
|
413
|
+
await waitFor(
|
|
414
|
+
() => {
|
|
415
|
+
expect(screen.getByText("Marketing")).toBeInTheDocument();
|
|
416
|
+
},
|
|
417
|
+
{ timeout: 3000 }
|
|
418
|
+
);
|
|
419
|
+
|
|
420
|
+
// Verify the reconsent UI renders successfully with visual indicators
|
|
421
|
+
expect(screen.getByText("Analytics")).toBeInTheDocument();
|
|
422
|
+
// Verify both purposes are present in the reconsent layout
|
|
423
|
+
const purposes = screen.getAllByText(/Marketing|Analytics/);
|
|
424
|
+
expect(purposes).toHaveLength(2);
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
it("passes check_mode parameter to API", async () => {
|
|
428
|
+
render(<RedactoNoticeConsent {...defaultProps} checkMode="required" />);
|
|
429
|
+
await waitFor(
|
|
430
|
+
() => {
|
|
431
|
+
expect(api.fetchConsentContent).toHaveBeenCalledWith({
|
|
432
|
+
noticeId: "notice-123",
|
|
433
|
+
accessToken: "mock-token",
|
|
434
|
+
refreshToken: "mock-refresh-token",
|
|
435
|
+
baseUrl: undefined,
|
|
436
|
+
language: "en",
|
|
437
|
+
specific_uuid: undefined,
|
|
438
|
+
check_mode: "required",
|
|
439
|
+
signal: expect.any(AbortSignal),
|
|
440
|
+
});
|
|
441
|
+
},
|
|
442
|
+
{ timeout: 3000 }
|
|
443
|
+
);
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
it("defaults to check_mode 'all' when not specified", async () => {
|
|
447
|
+
render(<RedactoNoticeConsent {...defaultProps} />);
|
|
448
|
+
await waitFor(
|
|
449
|
+
() => {
|
|
450
|
+
expect(api.fetchConsentContent).toHaveBeenCalledWith({
|
|
451
|
+
noticeId: "notice-123",
|
|
452
|
+
accessToken: "mock-token",
|
|
453
|
+
refreshToken: "mock-refresh-token",
|
|
454
|
+
baseUrl: undefined,
|
|
455
|
+
language: "en",
|
|
456
|
+
specific_uuid: undefined,
|
|
457
|
+
check_mode: "all",
|
|
458
|
+
signal: expect.any(AbortSignal),
|
|
459
|
+
});
|
|
460
|
+
},
|
|
461
|
+
{ timeout: 3000 }
|
|
462
|
+
);
|
|
463
|
+
});
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
describe("age verification and minor consent functionality", () => {
|
|
467
|
+
beforeEach(() => {
|
|
468
|
+
mockedApi.fetchConsentContent.mockResolvedValue(mockMinorConsentContent);
|
|
469
|
+
mockedApi.submitConsentEvent.mockResolvedValue(undefined);
|
|
470
|
+
mockedApi.submitGuardianInfo.mockResolvedValue(undefined);
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
it("shows age verification when is_minor is true", async () => {
|
|
474
|
+
render(<RedactoNoticeConsent {...defaultProps} />);
|
|
475
|
+
await waitFor(
|
|
476
|
+
() => {
|
|
477
|
+
expect(screen.getByText("Age Verification Required")).toBeInTheDocument();
|
|
478
|
+
expect(
|
|
479
|
+
screen.getByText(/Are you 18 years of age or older/)
|
|
480
|
+
).toBeInTheDocument();
|
|
481
|
+
},
|
|
482
|
+
{ timeout: 3000 }
|
|
483
|
+
);
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
it("shows age verification fields", async () => {
|
|
487
|
+
render(<RedactoNoticeConsent {...defaultProps} />);
|
|
488
|
+
await waitFor(
|
|
489
|
+
() => {
|
|
490
|
+
expect(screen.getByText("Age Verification Required")).toBeInTheDocument();
|
|
491
|
+
expect(screen.getByText("Yes, I am 18 or older")).toBeInTheDocument();
|
|
492
|
+
expect(screen.getByText("No, I am under 18")).toBeInTheDocument();
|
|
493
|
+
expect(screen.getByAltText("Redacto Logo")).toBeInTheDocument();
|
|
494
|
+
},
|
|
495
|
+
{ timeout: 3000 }
|
|
496
|
+
);
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
it("proceeds to consent form when user clicks Yes (18+)", async () => {
|
|
500
|
+
render(<RedactoNoticeConsent {...defaultProps} />);
|
|
501
|
+
await waitFor(
|
|
502
|
+
() => {
|
|
503
|
+
expect(screen.getByText("Age Verification Required")).toBeInTheDocument();
|
|
504
|
+
},
|
|
505
|
+
{ timeout: 3000 }
|
|
506
|
+
);
|
|
507
|
+
|
|
508
|
+
const yesButton = screen.getByText("Yes, I am 18 or older");
|
|
509
|
+
fireEvent.click(yesButton);
|
|
510
|
+
|
|
511
|
+
// Should transition directly to consent form
|
|
512
|
+
await waitFor(
|
|
513
|
+
() => {
|
|
514
|
+
expect(screen.getByText("Your Privacy Matters")).toBeInTheDocument();
|
|
515
|
+
expect(screen.queryByText("Age Verification Required")).not.toBeInTheDocument();
|
|
516
|
+
expect(screen.queryByText("Guardian Information Required")).not.toBeInTheDocument();
|
|
517
|
+
},
|
|
518
|
+
{ timeout: 3000 }
|
|
519
|
+
);
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
it("shows guardian form when user clicks No (under 18)", async () => {
|
|
523
|
+
render(<RedactoNoticeConsent {...defaultProps} />);
|
|
524
|
+
await waitFor(
|
|
525
|
+
() => {
|
|
526
|
+
expect(screen.getByText("Age Verification Required")).toBeInTheDocument();
|
|
527
|
+
},
|
|
528
|
+
{ timeout: 3000 }
|
|
529
|
+
);
|
|
530
|
+
|
|
531
|
+
const noButton = screen.getByText("No, I am under 18");
|
|
532
|
+
fireEvent.click(noButton);
|
|
533
|
+
|
|
534
|
+
// Should transition to guardian form
|
|
535
|
+
await waitFor(
|
|
536
|
+
() => {
|
|
537
|
+
expect(screen.getByText("Guardian Information Required")).toBeInTheDocument();
|
|
538
|
+
expect(screen.queryByText("Age Verification Required")).not.toBeInTheDocument();
|
|
539
|
+
},
|
|
540
|
+
{ timeout: 3000 }
|
|
541
|
+
);
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
it("completes full minor flow: age verification -> guardian form -> consent", async () => {
|
|
545
|
+
render(<RedactoNoticeConsent {...defaultProps} />);
|
|
546
|
+
await waitFor(
|
|
547
|
+
() => {
|
|
548
|
+
expect(screen.getByText("Age Verification Required")).toBeInTheDocument();
|
|
549
|
+
},
|
|
550
|
+
{ timeout: 3000 }
|
|
551
|
+
);
|
|
552
|
+
|
|
553
|
+
// Click No to proceed to guardian form
|
|
554
|
+
const noButton = screen.getByText("No, I am under 18");
|
|
555
|
+
fireEvent.click(noButton);
|
|
556
|
+
|
|
557
|
+
// Should show guardian form
|
|
558
|
+
await waitFor(
|
|
559
|
+
() => {
|
|
560
|
+
expect(screen.getByText("Guardian Information Required")).toBeInTheDocument();
|
|
561
|
+
expect(
|
|
562
|
+
screen.getByText(/As you are under the age of consent/i)
|
|
563
|
+
).toBeInTheDocument();
|
|
564
|
+
},
|
|
565
|
+
{ timeout: 3000 }
|
|
566
|
+
);
|
|
567
|
+
|
|
568
|
+
// Fill out guardian form
|
|
569
|
+
const nameInput = screen.getByLabelText(/Name of Guardian/i);
|
|
570
|
+
const contactInput = screen.getByLabelText(/Contact of Guardian/i);
|
|
571
|
+
const relationshipInput = screen.getByLabelText(/Relationship to Guardian/i);
|
|
572
|
+
|
|
573
|
+
fireEvent.change(nameInput, { target: { value: "John Doe" } });
|
|
574
|
+
fireEvent.change(contactInput, { target: { value: "john@example.com" } });
|
|
575
|
+
fireEvent.change(relationshipInput, { target: { value: "Parent" } });
|
|
576
|
+
|
|
577
|
+
const nextButton = screen.getByText("Next");
|
|
578
|
+
fireEvent.click(nextButton);
|
|
579
|
+
|
|
580
|
+
// Should transition to consent form
|
|
581
|
+
await waitFor(
|
|
582
|
+
() => {
|
|
583
|
+
expect(screen.getByText("Your Privacy Matters")).toBeInTheDocument();
|
|
584
|
+
expect(screen.queryByText("Guardian Information Required")).not.toBeInTheDocument();
|
|
585
|
+
},
|
|
586
|
+
{ timeout: 3000 }
|
|
587
|
+
);
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
it("displays guardian form fields after age verification", async () => {
|
|
591
|
+
render(<RedactoNoticeConsent {...defaultProps} />);
|
|
592
|
+
await waitFor(
|
|
593
|
+
() => {
|
|
594
|
+
expect(screen.getByText("Age Verification Required")).toBeInTheDocument();
|
|
595
|
+
},
|
|
596
|
+
{ timeout: 3000 }
|
|
597
|
+
);
|
|
598
|
+
|
|
599
|
+
// Navigate to guardian form
|
|
600
|
+
const noButton = screen.getByText("No, I am under 18");
|
|
601
|
+
fireEvent.click(noButton);
|
|
602
|
+
|
|
603
|
+
await waitFor(
|
|
604
|
+
() => {
|
|
605
|
+
expect(screen.getByAltText("Redacto Logo")).toBeInTheDocument();
|
|
606
|
+
expect(screen.getByLabelText(/Name of Guardian/i)).toBeInTheDocument();
|
|
607
|
+
expect(screen.getByLabelText(/Contact of Guardian/i)).toBeInTheDocument();
|
|
608
|
+
expect(screen.getByLabelText(/Relationship to Guardian/i)).toBeInTheDocument();
|
|
609
|
+
expect(screen.getByText("Next")).toBeInTheDocument();
|
|
610
|
+
expect(screen.getByText("Cancel")).toBeInTheDocument();
|
|
611
|
+
},
|
|
612
|
+
{ timeout: 3000 }
|
|
613
|
+
);
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
it("validates guardian form fields", async () => {
|
|
617
|
+
render(<RedactoNoticeConsent {...defaultProps} />);
|
|
618
|
+
await waitFor(
|
|
619
|
+
() => {
|
|
620
|
+
expect(screen.getByText("Age Verification Required")).toBeInTheDocument();
|
|
621
|
+
},
|
|
622
|
+
{ timeout: 3000 }
|
|
623
|
+
);
|
|
624
|
+
|
|
625
|
+
// Navigate to guardian form
|
|
626
|
+
const noButton = screen.getByText("No, I am under 18");
|
|
627
|
+
fireEvent.click(noButton);
|
|
628
|
+
|
|
629
|
+
await waitFor(
|
|
630
|
+
() => {
|
|
631
|
+
expect(screen.getByText("Guardian Information Required")).toBeInTheDocument();
|
|
632
|
+
},
|
|
633
|
+
{ timeout: 3000 }
|
|
634
|
+
);
|
|
635
|
+
|
|
636
|
+
const nextButton = screen.getByText("Next");
|
|
637
|
+
fireEvent.click(nextButton);
|
|
638
|
+
|
|
639
|
+
await waitFor(
|
|
640
|
+
() => {
|
|
641
|
+
expect(screen.getByText("Guardian name is required")).toBeInTheDocument();
|
|
642
|
+
expect(screen.getByText("Guardian contact is required")).toBeInTheDocument();
|
|
643
|
+
expect(screen.getByText("Relationship to guardian is required")).toBeInTheDocument();
|
|
644
|
+
},
|
|
645
|
+
{ timeout: 3000 }
|
|
646
|
+
);
|
|
647
|
+
});
|
|
648
|
+
|
|
649
|
+
it("transitions to consent form after filling guardian form", async () => {
|
|
650
|
+
render(<RedactoNoticeConsent {...defaultProps} />);
|
|
651
|
+
await waitFor(
|
|
652
|
+
() => {
|
|
653
|
+
expect(screen.getByText("Age Verification Required")).toBeInTheDocument();
|
|
654
|
+
},
|
|
655
|
+
{ timeout: 3000 }
|
|
656
|
+
);
|
|
657
|
+
|
|
658
|
+
// Navigate to guardian form
|
|
659
|
+
const noButton = screen.getByText("No, I am under 18");
|
|
660
|
+
fireEvent.click(noButton);
|
|
661
|
+
|
|
662
|
+
await waitFor(
|
|
663
|
+
() => {
|
|
664
|
+
expect(screen.getByText("Guardian Information Required")).toBeInTheDocument();
|
|
665
|
+
},
|
|
666
|
+
{ timeout: 3000 }
|
|
667
|
+
);
|
|
668
|
+
|
|
669
|
+
// Fill out guardian form
|
|
670
|
+
const nameInput = screen.getByLabelText(/Name of Guardian/i);
|
|
671
|
+
const contactInput = screen.getByLabelText(/Contact of Guardian/i);
|
|
672
|
+
const relationshipInput = screen.getByLabelText(/Relationship to Guardian/i);
|
|
673
|
+
|
|
674
|
+
fireEvent.change(nameInput, { target: { value: "John Doe" } });
|
|
675
|
+
fireEvent.change(contactInput, { target: { value: "john@example.com" } });
|
|
676
|
+
fireEvent.change(relationshipInput, { target: { value: "Parent" } });
|
|
677
|
+
|
|
678
|
+
const nextButton = screen.getByText("Next");
|
|
679
|
+
fireEvent.click(nextButton);
|
|
680
|
+
|
|
681
|
+
// Should transition to consent form
|
|
682
|
+
await waitFor(
|
|
683
|
+
() => {
|
|
684
|
+
expect(screen.getByText("Your Privacy Matters")).toBeInTheDocument();
|
|
685
|
+
expect(screen.queryByText("Guardian Information Required")).not.toBeInTheDocument();
|
|
686
|
+
},
|
|
687
|
+
{ timeout: 3000 }
|
|
688
|
+
);
|
|
689
|
+
});
|
|
690
|
+
|
|
691
|
+
it("validates whitespace-only input as empty", async () => {
|
|
692
|
+
render(<RedactoNoticeConsent {...defaultProps} />);
|
|
693
|
+
await waitFor(
|
|
694
|
+
() => {
|
|
695
|
+
expect(screen.getByText("Age Verification Required")).toBeInTheDocument();
|
|
696
|
+
},
|
|
697
|
+
{ timeout: 3000 }
|
|
698
|
+
);
|
|
699
|
+
|
|
700
|
+
// Navigate to guardian form
|
|
701
|
+
const noButton = screen.getByText("No, I am under 18");
|
|
702
|
+
fireEvent.click(noButton);
|
|
703
|
+
|
|
704
|
+
await waitFor(
|
|
705
|
+
() => {
|
|
706
|
+
expect(screen.getByText("Guardian Information Required")).toBeInTheDocument();
|
|
707
|
+
},
|
|
708
|
+
{ timeout: 3000 }
|
|
709
|
+
);
|
|
710
|
+
|
|
711
|
+
// Fill fields with only whitespace
|
|
712
|
+
const nameInput = screen.getByLabelText(/Name of Guardian/i);
|
|
713
|
+
const contactInput = screen.getByLabelText(/Contact of Guardian/i);
|
|
714
|
+
const relationshipInput = screen.getByLabelText(/Relationship to Guardian/i);
|
|
715
|
+
|
|
716
|
+
fireEvent.change(nameInput, { target: { value: " " } });
|
|
717
|
+
fireEvent.change(contactInput, { target: { value: "\t\t" } });
|
|
718
|
+
fireEvent.change(relationshipInput, { target: { value: "\n\n" } });
|
|
719
|
+
|
|
720
|
+
const nextButton = screen.getByText("Next");
|
|
721
|
+
fireEvent.click(nextButton);
|
|
722
|
+
|
|
723
|
+
// Should still show validation errors for whitespace-only input
|
|
724
|
+
await waitFor(
|
|
725
|
+
() => {
|
|
726
|
+
expect(screen.getByText("Guardian name is required")).toBeInTheDocument();
|
|
727
|
+
expect(screen.getByText("Guardian contact is required")).toBeInTheDocument();
|
|
728
|
+
expect(screen.getByText("Relationship to guardian is required")).toBeInTheDocument();
|
|
729
|
+
},
|
|
730
|
+
{ timeout: 3000 }
|
|
731
|
+
);
|
|
732
|
+
});
|
|
733
|
+
|
|
734
|
+
it("clears validation errors when user starts typing", async () => {
|
|
735
|
+
render(<RedactoNoticeConsent {...defaultProps} />);
|
|
736
|
+
await waitFor(
|
|
737
|
+
() => {
|
|
738
|
+
expect(screen.getByText("Age Verification Required")).toBeInTheDocument();
|
|
739
|
+
},
|
|
740
|
+
{ timeout: 3000 }
|
|
741
|
+
);
|
|
742
|
+
|
|
743
|
+
// Navigate to guardian form
|
|
744
|
+
const noButton = screen.getByText("No, I am under 18");
|
|
745
|
+
fireEvent.click(noButton);
|
|
746
|
+
|
|
747
|
+
await waitFor(
|
|
748
|
+
() => {
|
|
749
|
+
expect(screen.getByText("Guardian Information Required")).toBeInTheDocument();
|
|
750
|
+
},
|
|
751
|
+
{ timeout: 3000 }
|
|
752
|
+
);
|
|
753
|
+
|
|
754
|
+
// Click next with empty fields to trigger errors
|
|
755
|
+
const nextButton = screen.getByText("Next");
|
|
756
|
+
fireEvent.click(nextButton);
|
|
757
|
+
|
|
758
|
+
await waitFor(
|
|
759
|
+
() => {
|
|
760
|
+
expect(screen.getByText("Guardian name is required")).toBeInTheDocument();
|
|
761
|
+
},
|
|
762
|
+
{ timeout: 3000 }
|
|
763
|
+
);
|
|
764
|
+
|
|
765
|
+
// Start typing in name field
|
|
766
|
+
const nameInput = screen.getByLabelText(/Name of Guardian/i);
|
|
767
|
+
fireEvent.change(nameInput, { target: { value: "J" } });
|
|
768
|
+
|
|
769
|
+
// Error should be cleared
|
|
770
|
+
await waitFor(
|
|
771
|
+
() => {
|
|
772
|
+
expect(screen.queryByText("Guardian name is required")).not.toBeInTheDocument();
|
|
773
|
+
},
|
|
774
|
+
{ timeout: 3000 }
|
|
775
|
+
);
|
|
776
|
+
});
|
|
777
|
+
|
|
778
|
+
it("calls onDecline when cancel is clicked in guardian form", async () => {
|
|
779
|
+
render(<RedactoNoticeConsent {...defaultProps} />);
|
|
780
|
+
await waitFor(
|
|
781
|
+
() => {
|
|
782
|
+
expect(screen.getByText("Age Verification Required")).toBeInTheDocument();
|
|
783
|
+
},
|
|
784
|
+
{ timeout: 3000 }
|
|
785
|
+
);
|
|
786
|
+
|
|
787
|
+
// Navigate to guardian form
|
|
788
|
+
const noButton = screen.getByText("No, I am under 18");
|
|
789
|
+
fireEvent.click(noButton);
|
|
790
|
+
|
|
791
|
+
await waitFor(
|
|
792
|
+
() => {
|
|
793
|
+
expect(screen.getByText("Guardian Information Required")).toBeInTheDocument();
|
|
794
|
+
},
|
|
795
|
+
{ timeout: 3000 }
|
|
796
|
+
);
|
|
797
|
+
|
|
798
|
+
const cancelButton = screen.getByText("Cancel");
|
|
799
|
+
fireEvent.click(cancelButton);
|
|
800
|
+
|
|
801
|
+
await waitFor(
|
|
802
|
+
() => {
|
|
803
|
+
expect(defaultProps.onDecline).toHaveBeenCalled();
|
|
804
|
+
},
|
|
805
|
+
{ timeout: 3000 }
|
|
806
|
+
);
|
|
807
|
+
});
|
|
808
|
+
|
|
809
|
+
it("maintains focus when typing in guardian form fields", async () => {
|
|
810
|
+
render(<RedactoNoticeConsent {...defaultProps} />);
|
|
811
|
+
await waitFor(
|
|
812
|
+
() => {
|
|
813
|
+
expect(screen.getByText("Age Verification Required")).toBeInTheDocument();
|
|
814
|
+
},
|
|
815
|
+
{ timeout: 3000 }
|
|
816
|
+
);
|
|
817
|
+
|
|
818
|
+
// Navigate to guardian form
|
|
819
|
+
const noButton = screen.getByText("No, I am under 18");
|
|
820
|
+
fireEvent.click(noButton);
|
|
821
|
+
|
|
822
|
+
await waitFor(
|
|
823
|
+
() => {
|
|
824
|
+
expect(screen.getByText("Guardian Information Required")).toBeInTheDocument();
|
|
825
|
+
},
|
|
826
|
+
{ timeout: 3000 }
|
|
827
|
+
);
|
|
828
|
+
|
|
829
|
+
const contactInput = screen.getByLabelText(/Contact of Guardian/i);
|
|
830
|
+
|
|
831
|
+
// Focus on contact field and type
|
|
832
|
+
contactInput.focus();
|
|
833
|
+
fireEvent.change(contactInput, { target: { value: "j" } });
|
|
834
|
+
|
|
835
|
+
// Verify the input still has focus and value
|
|
836
|
+
expect(contactInput).toHaveFocus();
|
|
837
|
+
expect(contactInput).toHaveValue("j");
|
|
838
|
+
|
|
839
|
+
// Continue typing
|
|
840
|
+
fireEvent.change(contactInput, { target: { value: "john@example.com" } });
|
|
841
|
+
|
|
842
|
+
// Verify the input still has focus and updated value
|
|
843
|
+
expect(contactInput).toHaveFocus();
|
|
844
|
+
expect(contactInput).toHaveValue("john@example.com");
|
|
845
|
+
|
|
846
|
+
// Test other fields maintain focus too
|
|
847
|
+
const nameInput = screen.getByLabelText(/Name of Guardian/i);
|
|
848
|
+
nameInput.focus();
|
|
849
|
+
fireEvent.change(nameInput, { target: { value: "J" } });
|
|
850
|
+
|
|
851
|
+
expect(nameInput).toHaveFocus();
|
|
852
|
+
expect(nameInput).toHaveValue("J");
|
|
853
|
+
});
|
|
854
|
+
});
|
|
368
855
|
});
|