@envive-ai/react-hooks 0.3.32 → 0.3.33
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/application/commerce-api.d.cts +1 -1
- package/dist/application/commerce-api.d.ts +1 -1
- package/dist/atoms/app/index.d.cts +9 -9
- package/dist/atoms/app/index.d.ts +9 -9
- package/dist/atoms/app/variant.d.cts +8 -8
- package/dist/atoms/app/variant.d.ts +8 -8
- package/dist/atoms/chat/chatState.d.cts +20 -20
- package/dist/atoms/chat/chatState.d.ts +20 -20
- package/dist/atoms/chat/form.d.cts +2 -2
- package/dist/atoms/chat/form.d.ts +2 -2
- package/dist/atoms/chat/index.cjs +1 -1
- package/dist/atoms/chat/index.d.cts +3 -3
- package/dist/atoms/chat/index.d.ts +2 -2
- package/dist/atoms/chat/index.js +1 -1
- package/dist/atoms/chat/lastMessage.d.ts +2 -2
- package/dist/atoms/chat/messageQueue.d.cts +6 -6
- package/dist/atoms/chat/messageQueue.d.ts +6 -6
- package/dist/atoms/chat/performanceMetrics.d.ts +6 -6
- package/dist/atoms/chat/renderedWidgetRefs.d.cts +2 -2
- package/dist/atoms/chat/renderedWidgetRefs.d.ts +3 -3
- package/dist/atoms/chat/replies.d.ts +3 -3
- package/dist/atoms/chat/suggestions.d.cts +2 -2
- package/dist/atoms/chat/suggestions.d.ts +2 -2
- package/dist/atoms/envive/enviveConfig.d.cts +13 -13
- package/dist/atoms/envive/enviveConfig.d.ts +13 -13
- package/dist/atoms/globalSearch/globalSearch.d.cts +5 -5
- package/dist/atoms/globalSearch/globalSearch.d.ts +6 -6
- package/dist/atoms/org/customerService.d.cts +6 -6
- package/dist/atoms/org/customerService.d.ts +6 -6
- package/dist/atoms/org/graphqlConfig.d.cts +5 -5
- package/dist/atoms/org/graphqlConfig.d.ts +5 -5
- package/dist/atoms/org/index.cjs +2 -3
- package/dist/atoms/org/index.d.cts +2 -2
- package/dist/atoms/org/index.d.ts +2 -2
- package/dist/atoms/org/index.js +3 -3
- package/dist/atoms/org/newOrgConfigAtom.d.cts +2 -2
- package/dist/atoms/org/newOrgConfigAtom.d.ts +2 -2
- package/dist/atoms/org/orgAnalyticsConfig.cjs +1 -3
- package/dist/atoms/org/orgAnalyticsConfig.d.cts +7 -8
- package/dist/atoms/org/orgAnalyticsConfig.d.ts +7 -8
- package/dist/atoms/org/orgAnalyticsConfig.js +2 -3
- package/dist/atoms/search/chatSearch.cjs +1 -1
- package/dist/atoms/search/chatSearch.d.cts +17 -17
- package/dist/atoms/search/chatSearch.d.ts +17 -17
- package/dist/atoms/search/chatSearch.js +1 -1
- package/dist/atoms/search/searchAPI.cjs +1 -1
- package/dist/atoms/search/searchAPI.d.cts +13 -13
- package/dist/atoms/search/searchAPI.d.ts +13 -13
- package/dist/atoms/search/searchAPI.js +1 -1
- package/dist/atoms/widget/chatPreviewLoading.d.ts +2 -2
- package/dist/contexts/amplitudeContext/amplitudeContext.cjs +1 -5
- package/dist/contexts/amplitudeContext/amplitudeContext.js +1 -5
- package/dist/contexts/enviveConfigContext/enviveConfigContext.cjs +18 -23
- package/dist/contexts/enviveConfigContext/enviveConfigContext.d.cts +10 -12
- package/dist/contexts/enviveConfigContext/enviveConfigContext.d.ts +10 -12
- package/dist/contexts/enviveConfigContext/enviveConfigContext.js +18 -23
- package/dist/contexts/enviveContext/enviveContext.cjs +41 -74
- package/dist/contexts/enviveContext/enviveContext.d.cts +15 -32
- package/dist/contexts/enviveContext/enviveContext.d.ts +15 -32
- package/dist/contexts/enviveContext/enviveContext.js +41 -74
- package/dist/contexts/enviveContext/index.d.cts +2 -2
- package/dist/contexts/enviveContext/index.d.ts +2 -2
- package/dist/contexts/enviveCssContext/enviveCssContext.cjs +31 -16
- package/dist/contexts/enviveCssContext/enviveCssContext.js +31 -16
- package/dist/contexts/graphqlContext/graphqlContext.cjs +3 -212
- package/dist/contexts/graphqlContext/graphqlContext.d.cts +2 -10
- package/dist/contexts/graphqlContext/graphqlContext.d.ts +2 -10
- package/dist/contexts/graphqlContext/graphqlContext.js +3 -212
- package/dist/contexts/graphqlContext/mockV3Config.cjs +31 -16
- package/dist/contexts/graphqlContext/mockV3Config.js +31 -16
- package/dist/contexts/hardcopyContext/hardcopyContext.cjs +9 -238
- package/dist/contexts/hardcopyContext/hardcopyContext.d.cts +5 -17
- package/dist/contexts/hardcopyContext/hardcopyContext.d.ts +5 -17
- package/dist/contexts/hardcopyContext/hardcopyContext.js +9 -238
- package/dist/contexts/hardcopyContext/index.d.cts +3 -2
- package/dist/contexts/hardcopyContext/index.d.ts +3 -2
- package/dist/contexts/newOrgConfigContext/newOrgConfigContext.cjs +10 -32
- package/dist/contexts/newOrgConfigContext/newOrgConfigContext.d.cts +2 -2
- package/dist/contexts/newOrgConfigContext/newOrgConfigContext.d.ts +2 -2
- package/dist/contexts/newOrgConfigContext/newOrgConfigContext.js +12 -34
- package/dist/contexts/pageContext/mapping.d.cts +1 -1
- package/dist/contexts/pageContext/mapping.d.ts +1 -1
- package/dist/contexts/pageContext/types.d.cts +1 -1
- package/dist/contexts/salesAgentContext/chatAPI.cjs +2 -2
- package/dist/contexts/salesAgentContext/chatAPI.js +2 -2
- package/dist/contexts/salesAgentContext/salesAgentService.cjs +1 -1
- package/dist/contexts/salesAgentContext/salesAgentService.js +1 -1
- package/dist/contexts/searchContext/searchContext.cjs +1 -1
- package/dist/contexts/searchContext/searchContext.js +1 -1
- package/dist/contexts/systemSettingsContext/systemSettingsContext.d.cts +2 -2
- package/dist/contexts/types.d.cts +2 -2
- package/dist/contexts/types.d.ts +2 -2
- package/dist/contexts/typesV3.cjs +31 -16
- package/dist/contexts/typesV3.d.cts +62 -31
- package/dist/contexts/typesV3.d.ts +62 -31
- package/dist/contexts/typesV3.js +31 -16
- package/dist/contexts/userIdentityContext/userIdentityContext.cjs +1 -1
- package/dist/contexts/userIdentityContext/userIdentityContext.d.cts +3 -3
- package/dist/contexts/userIdentityContext/userIdentityContext.d.ts +3 -3
- package/dist/contexts/userIdentityContext/userIdentityContext.js +1 -1
- package/dist/hooks/ChatToggle/useChatToggle.cjs +1 -1
- package/dist/hooks/ChatToggle/useChatToggle.js +1 -1
- package/dist/hooks/GrabAndScroll/useGrabAndScroll.d.cts +2 -2
- package/dist/hooks/GraphQLConfig/index.cjs +0 -1
- package/dist/hooks/GraphQLConfig/index.d.cts +2 -2
- package/dist/hooks/GraphQLConfig/index.d.ts +2 -2
- package/dist/hooks/GraphQLConfig/index.js +2 -2
- package/dist/hooks/GraphQLConfig/useGraphQLConfig.cjs +7 -66
- package/dist/hooks/GraphQLConfig/useGraphQLConfig.d.cts +5 -13
- package/dist/hooks/GraphQLConfig/useGraphQLConfig.d.ts +5 -13
- package/dist/hooks/GraphQLConfig/useGraphQLConfig.js +8 -66
- package/dist/hooks/Search/useSearch.cjs +3 -3
- package/dist/hooks/Search/useSearch.js +3 -3
- package/dist/services/amplitudeService/amplitudeService.cjs +4 -3
- package/dist/services/amplitudeService/amplitudeService.d.cts +1 -2
- package/dist/services/amplitudeService/amplitudeService.d.ts +1 -2
- package/dist/services/amplitudeService/amplitudeService.js +4 -3
- package/dist/services/enviveConfigService/enviveConfigService.cjs +25 -5
- package/dist/services/enviveConfigService/enviveConfigService.d.cts +24 -5
- package/dist/services/enviveConfigService/enviveConfigService.d.ts +24 -5
- package/dist/services/enviveConfigService/enviveConfigService.js +25 -6
- package/dist/services/enviveConfigService/fetchGraphQLConfig.cjs +181 -0
- package/dist/services/enviveConfigService/fetchGraphQLConfig.js +180 -0
- package/dist/services/enviveConfigService/index.cjs +2 -1
- package/dist/services/enviveConfigService/index.d.cts +2 -2
- package/dist/services/enviveConfigService/index.d.ts +2 -2
- package/dist/services/enviveConfigService/index.js +2 -2
- package/dist/services/hardcopyService/hardcopyService.cjs +232 -0
- package/dist/services/hardcopyService/hardcopyService.d.cts +39 -0
- package/dist/services/hardcopyService/hardcopyService.d.ts +39 -0
- package/dist/services/hardcopyService/hardcopyService.js +229 -0
- package/dist/services/hardcopyService/index.cjs +5 -0
- package/dist/services/hardcopyService/index.d.cts +2 -0
- package/dist/services/hardcopyService/index.d.ts +2 -0
- package/dist/services/hardcopyService/index.js +3 -0
- package/dist/services/userIdentityService/index.cjs +1 -0
- package/dist/services/userIdentityService/index.d.cts +2 -2
- package/dist/services/userIdentityService/index.d.ts +2 -2
- package/dist/services/userIdentityService/index.js +2 -2
- package/dist/services/userIdentityService/userIdentityService.cjs +13 -1
- package/dist/services/userIdentityService/userIdentityService.d.cts +12 -2
- package/dist/services/userIdentityService/userIdentityService.d.ts +12 -2
- package/dist/services/userIdentityService/userIdentityService.js +13 -2
- package/dist/types/enviveConfig.d.cts +1 -1
- package/dist/types/enviveConfig.d.ts +1 -1
- package/package.json +5 -1
- package/src/atoms/org/orgAnalyticsConfig.ts +0 -5
- package/src/contexts/amplitudeContext/amplitudeContext.tsx +0 -4
- package/src/contexts/enviveConfigContext/enviveConfigContext.tsx +37 -49
- package/src/contexts/enviveContext/enviveContext.tsx +72 -134
- package/src/contexts/enviveCssContext/enviveCssContext.tsx +32 -17
- package/src/contexts/graphqlContext/__tests__/graphqlContext.test.tsx +3 -36
- package/src/contexts/graphqlContext/graphqlContext.tsx +4 -304
- package/src/contexts/graphqlContext/mockV3Config.ts +30 -15
- package/src/contexts/hardcopyContext/hardcopyContext.tsx +12 -270
- package/src/contexts/newOrgConfigContext/__tests__/newOrgConfigContext.test.tsx +54 -478
- package/src/contexts/newOrgConfigContext/newOrgConfigContext.tsx +9 -26
- package/src/contexts/typesV3.ts +61 -30
- package/src/contexts/userIdentityContext/userIdentityContext.tsx +2 -2
- package/src/hooks/GraphQLConfig/useGraphQLConfig.ts +2 -62
- package/src/hooks/Search/__tests__/useSearch.test.tsx +2 -2
- package/src/services/amplitudeService/__tests__/amplitudeService.test.ts +3 -5
- package/src/services/amplitudeService/amplitudeService.ts +5 -3
- package/src/services/enviveConfigService/__tests__/fetchGraphQLConfig.test.ts +425 -0
- package/src/services/enviveConfigService/enviveConfigService.ts +41 -13
- package/src/services/enviveConfigService/fetchGraphQLConfig.ts +225 -0
- package/src/services/hardcopyService/__tests__/hardcopyService.test.ts +367 -0
- package/src/services/hardcopyService/hardcopyService.ts +271 -0
- package/src/services/hardcopyService/index.ts +1 -0
- package/src/services/userIdentityService/userIdentityService.ts +18 -0
|
@@ -1,19 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
3
3
|
import { Provider, useAtomValue } from 'jotai';
|
|
4
|
-
import { EnviveConfigProvider } from 'src/contexts/enviveConfigContext/enviveConfigContext';
|
|
5
|
-
import { GraphQLProvider } from 'src/contexts/graphqlContext/graphqlContext';
|
|
6
|
-
import { LocalStorageProvider } from 'src/contexts/localStorageContext/localStorageContext';
|
|
7
4
|
import { newOrgConfigAtom } from 'src/atoms/org/newOrgConfigAtom';
|
|
8
|
-
import {
|
|
9
|
-
import { useUIConfig } from 'src/hooks/GraphQLConfig/useGraphQLConfig';
|
|
5
|
+
import { GraphQlConfigValues } from 'src/contexts/graphqlContext/graphqlContext';
|
|
10
6
|
import { NewOrgConfigProvider, useNewOrgConfigContext } from '../newOrgConfigContext';
|
|
11
7
|
|
|
12
|
-
// Mock the useUIConfig hook
|
|
13
|
-
vi.mock('src/hooks/GraphQLConfig/useGraphQLConfig', () => ({
|
|
14
|
-
useUIConfig: vi.fn(),
|
|
15
|
-
}));
|
|
16
|
-
|
|
17
8
|
// Component that uses the useNewOrgConfigContext hook
|
|
18
9
|
const MockNewOrgConfigComponent: React.FC = () => {
|
|
19
10
|
const config = useNewOrgConfigContext();
|
|
@@ -24,7 +15,6 @@ const MockNewOrgConfigComponent: React.FC = () => {
|
|
|
24
15
|
<div data-testid="has-error">{config.error ? 'true' : 'false'}</div>
|
|
25
16
|
<div data-testid="has-colors-config">{config.colorsConfig ? 'true' : 'false'}</div>
|
|
26
17
|
<div data-testid="has-frontend-config">{config.frontendConfig ? 'true' : 'false'}</div>
|
|
27
|
-
{config.error && <div data-testid="error-message">{config.error.message}</div>}
|
|
28
18
|
</div>
|
|
29
19
|
);
|
|
30
20
|
};
|
|
@@ -32,11 +22,9 @@ const MockNewOrgConfigComponent: React.FC = () => {
|
|
|
32
22
|
// Component that reads the atom directly to verify it's set
|
|
33
23
|
const AtomReaderComponent: React.FC = () => {
|
|
34
24
|
const config = useAtomValue(newOrgConfigAtom);
|
|
35
|
-
const orgShortName = useAtomValue(orgShortNameAtom);
|
|
36
25
|
|
|
37
26
|
return (
|
|
38
27
|
<div data-testid="atom-reader">
|
|
39
|
-
<div data-testid="atom-org-short-name">{orgShortName || 'not-set'}</div>
|
|
40
28
|
<div data-testid="atom-has-config">{config ? 'has-config' : 'no-config'}</div>
|
|
41
29
|
{config && (
|
|
42
30
|
<>
|
|
@@ -48,42 +36,14 @@ const AtomReaderComponent: React.FC = () => {
|
|
|
48
36
|
);
|
|
49
37
|
};
|
|
50
38
|
|
|
51
|
-
// Wrapper component to ensure providers are in correct order
|
|
52
39
|
const TestWrapper: React.FC<{
|
|
53
40
|
children: React.ReactNode;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}> = ({ children, orgShortName, mockHookData = {} }) => {
|
|
61
|
-
// Mock the hook
|
|
62
|
-
const mockUseUIConfig = useUIConfig as any;
|
|
63
|
-
mockUseUIConfig.mockReturnValue({
|
|
64
|
-
data: mockHookData.data || {},
|
|
65
|
-
loading: mockHookData.loading ?? false,
|
|
66
|
-
error: mockHookData.error || null,
|
|
67
|
-
refetch: vi.fn(),
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
return (
|
|
71
|
-
<Provider>
|
|
72
|
-
<EnviveConfigProvider
|
|
73
|
-
identifyingPrefix="test"
|
|
74
|
-
orgShortName={orgShortName}
|
|
75
|
-
baseUrl="https://test-api.example.com"
|
|
76
|
-
orgLevelApiKey="test-key"
|
|
77
|
-
>
|
|
78
|
-
<LocalStorageProvider>
|
|
79
|
-
<GraphQLProvider>
|
|
80
|
-
<NewOrgConfigProvider>{children}</NewOrgConfigProvider>
|
|
81
|
-
</GraphQLProvider>
|
|
82
|
-
</LocalStorageProvider>
|
|
83
|
-
</EnviveConfigProvider>
|
|
84
|
-
</Provider>
|
|
85
|
-
);
|
|
86
|
-
};
|
|
41
|
+
config?: GraphQlConfigValues;
|
|
42
|
+
}> = ({ children, config = {} }) => (
|
|
43
|
+
<Provider>
|
|
44
|
+
<NewOrgConfigProvider config={config}>{children}</NewOrgConfigProvider>
|
|
45
|
+
</Provider>
|
|
46
|
+
);
|
|
87
47
|
|
|
88
48
|
describe('NewOrgConfigProvider', () => {
|
|
89
49
|
beforeEach(() => {
|
|
@@ -92,16 +52,13 @@ describe('NewOrgConfigProvider', () => {
|
|
|
92
52
|
|
|
93
53
|
describe('useNewOrgConfigContext Hook Integration', () => {
|
|
94
54
|
it('should provide context through useNewOrgConfigContext hook', async () => {
|
|
95
|
-
const
|
|
96
|
-
colorsConfig: { accentPrimary: '#FF0000' },
|
|
97
|
-
frontendConfig: { merchantOverrideCss: 'test-css' },
|
|
55
|
+
const config: GraphQlConfigValues = {
|
|
56
|
+
colorsConfig: { accentPrimary: '#FF0000' } as any,
|
|
57
|
+
frontendConfig: { merchantOverrideCss: 'test-css' } as any,
|
|
98
58
|
};
|
|
99
59
|
|
|
100
60
|
render(
|
|
101
|
-
<TestWrapper
|
|
102
|
-
orgShortName="test-org"
|
|
103
|
-
mockHookData={{ data: mockData }}
|
|
104
|
-
>
|
|
61
|
+
<TestWrapper config={config}>
|
|
105
62
|
<MockNewOrgConfigComponent />
|
|
106
63
|
</TestWrapper>,
|
|
107
64
|
);
|
|
@@ -110,7 +67,6 @@ describe('NewOrgConfigProvider', () => {
|
|
|
110
67
|
expect(screen.getByTestId('loading')).toHaveTextContent('false');
|
|
111
68
|
});
|
|
112
69
|
|
|
113
|
-
expect(screen.getByTestId('new-org-config-component')).toBeInTheDocument();
|
|
114
70
|
expect(screen.getByTestId('has-colors-config')).toHaveTextContent('true');
|
|
115
71
|
expect(screen.getByTestId('has-frontend-config')).toHaveTextContent('true');
|
|
116
72
|
});
|
|
@@ -141,40 +97,10 @@ describe('NewOrgConfigProvider', () => {
|
|
|
141
97
|
});
|
|
142
98
|
});
|
|
143
99
|
|
|
144
|
-
describe('Loading State', () => {
|
|
145
|
-
it('should
|
|
146
|
-
render(
|
|
147
|
-
<TestWrapper
|
|
148
|
-
orgShortName="test-org"
|
|
149
|
-
mockHookData={{ loading: true, data: {} }}
|
|
150
|
-
>
|
|
151
|
-
<MockNewOrgConfigComponent />
|
|
152
|
-
</TestWrapper>,
|
|
153
|
-
);
|
|
154
|
-
|
|
155
|
-
await waitFor(() => {
|
|
156
|
-
expect(screen.getByTestId('loading')).toHaveTextContent('true');
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it('should show loading state when orgShortName is not available', async () => {
|
|
161
|
-
render(
|
|
162
|
-
<TestWrapper mockHookData={{ data: {}, loading: false }}>
|
|
163
|
-
<MockNewOrgConfigComponent />
|
|
164
|
-
</TestWrapper>,
|
|
165
|
-
);
|
|
166
|
-
|
|
167
|
-
await waitFor(() => {
|
|
168
|
-
expect(screen.getByTestId('loading')).toHaveTextContent('true');
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it('should not show loading when orgShortName is available and hook is not loading', async () => {
|
|
100
|
+
describe('Loading and Error State', () => {
|
|
101
|
+
it('should always have loading false', async () => {
|
|
173
102
|
render(
|
|
174
|
-
<TestWrapper
|
|
175
|
-
orgShortName="test-org"
|
|
176
|
-
mockHookData={{ data: {}, loading: false }}
|
|
177
|
-
>
|
|
103
|
+
<TestWrapper config={{}}>
|
|
178
104
|
<MockNewOrgConfigComponent />
|
|
179
105
|
</TestWrapper>,
|
|
180
106
|
);
|
|
@@ -183,169 +109,88 @@ describe('NewOrgConfigProvider', () => {
|
|
|
183
109
|
expect(screen.getByTestId('loading')).toHaveTextContent('false');
|
|
184
110
|
});
|
|
185
111
|
});
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
describe('Error Handling', () => {
|
|
189
|
-
it('should handle errors from useUIConfig', async () => {
|
|
190
|
-
const testError = new Error('Failed to fetch config');
|
|
191
112
|
|
|
113
|
+
it('should always have error null', async () => {
|
|
192
114
|
render(
|
|
193
|
-
<TestWrapper
|
|
194
|
-
orgShortName="test-org"
|
|
195
|
-
mockHookData={{ error: testError, loading: false, data: {} }}
|
|
196
|
-
>
|
|
115
|
+
<TestWrapper config={{}}>
|
|
197
116
|
<MockNewOrgConfigComponent />
|
|
198
117
|
</TestWrapper>,
|
|
199
118
|
);
|
|
200
119
|
|
|
201
120
|
await waitFor(() => {
|
|
202
|
-
expect(screen.getByTestId('has-error')).toHaveTextContent('
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
expect(screen.getByTestId('error-message')).toHaveTextContent('Failed to fetch config');
|
|
206
|
-
expect(screen.getByTestId('loading')).toHaveTextContent('false');
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
it('should return error state without throwing', async () => {
|
|
210
|
-
const testError = new Error('Network error');
|
|
211
|
-
|
|
212
|
-
render(
|
|
213
|
-
<TestWrapper
|
|
214
|
-
orgShortName="test-org"
|
|
215
|
-
mockHookData={{ error: testError, loading: false, data: {} }}
|
|
216
|
-
>
|
|
217
|
-
<MockNewOrgConfigComponent />
|
|
218
|
-
</TestWrapper>,
|
|
219
|
-
);
|
|
220
|
-
|
|
221
|
-
await waitFor(() => {
|
|
222
|
-
expect(screen.getByTestId('has-error')).toHaveTextContent('true');
|
|
121
|
+
expect(screen.getByTestId('has-error')).toHaveTextContent('false');
|
|
223
122
|
});
|
|
224
|
-
|
|
225
|
-
// Component should still render without crashing
|
|
226
|
-
expect(screen.getByTestId('new-org-config-component')).toBeInTheDocument();
|
|
227
123
|
});
|
|
228
124
|
});
|
|
229
125
|
|
|
230
126
|
describe('Atom Integration', () => {
|
|
231
|
-
it('should set newOrgConfigAtom when
|
|
232
|
-
const
|
|
233
|
-
colorsConfig: { accentPrimary: '#FF0000', accentSecondary: '#00FF00' },
|
|
234
|
-
frontendConfig: { merchantOverrideCss: 'test-css' },
|
|
127
|
+
it('should set newOrgConfigAtom when config is provided', async () => {
|
|
128
|
+
const config: GraphQlConfigValues = {
|
|
129
|
+
colorsConfig: { accentPrimary: '#FF0000', accentSecondary: '#00FF00' } as any,
|
|
130
|
+
frontendConfig: { merchantOverrideCss: 'test-css' } as any,
|
|
235
131
|
};
|
|
236
132
|
|
|
237
133
|
render(
|
|
238
|
-
<TestWrapper
|
|
239
|
-
orgShortName="test-org"
|
|
240
|
-
mockHookData={{ data: mockData, loading: false }}
|
|
241
|
-
>
|
|
134
|
+
<TestWrapper config={config}>
|
|
242
135
|
<AtomReaderComponent />
|
|
243
136
|
</TestWrapper>,
|
|
244
137
|
);
|
|
245
138
|
|
|
246
139
|
await waitFor(() => {
|
|
247
|
-
expect(screen.getByTestId('atom-
|
|
140
|
+
expect(screen.getByTestId('atom-has-config')).toHaveTextContent('has-config');
|
|
248
141
|
});
|
|
249
142
|
|
|
250
|
-
await waitFor(
|
|
251
|
-
() => {
|
|
252
|
-
expect(screen.getByTestId('atom-has-config')).toHaveTextContent('has-config');
|
|
253
|
-
},
|
|
254
|
-
{ timeout: 2000 },
|
|
255
|
-
);
|
|
256
|
-
|
|
257
143
|
expect(screen.getByTestId('atom-has-colors')).toHaveTextContent('true');
|
|
258
144
|
expect(screen.getByTestId('atom-has-frontend')).toHaveTextContent('true');
|
|
259
145
|
});
|
|
260
146
|
|
|
261
|
-
it('should
|
|
262
|
-
const
|
|
263
|
-
colorsConfig: { accentPrimary: '#FF0000' },
|
|
264
|
-
frontendConfig: {},
|
|
147
|
+
it('should update atom when config prop changes', async () => {
|
|
148
|
+
const initialConfig: GraphQlConfigValues = {
|
|
149
|
+
colorsConfig: { accentPrimary: '#FF0000' } as any,
|
|
265
150
|
};
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
<AtomReaderComponent />
|
|
270
|
-
</TestWrapper>,
|
|
271
|
-
);
|
|
272
|
-
|
|
273
|
-
await waitFor(() => {
|
|
274
|
-
expect(screen.getByTestId('atom-org-short-name')).toHaveTextContent('not-set');
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
// Atom should not be set when orgShortName is missing
|
|
278
|
-
await waitFor(() => {
|
|
279
|
-
const hasConfig = screen.getByTestId('atom-has-config').textContent;
|
|
280
|
-
// The atom might be set to null or not set at all
|
|
281
|
-
expect(hasConfig).toBeDefined();
|
|
282
|
-
});
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
it('should not set atom when loading', async () => {
|
|
286
|
-
const mockData = {
|
|
287
|
-
colorsConfig: { accentPrimary: '#FF0000' },
|
|
151
|
+
const updatedConfig: GraphQlConfigValues = {
|
|
152
|
+
colorsConfig: { accentPrimary: '#0000FF' } as any,
|
|
153
|
+
frontendConfig: { merchantOverrideCss: 'updated-css' } as any,
|
|
288
154
|
};
|
|
289
155
|
|
|
290
|
-
render(
|
|
291
|
-
<
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
</TestWrapper>,
|
|
156
|
+
const { rerender } = render(
|
|
157
|
+
<Provider>
|
|
158
|
+
<NewOrgConfigProvider config={initialConfig}>
|
|
159
|
+
<AtomReaderComponent />
|
|
160
|
+
</NewOrgConfigProvider>
|
|
161
|
+
</Provider>,
|
|
297
162
|
);
|
|
298
163
|
|
|
299
164
|
await waitFor(() => {
|
|
300
|
-
expect(screen.getByTestId('atom-
|
|
165
|
+
expect(screen.getByTestId('atom-has-config')).toHaveTextContent('has-config');
|
|
301
166
|
});
|
|
302
167
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
colorsConfig: { accentPrimary: '#FF0000' },
|
|
310
|
-
frontendConfig: { merchantOverrideCss: 'test-css' },
|
|
311
|
-
};
|
|
312
|
-
|
|
313
|
-
render(
|
|
314
|
-
<TestWrapper
|
|
315
|
-
orgShortName="test-org"
|
|
316
|
-
mockHookData={{ data: mockData, loading: false }}
|
|
317
|
-
>
|
|
318
|
-
<AtomReaderComponent />
|
|
319
|
-
</TestWrapper>,
|
|
168
|
+
rerender(
|
|
169
|
+
<Provider>
|
|
170
|
+
<NewOrgConfigProvider config={updatedConfig}>
|
|
171
|
+
<AtomReaderComponent />
|
|
172
|
+
</NewOrgConfigProvider>
|
|
173
|
+
</Provider>,
|
|
320
174
|
);
|
|
321
175
|
|
|
322
176
|
await waitFor(() => {
|
|
323
|
-
expect(screen.getByTestId('atom-has-
|
|
177
|
+
expect(screen.getByTestId('atom-has-frontend')).toHaveTextContent('true');
|
|
324
178
|
});
|
|
325
|
-
|
|
326
|
-
expect(screen.getByTestId('atom-has-colors')).toHaveTextContent('true');
|
|
327
|
-
expect(screen.getByTestId('atom-has-frontend')).toHaveTextContent('true');
|
|
328
179
|
});
|
|
329
180
|
});
|
|
330
181
|
|
|
331
182
|
describe('Context Value', () => {
|
|
332
183
|
it('should provide colorsConfig and frontendConfig in context', async () => {
|
|
333
|
-
const
|
|
184
|
+
const config: GraphQlConfigValues = {
|
|
334
185
|
colorsConfig: {
|
|
335
186
|
accentPrimary: '#FF0000',
|
|
336
187
|
accentSecondary: '#00FF00',
|
|
337
|
-
|
|
338
|
-
},
|
|
339
|
-
frontendConfig: {
|
|
340
|
-
merchantOverrideCss: 'test-css',
|
|
341
|
-
},
|
|
188
|
+
} as any,
|
|
189
|
+
frontendConfig: { merchantOverrideCss: 'test-css' } as any,
|
|
342
190
|
};
|
|
343
191
|
|
|
344
192
|
render(
|
|
345
|
-
<TestWrapper
|
|
346
|
-
orgShortName="test-org"
|
|
347
|
-
mockHookData={{ data: mockData, loading: false }}
|
|
348
|
-
>
|
|
193
|
+
<TestWrapper config={config}>
|
|
349
194
|
<MockNewOrgConfigComponent />
|
|
350
195
|
</TestWrapper>,
|
|
351
196
|
);
|
|
@@ -357,12 +202,9 @@ describe('NewOrgConfigProvider', () => {
|
|
|
357
202
|
expect(screen.getByTestId('has-frontend-config')).toHaveTextContent('true');
|
|
358
203
|
});
|
|
359
204
|
|
|
360
|
-
it('should provide empty config when
|
|
205
|
+
it('should provide empty config when config is empty', async () => {
|
|
361
206
|
render(
|
|
362
|
-
<TestWrapper
|
|
363
|
-
orgShortName="test-org"
|
|
364
|
-
mockHookData={{ data: {}, loading: false }}
|
|
365
|
-
>
|
|
207
|
+
<TestWrapper config={{}}>
|
|
366
208
|
<MockNewOrgConfigComponent />
|
|
367
209
|
</TestWrapper>,
|
|
368
210
|
);
|
|
@@ -374,41 +216,14 @@ describe('NewOrgConfigProvider', () => {
|
|
|
374
216
|
expect(screen.getByTestId('has-colors-config')).toHaveTextContent('false');
|
|
375
217
|
expect(screen.getByTestId('has-frontend-config')).toHaveTextContent('false');
|
|
376
218
|
});
|
|
377
|
-
|
|
378
|
-
it('should merge loading and error states with config data', async () => {
|
|
379
|
-
const mockData = {
|
|
380
|
-
colorsConfig: { accentPrimary: '#FF0000' },
|
|
381
|
-
};
|
|
382
|
-
|
|
383
|
-
render(
|
|
384
|
-
<TestWrapper
|
|
385
|
-
orgShortName="test-org"
|
|
386
|
-
mockHookData={{ data: mockData, loading: false }}
|
|
387
|
-
>
|
|
388
|
-
<MockNewOrgConfigComponent />
|
|
389
|
-
</TestWrapper>,
|
|
390
|
-
);
|
|
391
|
-
|
|
392
|
-
await waitFor(() => {
|
|
393
|
-
expect(screen.getByTestId('loading')).toHaveTextContent('false');
|
|
394
|
-
expect(screen.getByTestId('has-error')).toHaveTextContent('false');
|
|
395
|
-
expect(screen.getByTestId('has-colors-config')).toHaveTextContent('true');
|
|
396
|
-
});
|
|
397
|
-
});
|
|
398
219
|
});
|
|
399
220
|
|
|
400
|
-
describe('
|
|
401
|
-
it('should
|
|
402
|
-
const TestChild: React.FC = () =>
|
|
403
|
-
// This should work because FeatureFlagServiceProvider is wrapping it
|
|
404
|
-
return <div data-testid="child">Child Component</div>;
|
|
405
|
-
};
|
|
221
|
+
describe('Children rendering', () => {
|
|
222
|
+
it('should render children', async () => {
|
|
223
|
+
const TestChild: React.FC = () => <div data-testid="child">Child Component</div>;
|
|
406
224
|
|
|
407
225
|
render(
|
|
408
|
-
<TestWrapper
|
|
409
|
-
orgShortName="test-org"
|
|
410
|
-
mockHookData={{ data: {}, loading: false }}
|
|
411
|
-
>
|
|
226
|
+
<TestWrapper config={{}}>
|
|
412
227
|
<TestChild />
|
|
413
228
|
</TestWrapper>,
|
|
414
229
|
);
|
|
@@ -417,7 +232,6 @@ describe('NewOrgConfigProvider', () => {
|
|
|
417
232
|
expect(screen.getByTestId('child')).toBeInTheDocument();
|
|
418
233
|
});
|
|
419
234
|
|
|
420
|
-
// Verify the child is rendered (which means FeatureFlagServiceProvider is working)
|
|
421
235
|
expect(screen.getByTestId('child')).toHaveTextContent('Child Component');
|
|
422
236
|
});
|
|
423
237
|
});
|
|
@@ -440,10 +254,7 @@ describe('NewOrgConfigProvider', () => {
|
|
|
440
254
|
};
|
|
441
255
|
|
|
442
256
|
render(
|
|
443
|
-
<TestWrapper
|
|
444
|
-
orgShortName="test-org"
|
|
445
|
-
mockHookData={{ data: {}, loading: false }}
|
|
446
|
-
>
|
|
257
|
+
<TestWrapper config={{}}>
|
|
447
258
|
<Component1 />
|
|
448
259
|
<Component2 />
|
|
449
260
|
</TestWrapper>,
|
|
@@ -452,243 +263,8 @@ describe('NewOrgConfigProvider', () => {
|
|
|
452
263
|
await waitFor(() => {
|
|
453
264
|
expect(contextValue1).toBeDefined();
|
|
454
265
|
expect(contextValue2).toBeDefined();
|
|
455
|
-
// Both components should receive the same context instance
|
|
456
266
|
expect(contextValue1).toBe(contextValue2);
|
|
457
267
|
});
|
|
458
268
|
});
|
|
459
269
|
});
|
|
460
|
-
describe('Override Config', () => {
|
|
461
|
-
it('should use overrideConfig when provided instead of fetched config', async () => {
|
|
462
|
-
const fetchedData = {
|
|
463
|
-
colorsConfig: { accentPrimary: '#FF0000' },
|
|
464
|
-
frontendConfig: { merchantOverrideCss: 'fetched-css' },
|
|
465
|
-
};
|
|
466
|
-
|
|
467
|
-
const overrideData = {
|
|
468
|
-
colorsConfig: { accentPrimary: '#0000FF' },
|
|
469
|
-
frontendConfig: { merchantOverrideCss: 'override-css' },
|
|
470
|
-
orgPageConfig: { pageVariants: [] },
|
|
471
|
-
};
|
|
472
|
-
|
|
473
|
-
// Updated TestWrapper to accept overrideConfig
|
|
474
|
-
const TestWrapperWithOverride: React.FC<{
|
|
475
|
-
children: React.ReactNode;
|
|
476
|
-
orgShortName?: string;
|
|
477
|
-
mockHookData?: any;
|
|
478
|
-
overrideConfig?: any;
|
|
479
|
-
}> = ({ children, orgShortName, mockHookData = {}, overrideConfig }) => {
|
|
480
|
-
const mockUseUIConfig = useUIConfig as any;
|
|
481
|
-
mockUseUIConfig.mockReturnValue({
|
|
482
|
-
data: mockHookData.data || {},
|
|
483
|
-
loading: mockHookData.loading ?? false,
|
|
484
|
-
error: mockHookData.error || null,
|
|
485
|
-
refetch: vi.fn(),
|
|
486
|
-
});
|
|
487
|
-
|
|
488
|
-
return (
|
|
489
|
-
<Provider>
|
|
490
|
-
<EnviveConfigProvider
|
|
491
|
-
identifyingPrefix="test"
|
|
492
|
-
orgShortName={orgShortName}
|
|
493
|
-
baseUrl="https://test-api.example.com"
|
|
494
|
-
orgLevelApiKey="test-key"
|
|
495
|
-
>
|
|
496
|
-
<LocalStorageProvider>
|
|
497
|
-
<GraphQLProvider>
|
|
498
|
-
<NewOrgConfigProvider overrideConfig={overrideConfig}>
|
|
499
|
-
{children}
|
|
500
|
-
</NewOrgConfigProvider>
|
|
501
|
-
</GraphQLProvider>
|
|
502
|
-
</LocalStorageProvider>
|
|
503
|
-
</EnviveConfigProvider>
|
|
504
|
-
</Provider>
|
|
505
|
-
);
|
|
506
|
-
};
|
|
507
|
-
|
|
508
|
-
const ConfigChecker: React.FC = () => {
|
|
509
|
-
const config = useNewOrgConfigContext();
|
|
510
|
-
return (
|
|
511
|
-
<div data-testid="config-checker">
|
|
512
|
-
<div data-testid="accent-color">{config.colorsConfig?.accentPrimary || 'none'}</div>
|
|
513
|
-
<div data-testid="css-value">
|
|
514
|
-
{config.frontendConfig?.merchantOverrideCss || 'none'}
|
|
515
|
-
</div>
|
|
516
|
-
</div>
|
|
517
|
-
);
|
|
518
|
-
};
|
|
519
|
-
|
|
520
|
-
render(
|
|
521
|
-
<TestWrapperWithOverride
|
|
522
|
-
orgShortName="test-org"
|
|
523
|
-
mockHookData={{ data: fetchedData, loading: false }}
|
|
524
|
-
overrideConfig={overrideData}
|
|
525
|
-
>
|
|
526
|
-
<ConfigChecker />
|
|
527
|
-
</TestWrapperWithOverride>,
|
|
528
|
-
);
|
|
529
|
-
|
|
530
|
-
await waitFor(() => {
|
|
531
|
-
expect(screen.getByTestId('accent-color')).toHaveTextContent('#0000FF');
|
|
532
|
-
});
|
|
533
|
-
|
|
534
|
-
// Should use override config, not fetched config
|
|
535
|
-
expect(screen.getByTestId('css-value')).toHaveTextContent('override-css');
|
|
536
|
-
});
|
|
537
|
-
|
|
538
|
-
it('should fall back to fetched config when overrideConfig is not provided', async () => {
|
|
539
|
-
const fetchedData = {
|
|
540
|
-
colorsConfig: { accentPrimary: '#FF0000' },
|
|
541
|
-
frontendConfig: { merchantOverrideCss: 'fetched-css' },
|
|
542
|
-
};
|
|
543
|
-
|
|
544
|
-
const ConfigChecker: React.FC = () => {
|
|
545
|
-
const config = useNewOrgConfigContext();
|
|
546
|
-
return (
|
|
547
|
-
<div data-testid="config-checker">
|
|
548
|
-
<div data-testid="accent-color">{config.colorsConfig?.accentPrimary || 'none'}</div>
|
|
549
|
-
<div data-testid="css-value">
|
|
550
|
-
{config.frontendConfig?.merchantOverrideCss || 'none'}
|
|
551
|
-
</div>
|
|
552
|
-
</div>
|
|
553
|
-
);
|
|
554
|
-
};
|
|
555
|
-
|
|
556
|
-
render(
|
|
557
|
-
<TestWrapper
|
|
558
|
-
orgShortName="test-org"
|
|
559
|
-
mockHookData={{ data: fetchedData, loading: false }}
|
|
560
|
-
>
|
|
561
|
-
<ConfigChecker />
|
|
562
|
-
</TestWrapper>,
|
|
563
|
-
);
|
|
564
|
-
|
|
565
|
-
await waitFor(() => {
|
|
566
|
-
expect(screen.getByTestId('accent-color')).toHaveTextContent('#FF0000');
|
|
567
|
-
});
|
|
568
|
-
|
|
569
|
-
expect(screen.getByTestId('css-value')).toHaveTextContent('fetched-css');
|
|
570
|
-
});
|
|
571
|
-
|
|
572
|
-
it('should set newOrgConfigAtom with overrideConfig when provided', async () => {
|
|
573
|
-
const fetchedData = {
|
|
574
|
-
colorsConfig: { accentPrimary: '#FF0000' },
|
|
575
|
-
};
|
|
576
|
-
|
|
577
|
-
const overrideData = {
|
|
578
|
-
colorsConfig: { accentPrimary: '#00FF00' },
|
|
579
|
-
frontendConfig: { merchantOverrideCss: 'override-css' },
|
|
580
|
-
};
|
|
581
|
-
|
|
582
|
-
const TestWrapperWithOverride: React.FC<{
|
|
583
|
-
children: React.ReactNode;
|
|
584
|
-
orgShortName?: string;
|
|
585
|
-
mockHookData?: any;
|
|
586
|
-
overrideConfig?: any;
|
|
587
|
-
}> = ({ children, orgShortName, mockHookData = {}, overrideConfig }) => {
|
|
588
|
-
const mockUseUIConfig = useUIConfig as any;
|
|
589
|
-
mockUseUIConfig.mockReturnValue({
|
|
590
|
-
data: mockHookData.data || {},
|
|
591
|
-
loading: mockHookData.loading ?? false,
|
|
592
|
-
error: mockHookData.error || null,
|
|
593
|
-
refetch: vi.fn(),
|
|
594
|
-
});
|
|
595
|
-
|
|
596
|
-
return (
|
|
597
|
-
<Provider>
|
|
598
|
-
<EnviveConfigProvider
|
|
599
|
-
identifyingPrefix="test"
|
|
600
|
-
orgShortName={orgShortName}
|
|
601
|
-
baseUrl="https://test-api.example.com"
|
|
602
|
-
orgLevelApiKey="test-key"
|
|
603
|
-
>
|
|
604
|
-
<LocalStorageProvider>
|
|
605
|
-
<GraphQLProvider>
|
|
606
|
-
<NewOrgConfigProvider overrideConfig={overrideConfig}>
|
|
607
|
-
{children}
|
|
608
|
-
</NewOrgConfigProvider>
|
|
609
|
-
</GraphQLProvider>
|
|
610
|
-
</LocalStorageProvider>
|
|
611
|
-
</EnviveConfigProvider>
|
|
612
|
-
</Provider>
|
|
613
|
-
);
|
|
614
|
-
};
|
|
615
|
-
|
|
616
|
-
render(
|
|
617
|
-
<TestWrapperWithOverride
|
|
618
|
-
orgShortName="test-org"
|
|
619
|
-
mockHookData={{ data: fetchedData, loading: false }}
|
|
620
|
-
overrideConfig={overrideData}
|
|
621
|
-
>
|
|
622
|
-
<AtomReaderComponent />
|
|
623
|
-
</TestWrapperWithOverride>,
|
|
624
|
-
);
|
|
625
|
-
|
|
626
|
-
await waitFor(() => {
|
|
627
|
-
expect(screen.getByTestId('atom-has-config')).toHaveTextContent('has-config');
|
|
628
|
-
});
|
|
629
|
-
|
|
630
|
-
// Atom should have the override config values
|
|
631
|
-
expect(screen.getByTestId('atom-has-colors')).toHaveTextContent('true');
|
|
632
|
-
expect(screen.getByTestId('atom-has-frontend')).toHaveTextContent('true');
|
|
633
|
-
});
|
|
634
|
-
|
|
635
|
-
it('should handle undefined overrideConfig gracefully', async () => {
|
|
636
|
-
const fetchedData = {
|
|
637
|
-
colorsConfig: { accentPrimary: '#FF0000' },
|
|
638
|
-
frontendConfig: { merchantOverrideCss: 'fetched-css' },
|
|
639
|
-
};
|
|
640
|
-
|
|
641
|
-
const TestWrapperWithOverride: React.FC<{
|
|
642
|
-
children: React.ReactNode;
|
|
643
|
-
orgShortName?: string;
|
|
644
|
-
mockHookData?: any;
|
|
645
|
-
overrideConfig?: any;
|
|
646
|
-
}> = ({ children, orgShortName, mockHookData = {}, overrideConfig }) => {
|
|
647
|
-
const mockUseUIConfig = useUIConfig as any;
|
|
648
|
-
mockUseUIConfig.mockReturnValue({
|
|
649
|
-
data: mockHookData.data || {},
|
|
650
|
-
loading: mockHookData.loading ?? false,
|
|
651
|
-
error: mockHookData.error || null,
|
|
652
|
-
refetch: vi.fn(),
|
|
653
|
-
});
|
|
654
|
-
|
|
655
|
-
return (
|
|
656
|
-
<Provider>
|
|
657
|
-
<EnviveConfigProvider
|
|
658
|
-
identifyingPrefix="test"
|
|
659
|
-
orgShortName={orgShortName}
|
|
660
|
-
baseUrl="https://test-api.example.com"
|
|
661
|
-
orgLevelApiKey="test-key"
|
|
662
|
-
>
|
|
663
|
-
<LocalStorageProvider>
|
|
664
|
-
<GraphQLProvider>
|
|
665
|
-
<NewOrgConfigProvider overrideConfig={overrideConfig}>
|
|
666
|
-
{children}
|
|
667
|
-
</NewOrgConfigProvider>
|
|
668
|
-
</GraphQLProvider>
|
|
669
|
-
</LocalStorageProvider>
|
|
670
|
-
</EnviveConfigProvider>
|
|
671
|
-
</Provider>
|
|
672
|
-
);
|
|
673
|
-
};
|
|
674
|
-
|
|
675
|
-
render(
|
|
676
|
-
<TestWrapperWithOverride
|
|
677
|
-
orgShortName="test-org"
|
|
678
|
-
mockHookData={{ data: fetchedData, loading: false }}
|
|
679
|
-
overrideConfig={undefined}
|
|
680
|
-
>
|
|
681
|
-
<MockNewOrgConfigComponent />
|
|
682
|
-
</TestWrapperWithOverride>,
|
|
683
|
-
);
|
|
684
|
-
|
|
685
|
-
await waitFor(() => {
|
|
686
|
-
expect(screen.getByTestId('loading')).toHaveTextContent('false');
|
|
687
|
-
});
|
|
688
|
-
|
|
689
|
-
// Should fall back to fetched data
|
|
690
|
-
expect(screen.getByTestId('has-colors-config')).toHaveTextContent('true');
|
|
691
|
-
expect(screen.getByTestId('has-frontend-config')).toHaveTextContent('true');
|
|
692
|
-
});
|
|
693
|
-
});
|
|
694
270
|
});
|