@envive-ai/react-widgets-v3 0.3.68 → 0.3.69

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 (75) hide show
  1. package/dist/CXIntegration/hooks/useUnifiedCXButton.cjs +1 -1
  2. package/dist/CXIntegration/hooks/useUnifiedCXButton.js +1 -1
  3. package/dist/CXIntegration/implementations/useGladlyUnifiedCXButton.cjs +112 -36
  4. package/dist/CXIntegration/implementations/useGladlyUnifiedCXButton.js +112 -36
  5. package/dist/debug/chatEmbed.cjs +3 -3
  6. package/dist/debug/chatEmbed.js +3 -3
  7. package/dist/debug/reportIssue.cjs +18 -6
  8. package/dist/debug/reportIssue.js +19 -7
  9. package/dist/hocs/withBaseWidget/types.d.ts +1 -1
  10. package/dist/hocs/withBaseWidget/withBaseWidget.cjs +2 -2
  11. package/dist/hocs/withBaseWidget/withBaseWidget.d.cts +2 -2
  12. package/dist/hocs/withBaseWidget/withBaseWidget.d.ts +2 -2
  13. package/dist/hocs/withBaseWidget/withBaseWidget.js +2 -2
  14. package/dist/widgets/ChatPreviewComparisonWidget/ChatPreviewComparisonWidget.cjs +8 -8
  15. package/dist/widgets/ChatPreviewComparisonWidget/ChatPreviewComparisonWidget.d.cts +3 -3
  16. package/dist/widgets/ChatPreviewComparisonWidget/ChatPreviewComparisonWidget.d.ts +3 -3
  17. package/dist/widgets/ChatPreviewComparisonWidget/ChatPreviewComparisonWidget.js +8 -8
  18. package/dist/widgets/ChatPreviewLoadingWidget/ChatPreviewLoadingWidget.cjs +3 -3
  19. package/dist/widgets/ChatPreviewLoadingWidget/ChatPreviewLoadingWidget.d.cts +3 -3
  20. package/dist/widgets/ChatPreviewLoadingWidget/ChatPreviewLoadingWidget.d.ts +3 -3
  21. package/dist/widgets/ChatPreviewLoadingWidget/ChatPreviewLoadingWidget.js +3 -3
  22. package/dist/widgets/ChatPreviewWidget/ChatPreviewWidget.cjs +6 -6
  23. package/dist/widgets/ChatPreviewWidget/ChatPreviewWidget.d.cts +3 -3
  24. package/dist/widgets/ChatPreviewWidget/ChatPreviewWidget.d.ts +3 -3
  25. package/dist/widgets/ChatPreviewWidget/ChatPreviewWidget.js +6 -6
  26. package/dist/widgets/FloatingChatWidget/FloatingChatWidget.cjs +7 -4
  27. package/dist/widgets/FloatingChatWidget/FloatingChatWidget.d.cts +2 -2
  28. package/dist/widgets/FloatingChatWidget/FloatingChatWidget.d.ts +2 -2
  29. package/dist/widgets/FloatingChatWidget/FloatingChatWidget.js +7 -4
  30. package/dist/widgets/FloatingChatWidget/hooks/useAutoPopup.cjs +2 -2
  31. package/dist/widgets/FloatingChatWidget/hooks/useAutoPopup.js +2 -2
  32. package/dist/widgets/FloatingChatWidget/hooks/useFloatingButtonVisibility.cjs +3 -3
  33. package/dist/widgets/FloatingChatWidget/hooks/useFloatingButtonVisibility.js +3 -3
  34. package/dist/widgets/FullPageSalesAgentWidget/FullPageSalesAgentWidget.cjs +2 -2
  35. package/dist/widgets/FullPageSalesAgentWidget/FullPageSalesAgentWidget.d.cts +2 -2
  36. package/dist/widgets/FullPageSalesAgentWidget/FullPageSalesAgentWidget.d.ts +2 -2
  37. package/dist/widgets/FullPageSalesAgentWidget/FullPageSalesAgentWidget.js +2 -2
  38. package/dist/widgets/ProductCardWidget/ProductCardWidget.cjs +4 -4
  39. package/dist/widgets/ProductCardWidget/ProductCardWidget.d.cts +2 -2
  40. package/dist/widgets/ProductCardWidget/ProductCardWidget.d.ts +2 -2
  41. package/dist/widgets/ProductCardWidget/ProductCardWidget.js +4 -4
  42. package/dist/widgets/PromptButtonCarouselWithImageWidget/PromptButtonCarouselWithImageWidget.cjs +6 -6
  43. package/dist/widgets/PromptButtonCarouselWithImageWidget/PromptButtonCarouselWithImageWidget.d.cts +3 -3
  44. package/dist/widgets/PromptButtonCarouselWithImageWidget/PromptButtonCarouselWithImageWidget.d.ts +3 -3
  45. package/dist/widgets/PromptButtonCarouselWithImageWidget/PromptButtonCarouselWithImageWidget.js +6 -6
  46. package/dist/widgets/PromptCarouselWidget/PromptCarouselWidget.cjs +3 -3
  47. package/dist/widgets/PromptCarouselWidget/PromptCarouselWidget.d.ts +2 -2
  48. package/dist/widgets/PromptCarouselWidget/PromptCarouselWidget.js +3 -3
  49. package/dist/widgets/SocialProofFlowWidget/SocialProofFlowWidget.cjs +2 -2
  50. package/dist/widgets/SocialProofFlowWidget/SocialProofFlowWidget.d.cts +2 -2
  51. package/dist/widgets/SocialProofFlowWidget/SocialProofFlowWidget.js +2 -2
  52. package/dist/widgets/SocialProofWidget/SocialProofWidget.cjs +8 -8
  53. package/dist/widgets/SocialProofWidget/SocialProofWidget.d.cts +3 -3
  54. package/dist/widgets/SocialProofWidget/SocialProofWidget.d.ts +3 -3
  55. package/dist/widgets/SocialProofWidget/SocialProofWidget.js +8 -8
  56. package/dist/widgets/TitledPromptCarouselWidget/TitledPromptCarouselWidget.cjs +2 -2
  57. package/dist/widgets/TitledPromptCarouselWidget/TitledPromptCarouselWidget.d.cts +2 -2
  58. package/dist/widgets/TitledPromptCarouselWidget/TitledPromptCarouselWidget.d.ts +2 -2
  59. package/dist/widgets/TitledPromptCarouselWidget/TitledPromptCarouselWidget.js +2 -2
  60. package/dist/widgets/TypingAnimationFlowWidget/TypingAnimationFlowWidget.cjs +2 -2
  61. package/dist/widgets/TypingAnimationFlowWidget/TypingAnimationFlowWidget.d.cts +2 -2
  62. package/dist/widgets/TypingAnimationFlowWidget/TypingAnimationFlowWidget.d.ts +2 -2
  63. package/dist/widgets/TypingAnimationFlowWidget/TypingAnimationFlowWidget.js +2 -2
  64. package/dist/widgets/TypingAnimationWidget/TypingAnimationWidget.cjs +4 -4
  65. package/dist/widgets/TypingAnimationWidget/TypingAnimationWidget.d.cts +3 -3
  66. package/dist/widgets/TypingAnimationWidget/TypingAnimationWidget.d.ts +3 -3
  67. package/dist/widgets/TypingAnimationWidget/TypingAnimationWidget.js +4 -4
  68. package/dist/widgets/hooks/useGetWidgetStatus.cjs +1 -1
  69. package/dist/widgets/hooks/useGetWidgetStatus.js +1 -1
  70. package/package.json +1 -1
  71. package/src/CXIntegration/implementations/__tests__/useGladlyUnifiedCXButton.test.ts +233 -0
  72. package/src/CXIntegration/implementations/useGladlyUnifiedCXButton.ts +173 -40
  73. package/src/debug/reportIssue.tsx +44 -4
  74. package/src/widgets/FloatingChatWidget/FloatingChatWidget.tsx +14 -1
  75. package/src/widgets/FloatingChatWidget/__tests__/FloatingChatWidget.cxClose.test.tsx +138 -0
