@griddo/ax 1.72.11 → 1.73.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.
Files changed (76) hide show
  1. package/package.json +2 -2
  2. package/scripts/griddo-sync-schemas.js +1 -1
  3. package/src/__tests__/components/ErrorCenter/ErrorCenter.test.tsx +186 -0
  4. package/src/__tests__/components/Flag/Flag.test.tsx +60 -0
  5. package/src/__tests__/components/FloatingMenu/FloatingMenu.test.tsx +712 -0
  6. package/src/__tests__/components/FloatingPanel/FloatingPanel.test.tsx +149 -0
  7. package/src/__tests__/components/GuardModal/GuardModal.test.tsx +31 -0
  8. package/src/__tests__/components/Icon/Icon.test.tsx +76 -0
  9. package/src/__tests__/components/IconAction/IconAction.test.tsx +91 -0
  10. package/src/__tests__/components/Notification/Notification.test.tsx +206 -0
  11. package/src/__tests__/components/Notification/SubNotification/Subnotification.test.tsx +46 -0
  12. package/src/__tests__/components/ReorderArrows/ReorderArrows.test.tsx +96 -0
  13. package/src/__tests__/components/ResizePanel/ResizePanel.test.tsx +200 -0
  14. package/src/__tests__/components/SearchField/SearchField.test.tsx +375 -0
  15. package/src/api/analytics.tsx +4 -4
  16. package/src/components/ActionMenu/style.tsx +1 -0
  17. package/src/components/ConfigPanel/Form/ConnectedField/NavConnectedField/index.tsx +1 -1
  18. package/src/components/ConfigPanel/Form/ConnectedField/PageConnectedField/Field/index.tsx +2 -1
  19. package/src/components/ConfigPanel/Form/index.tsx +22 -1
  20. package/src/components/ConfigPanel/Form/style.tsx +19 -0
  21. package/src/components/ConfigPanel/GlobalPageForm/index.tsx +22 -3
  22. package/src/components/ConfigPanel/GlobalPageForm/style.tsx +18 -2
  23. package/src/components/ConfigPanel/NavigationForm/Field/index.tsx +25 -13
  24. package/src/components/ConfigPanel/index.tsx +8 -0
  25. package/src/components/ErrorCenter/index.tsx +8 -4
  26. package/src/components/Fields/DateField/DatePickerInput/index.tsx +30 -8
  27. package/src/components/Fields/DateField/index.tsx +8 -2
  28. package/src/components/Fields/Select/index.tsx +1 -0
  29. package/src/components/Flag/index.tsx +13 -11
  30. package/src/components/FloatingMenu/index.tsx +23 -7
  31. package/src/components/FloatingMenu/style.tsx +1 -0
  32. package/src/components/FloatingPanel/index.tsx +9 -3
  33. package/src/components/GuardModal/index.tsx +3 -3
  34. package/src/components/Icon/index.tsx +2 -1
  35. package/src/components/IconAction/index.tsx +3 -3
  36. package/src/components/MainWrapper/AppBar/index.tsx +3 -1
  37. package/src/components/MainWrapper/AppBar/style.tsx +3 -0
  38. package/src/components/MenuItem/index.tsx +1 -1
  39. package/src/components/Modal/index.tsx +1 -1
  40. package/src/components/Notification/SubNotification/index.tsx +33 -0
  41. package/src/components/Notification/SubNotification/style.tsx +49 -0
  42. package/src/components/Notification/index.tsx +31 -17
  43. package/src/components/Notification/style.tsx +33 -8
  44. package/src/components/ReorderArrows/index.tsx +3 -3
  45. package/src/components/ResizePanel/ResizeHandle/index.tsx +29 -38
  46. package/src/components/ResizePanel/index.tsx +13 -15
  47. package/src/components/SearchField/index.tsx +9 -8
  48. package/src/containers/Analytics/actions.tsx +14 -4
  49. package/src/containers/App/actions.tsx +18 -6
  50. package/src/containers/App/reducer.tsx +1 -0
  51. package/src/containers/Domains/actions.tsx +8 -1
  52. package/src/containers/Navigation/Defaults/actions.tsx +16 -2
  53. package/src/containers/PageEditor/actions.tsx +82 -6
  54. package/src/containers/PageEditor/utils.tsx +28 -10
  55. package/src/containers/Redirects/actions.tsx +16 -2
  56. package/src/containers/Sites/actions.tsx +80 -3
  57. package/src/containers/StructuredData/actions.tsx +24 -3
  58. package/src/containers/Users/actions.tsx +8 -1
  59. package/src/forms/errors.tsx +1 -0
  60. package/src/forms/fields.tsx +6 -3
  61. package/src/forms/validators.tsx +14 -4
  62. package/src/guards/error/index.tsx +17 -21
  63. package/src/helpers/dates.tsx +2 -0
  64. package/src/helpers/index.tsx +2 -0
  65. package/src/hooks/modals.tsx +4 -4
  66. package/src/modules/Content/OptionTable/index.tsx +20 -7
  67. package/src/modules/Content/index.tsx +4 -7
  68. package/src/modules/Content/utils.tsx +18 -13
  69. package/src/modules/FramePreview/index.tsx +39 -12
  70. package/src/modules/GlobalEditor/index.tsx +17 -20
  71. package/src/modules/Navigation/Menus/List/Table/index.tsx +2 -2
  72. package/src/modules/PageEditor/Editor/index.tsx +13 -0
  73. package/src/modules/PageEditor/index.tsx +17 -20
  74. package/src/modules/Redirects/RedirectItem/index.tsx +17 -3
  75. package/src/modules/Settings/ContentTypes/DataPacks/Item/index.tsx +1 -1
  76. package/src/modules/StructuredData/Form/index.tsx +10 -13
