@khanacademy/wonder-blocks-popover 3.2.15 → 3.3.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.
@@ -1,98 +0,0 @@
1
- import * as React from "react";
2
- import {render, screen} from "@testing-library/react";
3
- import {userEvent} from "@testing-library/user-event";
4
-
5
- import {View} from "@khanacademy/wonder-blocks-core";
6
- import PopoverEventListener from "../popover-event-listener";
7
- import PopoverContent from "../popover-content";
8
-
9
- describe("PopoverKeypressListener", () => {
10
- // TODO(FEI-5533): Key press events aren't working correctly with
11
- // user-event v14. We need to investigate and fix this.
12
- it.skip("should call onClose if Escape is pressed", async () => {
13
- // Arrange
14
- const onCloseMock = jest.fn();
15
-
16
- render(<PopoverEventListener onClose={onCloseMock} />);
17
-
18
- // Act
19
- await userEvent.keyboard("{esc}");
20
-
21
- // Assert
22
- expect(onCloseMock).toHaveBeenCalled();
23
- });
24
-
25
- it("should call onClose if clicked outside content ref", async () => {
26
- // Arrange
27
- const onCloseMock = jest.fn();
28
- const contentRef: React.RefObject<PopoverContent> = React.createRef();
29
-
30
- render(
31
- <View>
32
- <PopoverContent
33
- ref={contentRef}
34
- title="Title"
35
- content="Content"
36
- />
37
- <PopoverEventListener
38
- onClose={onCloseMock}
39
- contentRef={contentRef}
40
- />
41
- </View>,
42
- );
43
-
44
- // Act
45
- const event = new MouseEvent("click", {view: window, bubbles: true});
46
- const node = document.body;
47
- if (node) {
48
- // First click is ignored by PopoverEventListener
49
- // because it is triggered when opening the popover.
50
- node.dispatchEvent(event);
51
- node.dispatchEvent(event);
52
- } else {
53
- // Signal that body was never found
54
- expect(node).not.toBe(null);
55
- }
56
-
57
- // Assert
58
- expect(onCloseMock).toHaveBeenCalled();
59
- });
60
-
61
- it("should not call onClose if clicked inside content ref", async () => {
62
- // Arrange
63
- const onCloseMock = jest.fn();
64
- const contentRef: React.RefObject<PopoverContent> = React.createRef();
65
-
66
- render(
67
- <View>
68
- <PopoverContent
69
- ref={contentRef}
70
- title="Title"
71
- content="Content"
72
- testId="popover-content"
73
- />
74
- <PopoverEventListener
75
- onClose={onCloseMock}
76
- contentRef={contentRef}
77
- />
78
- </View>,
79
- );
80
-
81
- // Act
82
- const event = new MouseEvent("click", {view: window, bubbles: true});
83
- const node = await screen.findByTestId("popover-content");
84
-
85
- if (node) {
86
- // First click is ignored by PopoverEventListener
87
- // because it is triggered when opening the popover.
88
- node.dispatchEvent(event);
89
- node.dispatchEvent(event);
90
- } else {
91
- // Signal that PopoverContent was never found
92
- expect(node).not.toBe(null);
93
- }
94
-
95
- // Assert
96
- expect(onCloseMock).not.toHaveBeenCalled();
97
- });
98
- });