@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.
- package/dist/CXIntegration/hooks/useUnifiedCXButton.cjs +1 -1
- package/dist/CXIntegration/hooks/useUnifiedCXButton.js +1 -1
- package/dist/CXIntegration/implementations/useGladlyUnifiedCXButton.cjs +112 -36
- package/dist/CXIntegration/implementations/useGladlyUnifiedCXButton.js +112 -36
- package/dist/debug/chatEmbed.cjs +3 -3
- package/dist/debug/chatEmbed.js +3 -3
- package/dist/debug/reportIssue.cjs +18 -6
- package/dist/debug/reportIssue.js +19 -7
- package/dist/hocs/withBaseWidget/types.d.ts +1 -1
- package/dist/hocs/withBaseWidget/withBaseWidget.cjs +2 -2
- package/dist/hocs/withBaseWidget/withBaseWidget.d.cts +2 -2
- package/dist/hocs/withBaseWidget/withBaseWidget.d.ts +2 -2
- package/dist/hocs/withBaseWidget/withBaseWidget.js +2 -2
- package/dist/widgets/ChatPreviewComparisonWidget/ChatPreviewComparisonWidget.cjs +8 -8
- package/dist/widgets/ChatPreviewComparisonWidget/ChatPreviewComparisonWidget.d.cts +3 -3
- package/dist/widgets/ChatPreviewComparisonWidget/ChatPreviewComparisonWidget.d.ts +3 -3
- package/dist/widgets/ChatPreviewComparisonWidget/ChatPreviewComparisonWidget.js +8 -8
- package/dist/widgets/ChatPreviewLoadingWidget/ChatPreviewLoadingWidget.cjs +3 -3
- package/dist/widgets/ChatPreviewLoadingWidget/ChatPreviewLoadingWidget.d.cts +3 -3
- package/dist/widgets/ChatPreviewLoadingWidget/ChatPreviewLoadingWidget.d.ts +3 -3
- package/dist/widgets/ChatPreviewLoadingWidget/ChatPreviewLoadingWidget.js +3 -3
- package/dist/widgets/ChatPreviewWidget/ChatPreviewWidget.cjs +6 -6
- package/dist/widgets/ChatPreviewWidget/ChatPreviewWidget.d.cts +3 -3
- package/dist/widgets/ChatPreviewWidget/ChatPreviewWidget.d.ts +3 -3
- package/dist/widgets/ChatPreviewWidget/ChatPreviewWidget.js +6 -6
- package/dist/widgets/FloatingChatWidget/FloatingChatWidget.cjs +7 -4
- package/dist/widgets/FloatingChatWidget/FloatingChatWidget.d.cts +2 -2
- package/dist/widgets/FloatingChatWidget/FloatingChatWidget.d.ts +2 -2
- package/dist/widgets/FloatingChatWidget/FloatingChatWidget.js +7 -4
- package/dist/widgets/FloatingChatWidget/hooks/useAutoPopup.cjs +2 -2
- package/dist/widgets/FloatingChatWidget/hooks/useAutoPopup.js +2 -2
- package/dist/widgets/FloatingChatWidget/hooks/useFloatingButtonVisibility.cjs +3 -3
- package/dist/widgets/FloatingChatWidget/hooks/useFloatingButtonVisibility.js +3 -3
- package/dist/widgets/FullPageSalesAgentWidget/FullPageSalesAgentWidget.cjs +2 -2
- package/dist/widgets/FullPageSalesAgentWidget/FullPageSalesAgentWidget.d.cts +2 -2
- package/dist/widgets/FullPageSalesAgentWidget/FullPageSalesAgentWidget.d.ts +2 -2
- package/dist/widgets/FullPageSalesAgentWidget/FullPageSalesAgentWidget.js +2 -2
- package/dist/widgets/ProductCardWidget/ProductCardWidget.cjs +4 -4
- package/dist/widgets/ProductCardWidget/ProductCardWidget.d.cts +2 -2
- package/dist/widgets/ProductCardWidget/ProductCardWidget.d.ts +2 -2
- package/dist/widgets/ProductCardWidget/ProductCardWidget.js +4 -4
- package/dist/widgets/PromptButtonCarouselWithImageWidget/PromptButtonCarouselWithImageWidget.cjs +6 -6
- package/dist/widgets/PromptButtonCarouselWithImageWidget/PromptButtonCarouselWithImageWidget.d.cts +3 -3
- package/dist/widgets/PromptButtonCarouselWithImageWidget/PromptButtonCarouselWithImageWidget.d.ts +3 -3
- package/dist/widgets/PromptButtonCarouselWithImageWidget/PromptButtonCarouselWithImageWidget.js +6 -6
- package/dist/widgets/PromptCarouselWidget/PromptCarouselWidget.cjs +3 -3
- package/dist/widgets/PromptCarouselWidget/PromptCarouselWidget.d.ts +2 -2
- package/dist/widgets/PromptCarouselWidget/PromptCarouselWidget.js +3 -3
- package/dist/widgets/SocialProofFlowWidget/SocialProofFlowWidget.cjs +2 -2
- package/dist/widgets/SocialProofFlowWidget/SocialProofFlowWidget.d.cts +2 -2
- package/dist/widgets/SocialProofFlowWidget/SocialProofFlowWidget.js +2 -2
- package/dist/widgets/SocialProofWidget/SocialProofWidget.cjs +8 -8
- package/dist/widgets/SocialProofWidget/SocialProofWidget.d.cts +3 -3
- package/dist/widgets/SocialProofWidget/SocialProofWidget.d.ts +3 -3
- package/dist/widgets/SocialProofWidget/SocialProofWidget.js +8 -8
- package/dist/widgets/TitledPromptCarouselWidget/TitledPromptCarouselWidget.cjs +2 -2
- package/dist/widgets/TitledPromptCarouselWidget/TitledPromptCarouselWidget.d.cts +2 -2
- package/dist/widgets/TitledPromptCarouselWidget/TitledPromptCarouselWidget.d.ts +2 -2
- package/dist/widgets/TitledPromptCarouselWidget/TitledPromptCarouselWidget.js +2 -2
- package/dist/widgets/TypingAnimationFlowWidget/TypingAnimationFlowWidget.cjs +2 -2
- package/dist/widgets/TypingAnimationFlowWidget/TypingAnimationFlowWidget.d.cts +2 -2
- package/dist/widgets/TypingAnimationFlowWidget/TypingAnimationFlowWidget.d.ts +2 -2
- package/dist/widgets/TypingAnimationFlowWidget/TypingAnimationFlowWidget.js +2 -2
- package/dist/widgets/TypingAnimationWidget/TypingAnimationWidget.cjs +4 -4
- package/dist/widgets/TypingAnimationWidget/TypingAnimationWidget.d.cts +3 -3
- package/dist/widgets/TypingAnimationWidget/TypingAnimationWidget.d.ts +3 -3
- package/dist/widgets/TypingAnimationWidget/TypingAnimationWidget.js +4 -4
- package/dist/widgets/hooks/useGetWidgetStatus.cjs +1 -1
- package/dist/widgets/hooks/useGetWidgetStatus.js +1 -1
- package/package.json +1 -1
- package/src/CXIntegration/implementations/__tests__/useGladlyUnifiedCXButton.test.ts +233 -0
- package/src/CXIntegration/implementations/useGladlyUnifiedCXButton.ts +173 -40
- package/src/debug/reportIssue.tsx +44 -4
- package/src/widgets/FloatingChatWidget/FloatingChatWidget.tsx +14 -1
- 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
|
+
});
|