@@ -0,0 +1,712 @@
1
+ import React, { useRef } from "react";
2
+
3
+ import { ThemeProvider } from "styled-components";
4
+ import { render, cleanup, screen, fireEvent } from "@testing-library/react";
5
+ import { parseTheme } from "@ax/helpers";
6
+ import "@testing-library/jest-dom";
7
+
8
+ import FloatingMenu, { IFloatingProps } from "@ax/components/FloatingMenu";
9
+ import globalTheme from "@ax/themes/theme.json";
10
+
11
+ afterEach(cleanup);
12
+
13
+ jest.mock("react", () => {
14
+ const originReact = jest.requireActual("react");
15
+ const mUseRef = jest.fn();
16
+ return {
17
+ ...originReact,
18
+ useRef: mUseRef,
19
+ };
20
+ });
21
+
22
+ const useMockRef = useRef as jest.MockedFunction<typeof useRef>;
23
+
24
+ describe("FloatingMenu component rendering", () => {
25
+ it("should render the component", () => {
26
+ const buttonContent = () => (
27
+ <div>
28
+ <span>texto</span>
29
+ </div>
30
+ );
31
+
32
+ const defaultProps: IFloatingProps = {
33
+ children: "<div>hola</div>",
34
+ Button: buttonContent,
35
+ isInAppBar: true,
36
+ position: "left",
37
+ closeOnSelect: false,
38
+ isCheckGroup: true,
39
+ reactiveToHover: true,
40
+ offset: 10,
41
+ };
42
+
43
+ render(
44
+ <ThemeProvider theme={parseTheme(globalTheme)}>
45
+ <FloatingMenu {...defaultProps} />
46
+ </ThemeProvider>
47
+ );
48
+
49
+ const floatingMenu = screen.getByTestId("floating-menu");
50
+ expect(floatingMenu).toBeTruthy();
51
+ });
52
+
53
+ it("should show the floating div when click", () => {
54
+ const buttonContent = () => (
55
+ <div>
56
+ <span>texto</span>
57
+ </div>
58
+ );
59
+
60
+ const defaultProps: IFloatingProps = {
61
+ children: "<div>hola</div>",
62
+ Button: buttonContent,
63
+ isInAppBar: true,
64
+ isCheckGroup: true,
65
+ reactiveToHover: true,
66
+ offset: 10,
67
+ };
68
+
69
+ const wrapperRef = { current: {} };
70
+ const buttonRef = { current: {} };
71
+ const menuOptionsRef = { current: {} };
72
+ Object.defineProperty(wrapperRef, "current", {
73
+ set(_current) {
74
+ if (_current) {
75
+ jest.spyOn(_current, "contains").mockReturnValueOnce(true);
76
+ }
77
+ this._current = _current;
78
+ },
79
+ get() {
80
+ return this._current;
81
+ },
82
+ });
83
+ Object.defineProperty(buttonRef, "current", {
84
+ set(_current) {
85
+ if (_current) {
86
+ jest.spyOn(_current, "contains").mockReturnValueOnce(true);
87
+ }
88
+ this._current = _current;
89
+ },
90
+ get() {
91
+ return this._current;
92
+ },
93
+ });
94
+ Object.defineProperty(menuOptionsRef, "current", {
95
+ set(_current) {
96
+ if (_current) {
97
+ jest.spyOn(_current, "contains").mockReturnValueOnce(false);
98
+ }
99
+ this._current = _current;
100
+ },
101
+ get() {
102
+ return this._current;
103
+ },
104
+ });
105
+ useMockRef.mockReturnValueOnce(wrapperRef);
106
+ useMockRef.mockReturnValueOnce(buttonRef);
107
+ useMockRef.mockReturnValueOnce(menuOptionsRef);
108
+
109
+ const { rerender } = render(
110
+ <ThemeProvider theme={parseTheme(globalTheme)}>
111
+ <FloatingMenu {...defaultProps} />
112
+ </ThemeProvider>
113
+ );
114
+
115
+ const floatingMenu = screen.getByTestId("floating-menu");
116
+ expect(floatingMenu).toBeTruthy();
117
+
118
+ fireEvent.click(floatingMenu);
119
+
120
+ expect(screen.getByTestId("floating-menu-wrapper")).toBeTruthy();
121
+
122
+ useMockRef.mockReturnValueOnce(wrapperRef);
123
+
124
+ rerender(
125
+ <ThemeProvider theme={parseTheme(globalTheme)}>
126
+ <FloatingMenu {...defaultProps} />
127
+ </ThemeProvider>
128
+ );
129
+ fireEvent.mouseDown(document);
130
+ expect(screen.getByTestId("floating-menu-wrapper")).toBeTruthy();
131
+ });
132
+
133
+ it("should close the floating div when click", () => {
134
+ const buttonContent = () => (
135
+ <div>
136
+ <span>texto</span>
137
+ </div>
138
+ );
139
+
140
+ const defaultProps: IFloatingProps = {
141
+ children: "<div>hola</div>",
142
+ Button: buttonContent,
143
+ isInAppBar: true,
144
+ isCheckGroup: true,
145
+ reactiveToHover: true,
146
+ offset: 10,
147
+ };
148
+
149
+ const wrapperRef = { current: {} };
150
+ const buttonRef = { current: {} };
151
+ const menuOptionsRef = { current: {} };
152
+
153
+ Object.defineProperty(wrapperRef, "current", {
154
+ set(_current) {
155
+ if (_current) {
156
+ jest.spyOn(_current, "contains").mockReturnValue(true);
157
+ }
158
+ this._current = _current;
159
+ },
160
+ get() {
161
+ return this._current;
162
+ },
163
+ });
164
+ Object.defineProperty(buttonRef, "current", {
165
+ set(_current) {
166
+ if (_current) {
167
+ jest.spyOn(_current, "contains").mockReturnValueOnce(true);
168
+ }
169
+ this._current = _current;
170
+ },
171
+ get() {
172
+ return this._current;
173
+ },
174
+ });
175
+ Object.defineProperty(menuOptionsRef, "current", {
176
+ set(_current) {
177
+ if (_current) {
178
+ jest.spyOn(_current, "contains").mockReturnValueOnce(false);
179
+ }
180
+ this._current = _current;
181
+ },
182
+ get() {
183
+ return this._current;
184
+ },
185
+ });
186
+
187
+ useMockRef.mockReturnValueOnce(wrapperRef);
188
+ useMockRef.mockReturnValueOnce(buttonRef);
189
+ useMockRef.mockReturnValueOnce(menuOptionsRef);
190
+
191
+ const { rerender } = render(
192
+ <ThemeProvider theme={parseTheme(globalTheme)}>
193
+ <FloatingMenu {...defaultProps} />
194
+ </ThemeProvider>
195
+ );
196
+ const floatingMenu = screen.getByTestId("floating-menu");
197
+ expect(floatingMenu).toBeTruthy();
198
+
199
+ fireEvent.click(floatingMenu);
200
+
201
+ expect(screen.getByTestId("floating-menu-wrapper")).toBeTruthy();
202
+
203
+ Object.defineProperty(wrapperRef, "current", {
204
+ set(_current) {
205
+ if (_current) {
206
+ jest.spyOn(_current, "contains").mockReturnValue(false);
207
+ }
208
+ this._current = _current;
209
+ },
210
+ get() {
211
+ return this._current;
212
+ },
213
+ });
214
+ useMockRef.mockReturnValueOnce(wrapperRef);
215
+
216
+ rerender(
217
+ <ThemeProvider theme={parseTheme(globalTheme)}>
218
+ <FloatingMenu {...defaultProps} />
219
+ </ThemeProvider>
220
+ );
221
+
222
+ fireEvent.mouseDown(document);
223
+
224
+ expect(screen.queryByTestId("floating-menu-wrapper")).not.toBeTruthy();
225
+ });
226
+
227
+ it("should close the floating div when select option", () => {
228
+ const buttonContent = () => <input type="checkbox" data-testid="menu-children" />;
229
+
230
+ const defaultProps: IFloatingProps = {
231
+ children: "<div>hola</div>",
232
+ Button: buttonContent,
233
+ isInAppBar: true,
234
+ isCheckGroup: true,
235
+ reactiveToHover: true,
236
+ offset: 10,
237
+ };
238
+
239
+ const wrapperRef = { current: {} };
240
+ const buttonRef = { current: {} };
241
+ const menuOptionsRef = { current: {} };
242
+
243
+ Object.defineProperty(wrapperRef, "current", {
244
+ set(_current) {
245
+ if (_current) {
246
+ jest.spyOn(_current, "contains").mockReturnValue(true);
247
+ }
248
+ this._current = _current;
249
+ },
250
+ get() {
251
+ return this._current;
252
+ },
253
+ });
254
+ Object.defineProperty(buttonRef, "current", {
255
+ set(_current) {
256
+ if (_current) {
257
+ jest.spyOn(_current, "contains").mockReturnValueOnce(true);
258
+ }
259
+ this._current = _current;
260
+ },
261
+ get() {
262
+ return this._current;
263
+ },
264
+ });
265
+ Object.defineProperty(menuOptionsRef, "current", {
266
+ set(_current) {
267
+ if (_current) {
268
+ jest.spyOn(_current, "contains").mockReturnValueOnce(false);
269
+ }
270
+ this._current = _current;
271
+ },
272
+ get() {
273
+ return this._current;
274
+ },
275
+ });
276
+
277
+ useMockRef.mockReturnValueOnce(wrapperRef);
278
+ useMockRef.mockReturnValueOnce(buttonRef);
279
+ useMockRef.mockReturnValueOnce(menuOptionsRef);
280
+
281
+ const { rerender } = render(
282
+ <ThemeProvider theme={parseTheme(globalTheme)}>
283
+ <FloatingMenu {...defaultProps} />
284
+ </ThemeProvider>
285
+ );
286
+ const floatingMenu = screen.getByTestId("floating-menu");
287
+ expect(floatingMenu).toBeTruthy();
288
+
289
+ fireEvent.click(floatingMenu);
290
+
291
+ expect(screen.getByTestId("floating-menu-wrapper")).toBeTruthy();
292
+
293
+ Object.defineProperty(wrapperRef, "current", {
294
+ set(_current) {
295
+ if (_current) {
296
+ jest.spyOn(_current, "contains").mockReturnValue(true);
297
+ }
298
+ this._current = _current;
299
+ },
300
+ get() {
301
+ return this._current;
302
+ },
303
+ });
304
+ Object.defineProperty(buttonRef, "current", {
305
+ set(_current) {
306
+ if (_current) {
307
+ jest.spyOn(_current, "contains").mockReturnValueOnce(false);
308
+ }
309
+ this._current = _current;
310
+ },
311
+ get() {
312
+ return this._current;
313
+ },
314
+ });
315
+ Object.defineProperty(menuOptionsRef, "current", {
316
+ set(_current) {
317
+ if (_current) {
318
+ jest.spyOn(_current, "contains").mockReturnValueOnce(true);
319
+ }
320
+ this._current = _current;
321
+ },
322
+ get() {
323
+ return this._current;
324
+ },
325
+ });
326
+
327
+ useMockRef.mockReturnValueOnce(wrapperRef);
328
+ useMockRef.mockReturnValueOnce(buttonRef);
329
+ useMockRef.mockReturnValueOnce(menuOptionsRef);
330
+ rerender(
331
+ <ThemeProvider theme={parseTheme(globalTheme)}>
332
+ <FloatingMenu {...defaultProps} />
333
+ </ThemeProvider>
334
+ );
335
+
336
+ const menuChildren = screen.getByTestId("menu-children");
337
+ fireEvent.click(menuChildren);
338
+
339
+ expect(screen.queryByTestId("floating-menu-wrapper")).not.toBeTruthy();
340
+ });
341
+
342
+ it("should close the floating div when select option and is not a checkgroup", () => {
343
+ const buttonContent = () => <span data-testid="menu-children">texto</span>;
344
+
345
+ const defaultProps: IFloatingProps = {
346
+ children: "<div>hola</div>",
347
+ Button: buttonContent,
348
+ isInAppBar: true,
349
+ isCheckGroup: false,
350
+ reactiveToHover: true,
351
+ offset: 10,
352
+ };
353
+
354
+ const wrapperRef = { current: {} };
355
+ const buttonRef = { current: {} };
356
+ const menuOptionsRef = { current: {} };
357
+
358
+ Object.defineProperty(wrapperRef, "current", {
359
+ set(_current) {
360
+ if (_current) {
361
+ jest.spyOn(_current, "contains").mockReturnValue(true);
362
+ }
363
+ this._current = _current;
364
+ },
365
+ get() {
366
+ return this._current;
367
+ },
368
+ });
369
+ Object.defineProperty(buttonRef, "current", {
370
+ set(_current) {
371
+ if (_current) {
372
+ jest.spyOn(_current, "contains").mockReturnValueOnce(true);
373
+ }
374
+ this._current = _current;
375
+ },
376
+ get() {
377
+ return this._current;
378
+ },
379
+ });
380
+ Object.defineProperty(menuOptionsRef, "current", {
381
+ set(_current) {
382
+ if (_current) {
383
+ jest.spyOn(_current, "contains").mockReturnValueOnce(false);
384
+ }
385
+ this._current = _current;
386
+ },
387
+ get() {
388
+ return this._current;
389
+ },
390
+ });
391
+
392
+ useMockRef.mockReturnValueOnce(wrapperRef);
393
+ useMockRef.mockReturnValueOnce(buttonRef);
394
+ useMockRef.mockReturnValueOnce(menuOptionsRef);
395
+
396
+ const { rerender } = render(
397
+ <ThemeProvider theme={parseTheme(globalTheme)}>
398
+ <FloatingMenu {...defaultProps} />
399
+ </ThemeProvider>
400
+ );
401
+ const floatingMenu = screen.getByTestId("floating-menu");
402
+ expect(floatingMenu).toBeTruthy();
403
+
404
+ fireEvent.click(floatingMenu);
405
+
406
+ expect(screen.getByTestId("floating-menu-wrapper")).toBeTruthy();
407
+
408
+ Object.defineProperty(wrapperRef, "current", {
409
+ set(_current) {
410
+ if (_current) {
411
+ jest.spyOn(_current, "contains").mockReturnValue(true);
412
+ }
413
+ this._current = _current;
414
+ },
415
+ get() {
416
+ return this._current;
417
+ },
418
+ });
419
+ Object.defineProperty(buttonRef, "current", {
420
+ set(_current) {
421
+ if (_current) {
422
+ jest.spyOn(_current, "contains").mockReturnValueOnce(false);
423
+ }
424
+ this._current = _current;
425
+ },
426
+ get() {
427
+ return this._current;
428
+ },
429
+ });
430
+ Object.defineProperty(menuOptionsRef, "current", {
431
+ set(_current) {
432
+ if (_current) {
433
+ jest.spyOn(_current, "contains").mockReturnValueOnce(true);
434
+ }
435
+ this._current = _current;
436
+ },
437
+ get() {
438
+ return this._current;
439
+ },
440
+ });
441
+
442
+ useMockRef.mockReturnValueOnce(wrapperRef);
443
+ useMockRef.mockReturnValueOnce(buttonRef);
444
+ useMockRef.mockReturnValueOnce(menuOptionsRef);
445
+ rerender(
446
+ <ThemeProvider theme={parseTheme(globalTheme)}>
447
+ <FloatingMenu {...defaultProps} />
448
+ </ThemeProvider>
449
+ );
450
+
451
+ const menuChildren = screen.getByTestId("menu-children");
452
+ fireEvent.click(menuChildren);
453
+
454
+ expect(screen.queryByTestId("floating-menu-wrapper")).not.toBeTruthy();
455
+ });
456
+
457
+ it("shouldn't close the floating div when select option", () => {
458
+ const buttonContent = () => <span data-testid="menu-children">texto</span>;
459
+
460
+ const defaultProps: IFloatingProps = {
461
+ children: "<div>hola</div>",
462
+ Button: buttonContent,
463
+ isInAppBar: true,
464
+ isCheckGroup: false,
465
+ reactiveToHover: true,
466
+ offset: 10,
467
+ closeOnSelect: false,
468
+ };
469
+
470
+ const wrapperRef = { current: {} };
471
+ const buttonRef = { current: {} };
472
+ const menuOptionsRef = { current: {} };
473
+
474
+ Object.defineProperty(wrapperRef, "current", {
475
+ set(_current) {
476
+ if (_current) {
477
+ jest.spyOn(_current, "contains").mockReturnValue(true);
478
+ }
479
+ this._current = _current;
480
+ },
481
+ get() {
482
+ return this._current;
483
+ },
484
+ });
485
+ Object.defineProperty(buttonRef, "current", {
486
+ set(_current) {
487
+ if (_current) {
488
+ jest.spyOn(_current, "contains").mockReturnValueOnce(true);
489
+ }
490
+ this._current = _current;
491
+ },
492
+ get() {
493
+ return this._current;
494
+ },
495
+ });
496
+ Object.defineProperty(menuOptionsRef, "current", {
497
+ set(_current) {
498
+ if (_current) {
499
+ jest.spyOn(_current, "contains").mockReturnValueOnce(false);
500
+ }
501
+ this._current = _current;
502
+ },
503
+ get() {
504
+ return this._current;
505
+ },
506
+ });
507
+
508
+ useMockRef.mockReturnValueOnce(wrapperRef);
509
+ useMockRef.mockReturnValueOnce(buttonRef);
510
+ useMockRef.mockReturnValueOnce(menuOptionsRef);
511
+
512
+ const { rerender } = render(
513
+ <ThemeProvider theme={parseTheme(globalTheme)}>
514
+ <FloatingMenu {...defaultProps} />
515
+ </ThemeProvider>
516
+ );
517
+ const floatingMenu = screen.getByTestId("floating-menu");
518
+ expect(floatingMenu).toBeTruthy();
519
+
520
+ fireEvent.click(floatingMenu);
521
+
522
+ expect(screen.getByTestId("floating-menu-wrapper")).toBeTruthy();
523
+
524
+ Object.defineProperty(wrapperRef, "current", {
525
+ set(_current) {
526
+ if (_current) {
527
+ jest.spyOn(_current, "contains").mockReturnValue(true);
528
+ }
529
+ this._current = _current;
530
+ },
531
+ get() {
532
+ return this._current;
533
+ },
534
+ });
535
+ Object.defineProperty(buttonRef, "current", {
536
+ set(_current) {
537
+ if (_current) {
538
+ jest.spyOn(_current, "contains").mockReturnValueOnce(false);
539
+ }
540
+ this._current = _current;
541
+ },
542
+ get() {
543
+ return this._current;
544
+ },
545
+ });
546
+ Object.defineProperty(menuOptionsRef, "current", {
547
+ set(_current) {
548
+ if (_current) {
549
+ jest.spyOn(_current, "contains").mockReturnValueOnce(true);
550
+ }
551
+ this._current = _current;
552
+ },
553
+ get() {
554
+ return this._current;
555
+ },
556
+ });
557
+
558
+ useMockRef.mockReturnValueOnce(wrapperRef);
559
+ useMockRef.mockReturnValueOnce(buttonRef);
560
+ useMockRef.mockReturnValueOnce(menuOptionsRef);
561
+ rerender(
562
+ <ThemeProvider theme={parseTheme(globalTheme)}>
563
+ <FloatingMenu {...defaultProps} />
564
+ </ThemeProvider>
565
+ );
566
+
567
+ const menuChildren = screen.getByTestId("menu-children");
568
+ fireEvent.click(menuChildren);
569
+
570
+ expect(screen.queryByTestId("floating-menu-wrapper")).toBeTruthy();
571
+ });
572
+
573
+ it("should open the floating menu when handle over", () => {
574
+ const buttonContent = () => <span data-testid="menu-children">texto</span>;
575
+
576
+ const defaultProps: IFloatingProps = {
577
+ children: "<div>hola</div>",
578
+ Button: buttonContent,
579
+ isInAppBar: true,
580
+ isCheckGroup: false,
581
+ reactiveToHover: true,
582
+ offset: 10,
583
+ closeOnSelect: false,
584
+ };
585
+
586
+ const wrapperRef = { current: {} };
587
+ const buttonRef = { current: {} };
588
+ const menuOptionsRef = { current: {} };
589
+
590
+ Object.defineProperty(wrapperRef, "current", {
591
+ set(_current) {
592
+ if (_current) {
593
+ jest.spyOn(_current, "contains").mockReturnValue(true);
594
+ }
595
+ this._current = _current;
596
+ },
597
+ get() {
598
+ return this._current;
599
+ },
600
+ });
601
+ Object.defineProperty(buttonRef, "current", {
602
+ set(_current) {
603
+ if (_current) {
604
+ jest.spyOn(_current, "contains").mockReturnValueOnce(true);
605
+ }
606
+ this._current = _current;
607
+ },
608
+ get() {
609
+ return this._current;
610
+ },
611
+ });
612
+ Object.defineProperty(menuOptionsRef, "current", {
613
+ set(_current) {
614
+ if (_current) {
615
+ jest.spyOn(_current, "contains").mockReturnValueOnce(false);
616
+ }
617
+ this._current = _current;
618
+ },
619
+ get() {
620
+ return this._current;
621
+ },
622
+ });
623
+
624
+ useMockRef.mockReturnValueOnce(wrapperRef);
625
+ useMockRef.mockReturnValueOnce(buttonRef);
626
+ useMockRef.mockReturnValueOnce(menuOptionsRef);
627
+
628
+ render(
629
+ <ThemeProvider theme={parseTheme(globalTheme)}>
630
+ <FloatingMenu {...defaultProps} />
631
+ </ThemeProvider>
632
+ );
633
+ const floatingMenu = screen.getByTestId("floating-menu");
634
+ expect(floatingMenu).toBeTruthy();
635
+
636
+ fireEvent.mouseEnter(floatingMenu);
637
+ expect(screen.getByTestId("floating-menu-wrapper")).toBeTruthy();
638
+ //Comprobación extra para testear que si ya está abierto, no gestiona el handleClick
639
+ fireEvent.mouseEnter(floatingMenu);
640
+ expect(screen.getByTestId("floating-menu-wrapper")).toBeTruthy();
641
+ });
642
+
643
+ it("should close the floating menu when handle leave", () => {
644
+ const buttonContent = () => <span data-testid="menu-children">texto</span>;
645
+
646
+ const defaultProps: IFloatingProps = {
647
+ children: "<div>hola</div>",
648
+ Button: buttonContent,
649
+ isInAppBar: true,
650
+ isCheckGroup: false,
651
+ reactiveToHover: true,
652
+ offset: 10,
653
+ closeOnSelect: false,
654
+ };
655
+
656
+ const wrapperRef = { current: {} };
657
+ const buttonRef = { current: {} };
658
+ const menuOptionsRef = { current: {} };
659
+
660
+ Object.defineProperty(wrapperRef, "current", {
661
+ set(_current) {
662
+ if (_current) {
663
+ jest.spyOn(_current, "contains").mockReturnValue(true);
664
+ }
665
+ this._current = _current;
666
+ },
667
+ get() {
668
+ return this._current;
669
+ },
670
+ });
671
+ Object.defineProperty(buttonRef, "current", {
672
+ set(_current) {
673
+ if (_current) {
674
+ jest.spyOn(_current, "contains").mockReturnValueOnce(true);
675
+ }
676
+ this._current = _current;
677
+ },
678
+ get() {
679
+ return this._current;
680
+ },
681
+ });
682
+ Object.defineProperty(menuOptionsRef, "current", {
683
+ set(_current) {
684
+ if (_current) {
685
+ jest.spyOn(_current, "contains").mockReturnValueOnce(false);
686
+ }
687
+ this._current = _current;
688
+ },
689
+ get() {
690
+ return this._current;
691
+ },
692
+ });
693
+
694
+ useMockRef.mockReturnValueOnce(wrapperRef);
695
+ useMockRef.mockReturnValueOnce(buttonRef);
696
+ useMockRef.mockReturnValueOnce(menuOptionsRef);
697
+
698
+ render(
699
+ <ThemeProvider theme={parseTheme(globalTheme)}>
700
+ <FloatingMenu {...defaultProps} />
701
+ </ThemeProvider>
702
+ );
703
+ const floatingMenu = screen.getByTestId("floating-menu");
704
+ expect(floatingMenu).toBeTruthy();
705
+
706
+ fireEvent.mouseEnter(floatingMenu);
707
+ expect(screen.getByTestId("floating-menu-wrapper")).toBeTruthy();
708
+
709
+ fireEvent.mouseLeave(floatingMenu);
710
+ expect(screen.queryByTestId("floating-menu-wrapper")).not.toBeTruthy();
711
+ });
712
+ });