@@ -0,0 +1,138 @@
1
+ import { useState } from 'react';
2
+ import { act, render, screen } from '@testing-library/react';
3
+ import { FloatingChatWidget } from '../FloatingChatWidget';
4
+
5
+ /**
6
+ * Reproduces, without a browser, the exact state composition behind "the
7
+ * Envive floating button doesn't come back after closing Gladly": the button
8
+ * only renders when BOTH `isCXOpen` (owned by this widget) AND the Envive
9
+ * chat overlay's own `isOpen` (owned by `useChatToggle`, a separate jotai
10
+ * atom) are false. `onCXClose` must flip both.
11
+ *
12
+ * `useChatToggle` is mocked here with the same shape as the real hook
13
+ * (including the `if (isOpen) toggle()` closure-captured gate in `closeChat`)
14
+ * so this also catches a stale-closure regression, not just a logic typo.
15
+ */
16
+ let capturedOnSwitchToAgent: (() => void) | undefined;
17
+ let capturedOnCXClose: (() => void) | undefined;
18
+
19
+ vi.mock('../../../hocs/withBaseWidget', () => ({
20
+ withBaseWidget: (Widget: React.ComponentType<Record<string, unknown>>) => {
21
+ const Wrapped = (props: Record<string, unknown>) => (
22
+ <Widget
23
+ {...props}
24
+ uiConfig={{
25
+ customerServiceIntegration: {
26
+ enabled: true,
27
+ provider: 'gladly',
28
+ suppressMerchantButton: true,
29
+ },
30
+ floatingButton: { showOption: 'always' },
31
+ floatingChat: {},
32
+ lookAndFeel: {},
33
+ }}
34
+ isUiConfigLoading={false}
35
+ hardcopyContent={undefined}
36
+ />
37
+ );
38
+ return Wrapped;
39
+ },
40
+ }));
41
+
42
+ vi.mock('@envive-ai/react-toolkit-v3/FloatingButton', () => ({
43
+ FloatingButton: () => <div data-testid="floating-button">Floating Button</div>,
44
+ }));
45
+
46
+ vi.mock('@envive-ai/react-hooks/contexts/amplitudeContext', () => ({
47
+ useAmplitude: () => ({ trackEvent: vi.fn(), isReady: true }),
48
+ }));
49
+
50
+ vi.mock('@envive-ai/react-hooks/hooks/TrackComponentVisibleEvent', () => ({
51
+ useTrackComponentVisibleEvent: () => ({ isVisible: true }),
52
+ }));
53
+
54
+ vi.mock('@envive-ai/react-hooks/contexts/salesAgentContext', () => ({
55
+ useSalesAgent: () => ({}),
56
+ }));
57
+
58
+ vi.mock('@envive-ai/react-hooks/contexts/featureFlagServiceContext', () => ({
59
+ useFeatureFlagService: () => ({
60
+ featureFlagService: { isFeatureGateEnabled: vi.fn().mockReturnValue(false) },
61
+ }),
62
+ }));
63
+
64
+ vi.mock('../../hooks/useGetWidgetStatus', () => ({
65
+ default: () => ({ userHasInteractedValue: false }),
66
+ }));
67
+
68
+ vi.mock('../hooks/useFloatingButtonVisibility', () => ({
69
+ useFloatingButtonVisibility: () => ({ shouldShowFloatingButton: true }),
70
+ }));
71
+
72
+ vi.mock('../hooks/useAutoPopup', () => ({
73
+ useAutoPopup: () => {},
74
+ }));
75
+
76
+ vi.mock('src/debug/debugBar', () => ({
77
+ DebugBar: () => null,
78
+ }));
79
+
80
+ vi.mock('../FloatingChatOverlay', () => ({
81
+ FloatingChatOverlay: () => null,
82
+ }));
83
+
84
+ // Mirrors the real `useChatToggle` (packages/hooks/src/hooks/ChatToggle/useChatToggle.ts):
85
+ // `closeChat`/`openChat` only call `toggle` when the closure's own `isOpen` says it's
86
+ // necessary, exactly like the real hook's `if (isOpen) toggle(...)` guards.
87
+ vi.mock('@envive-ai/react-hooks/hooks/ChatToggle', () => ({
88
+ useChatToggle: () => {
89
+ const [isOpen, setIsOpen] = useState(true); // Envive chat starts open
90
+ const toggle = () => setIsOpen(prev => !prev);
91
+ return {
92
+ isOpen,
93
+ openChat: () => {
94
+ if (!isOpen) toggle();
95
+ },
96
+ closeChat: () => {
97
+ if (isOpen) toggle();
98
+ },
99
+ onHover: () => {},
100
+ };
101
+ },
102
+ }));
103
+
104
+ vi.mock('../../../CXIntegration/hooks/useUnifiedCXButton', () => ({
105
+ useUnifiedCXButton: (props: { onSwitchToAgent: () => void; onCXClose: () => void }) => {
106
+ capturedOnSwitchToAgent = props.onSwitchToAgent;
107
+ capturedOnCXClose = props.onCXClose;
108
+ return { isSwitchEnabled: () => true, toggle: () => {} };
109
+ },
110
+ }));
111
+
112
+ describe('FloatingChatWidget — CX close restores the floating button', () => {
113
+ beforeEach(() => {
114
+ capturedOnSwitchToAgent = undefined;
115
+ capturedOnCXClose = undefined;
116
+ });
117
+
118
+ it('does not render the floating button while the CX chat (Gladly) is open', () => {
119
+ render(<FloatingChatWidget />);
120
+
121
+ expect(capturedOnSwitchToAgent).toBeDefined();
122
+ act(() => capturedOnSwitchToAgent?.());
123
+
124
+ expect(screen.queryByTestId('floating-button')).toBeNull();
125
+ });
126
+
127
+ it('renders the floating button again once the CX chat closes, even though the Envive overlay was still open the whole time', () => {
128
+ render(<FloatingChatWidget />);
129
+
130
+ act(() => capturedOnSwitchToAgent?.());
131
+ expect(screen.queryByTestId('floating-button')).toBeNull();
132
+
133
+ expect(capturedOnCXClose).toBeDefined();
134
+ act(() => capturedOnCXClose?.());
135
+
136
+ expect(screen.getByTestId('floating-button')).toBeInTheDocument();
137
+ });
138
+ });