@hubspot/ui-extensions 0.11.1 → 0.11.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.
- package/dist/__synced__/experimental/types.synced.d.ts +3 -4
- package/dist/__synced__/remoteComponents.synced.d.ts +152 -70
- package/dist/__synced__/remoteComponents.synced.js +98 -0
- package/dist/__synced__/types/components/button.synced.d.ts +6 -0
- package/dist/__tests__/crm/hooks/useAssociations.spec.js +33 -29
- package/dist/__tests__/crm/hooks/useCrmProperties.spec.js +19 -18
- package/dist/__tests__/crm/utils/fetchAssociations.spec.js +8 -7
- package/dist/__tests__/crm/utils/fetchCrmProperties.spec.js +34 -33
- package/dist/crm/index.d.ts +1 -1
- package/dist/crm/index.js +1 -1
- package/dist/experimental/index.d.ts +1 -1
- package/dist/experimental/index.js +1 -1
- package/dist/experimental/testing/__tests__/debug.spec.d.ts +1 -0
- package/dist/experimental/testing/__tests__/debug.spec.js +43 -0
- package/dist/experimental/testing/__tests__/find.spec.d.ts +1 -0
- package/dist/experimental/testing/__tests__/find.spec.js +33 -0
- package/dist/experimental/testing/__tests__/findAll.spec.d.ts +1 -0
- package/dist/experimental/testing/__tests__/findAll.spec.js +12 -0
- package/dist/experimental/testing/__tests__/findAllChildren.spec.d.ts +1 -0
- package/dist/experimental/testing/__tests__/findAllChildren.spec.js +48 -0
- package/dist/experimental/testing/__tests__/findChild.spec.d.ts +1 -0
- package/dist/experimental/testing/__tests__/findChild.spec.js +29 -0
- package/dist/experimental/testing/__tests__/fragments.spec.d.ts +1 -0
- package/dist/experimental/testing/__tests__/fragments.spec.js +59 -0
- package/dist/experimental/testing/__tests__/invalid-components.spec.d.ts +1 -0
- package/dist/experimental/testing/__tests__/invalid-components.spec.js +88 -0
- package/dist/experimental/testing/__tests__/isMatch.spec.d.ts +1 -0
- package/dist/experimental/testing/__tests__/isMatch.spec.js +60 -0
- package/dist/experimental/testing/__tests__/maybeFind.spec.d.ts +1 -0
- package/dist/experimental/testing/__tests__/maybeFind.spec.js +58 -0
- package/dist/experimental/testing/__tests__/maybeFindChild.spec.d.ts +1 -0
- package/dist/experimental/testing/__tests__/maybeFindChild.spec.js +65 -0
- package/dist/experimental/testing/__tests__/trigger.spec.d.ts +1 -0
- package/dist/experimental/testing/__tests__/trigger.spec.js +40 -0
- package/dist/experimental/testing/__tests__/type-utils.spec.d.ts +1 -0
- package/dist/experimental/testing/__tests__/type-utils.spec.js +163 -0
- package/dist/experimental/testing/__tests__/waitFor.spec.d.ts +1 -0
- package/dist/experimental/testing/__tests__/waitFor.spec.js +55 -0
- package/dist/experimental/testing/index.d.ts +3 -0
- package/dist/experimental/testing/index.js +3 -0
- package/dist/experimental/testing/internal/convert.d.ts +10 -0
- package/dist/experimental/testing/internal/convert.js +131 -0
- package/dist/experimental/testing/internal/debug.d.ts +1 -1
- package/dist/experimental/testing/internal/debug.js +10 -1
- package/dist/experimental/testing/internal/document.d.ts +14 -0
- package/dist/experimental/testing/internal/document.js +37 -0
- package/dist/experimental/testing/internal/errors.d.ts +12 -0
- package/dist/experimental/testing/internal/errors.js +18 -0
- package/dist/experimental/testing/internal/match.d.ts +19 -0
- package/dist/experimental/testing/internal/match.js +42 -0
- package/dist/experimental/testing/internal/query.js +1 -19
- package/dist/experimental/testing/internal/utils/promise-utils.d.ts +14 -0
- package/dist/experimental/testing/internal/utils/promise-utils.js +14 -0
- package/dist/experimental/testing/render.d.ts +9 -0
- package/dist/experimental/testing/render.js +155 -0
- package/dist/experimental/testing/types.d.ts +1 -0
- package/dist/pages/home/index.d.ts +1 -1
- package/dist/pages/home/index.js +1 -1
- package/package.json +11 -13
- package/dist/__synced__/appHomeRemoteComponents.synced.d.ts +0 -28
- package/dist/__synced__/appHomeRemoteComponents.synced.js +0 -21
- package/dist/__synced__/crmRemoteComponents.synced.d.ts +0 -66
- package/dist/__synced__/crmRemoteComponents.synced.js +0 -15
- package/dist/__synced__/experimentalRemoteComponents.synced.d.ts +0 -94
- package/dist/__synced__/experimentalRemoteComponents.synced.js +0 -56
|
@@ -6,6 +6,9 @@ import { createRemoteComponentRegistry } from './utils/remote-component-registry
|
|
|
6
6
|
*/
|
|
7
7
|
export const __hubSpotComponentRegistry = createRemoteComponentRegistry();
|
|
8
8
|
const { createAndRegisterRemoteReactComponent, createAndRegisterRemoteCompoundReactComponent, } = __hubSpotComponentRegistry;
|
|
9
|
+
////////////////////////////////////////////////////////////
|
|
10
|
+
// STANDARD COMPONENTS
|
|
11
|
+
////////////////////////////////////////////////////////////
|
|
9
12
|
/**
|
|
10
13
|
* The `Alert` component renders an alert within a card. Use this component to give usage guidance, notify users of action results, or warn them about potential issues or failures.
|
|
11
14
|
*
|
|
@@ -586,3 +589,98 @@ export const CurrencyInput = createAndRegisterRemoteReactComponent('CurrencyInpu
|
|
|
586
589
|
* - {@link https://developers.hubspot.com/docs/reference/ui-components/standard-components/simple-grid Docs}
|
|
587
590
|
*/
|
|
588
591
|
export const AutoGrid = createAndRegisterRemoteReactComponent('AutoGrid');
|
|
592
|
+
////////////////////////////////////////////////////////
|
|
593
|
+
// CRM COMPONENTS
|
|
594
|
+
////////////////////////////////////////////////////////
|
|
595
|
+
export const CrmPropertyList = createAndRegisterRemoteReactComponent('CrmPropertyList');
|
|
596
|
+
export const CrmAssociationTable = createAndRegisterRemoteReactComponent('CrmAssociationTable');
|
|
597
|
+
export const CrmDataHighlight = createAndRegisterRemoteReactComponent('CrmDataHighlight');
|
|
598
|
+
export const CrmReport = createAndRegisterRemoteReactComponent('CrmReport');
|
|
599
|
+
export const CrmAssociationPivot = createAndRegisterRemoteReactComponent('CrmAssociationPivot');
|
|
600
|
+
export const CrmAssociationPropertyList = createAndRegisterRemoteReactComponent('CrmAssociationPropertyList');
|
|
601
|
+
export const CrmAssociationStageTracker = createAndRegisterRemoteReactComponent('CrmAssociationStageTracker');
|
|
602
|
+
export const CrmSimpleDeadline = createAndRegisterRemoteReactComponent('CrmSimpleDeadline');
|
|
603
|
+
export const CrmStageTracker = createAndRegisterRemoteReactComponent('CrmStageTracker');
|
|
604
|
+
export const CrmStatistics = createAndRegisterRemoteReactComponent('CrmStatistics');
|
|
605
|
+
export const CrmActionButton = createAndRegisterRemoteReactComponent('CrmActionButton');
|
|
606
|
+
export const CrmActionLink = createAndRegisterRemoteReactComponent('CrmActionLink');
|
|
607
|
+
export const CrmCardActions = createAndRegisterRemoteReactComponent('CrmCardActions');
|
|
608
|
+
////////////////////////////////////////////////////////
|
|
609
|
+
// APP HOME COMPONENTS
|
|
610
|
+
////////////////////////////////////////////////////////
|
|
611
|
+
/**
|
|
612
|
+
* The `HeaderActions` component renders a container for action buttons in the app home header. It accepts `PrimaryHeaderActionButton` and `SecondaryHeaderActionButton` as children.
|
|
613
|
+
*
|
|
614
|
+
*/
|
|
615
|
+
export const HeaderActions = createAndRegisterRemoteReactComponent('HeaderActions');
|
|
616
|
+
/**
|
|
617
|
+
* The `PrimaryHeaderActionButton` component renders a primary action button in the app home header. This button is styled as the main call-to-action and only one should be used per `HeaderActions` container.
|
|
618
|
+
*
|
|
619
|
+
*/
|
|
620
|
+
export const PrimaryHeaderActionButton = createAndRegisterRemoteReactComponent('PrimaryHeaderActionButton', {
|
|
621
|
+
fragmentProps: ['overlay'],
|
|
622
|
+
});
|
|
623
|
+
/**
|
|
624
|
+
* The `SecondaryHeaderActionButton` component renders a secondary action button in the app home header. Multiple secondary actions can be used and they will be grouped appropriately in the header.
|
|
625
|
+
*
|
|
626
|
+
*/
|
|
627
|
+
export const SecondaryHeaderActionButton = createAndRegisterRemoteReactComponent('SecondaryHeaderActionButton', {
|
|
628
|
+
fragmentProps: ['overlay'],
|
|
629
|
+
});
|
|
630
|
+
////////////////////////////////////////////////////////
|
|
631
|
+
// EXPERIMENTAL COMPONENTS
|
|
632
|
+
////////////////////////////////////////////////////////
|
|
633
|
+
/**
|
|
634
|
+
* @experimental This component is experimental. Avoid using it in production due to potential breaking changes. Your feedback is valuable for improvements. Stay tuned for updates.
|
|
635
|
+
*/
|
|
636
|
+
export const Iframe = createAndRegisterRemoteReactComponent('Iframe');
|
|
637
|
+
/**
|
|
638
|
+
* @experimental This component is experimental. Avoid using it in production due to potential breaking changes. Your feedback is valuable for improvements. Stay tuned for updates.
|
|
639
|
+
*/
|
|
640
|
+
export const MediaObject = createAndRegisterRemoteReactComponent('MediaObject', {
|
|
641
|
+
fragmentProps: ['itemRight', 'itemLeft'],
|
|
642
|
+
});
|
|
643
|
+
/**
|
|
644
|
+
* @experimental This component is experimental. Avoid using it in production due to potential breaking changes. Your feedback is valuable for improvements. Stay tuned for updates.
|
|
645
|
+
*/
|
|
646
|
+
export const Stack2 = createAndRegisterRemoteReactComponent('Stack2');
|
|
647
|
+
/**
|
|
648
|
+
* @experimental This component is experimental. Avoid using it in production due to potential breaking changes. Your feedback is valuable for improvements. Stay tuned for updates.
|
|
649
|
+
*/
|
|
650
|
+
export const Center = createAndRegisterRemoteReactComponent('Center');
|
|
651
|
+
/**
|
|
652
|
+
* @experimental This component is experimental. Avoid using it in production due to potential breaking changes. Your feedback is valuable for improvements. Stay tuned for updates.
|
|
653
|
+
*/
|
|
654
|
+
export const Grid = createAndRegisterRemoteReactComponent('Grid');
|
|
655
|
+
/**
|
|
656
|
+
* @experimental This component is experimental. Avoid using it in production due to potential breaking changes. Your feedback is valuable for improvements. Stay tuned for updates.
|
|
657
|
+
*/
|
|
658
|
+
export const GridItem = createAndRegisterRemoteReactComponent('GridItem');
|
|
659
|
+
/**
|
|
660
|
+
* @experimental This component is experimental. Avoid using it in production due to potential breaking changes. Your feedback is valuable for improvements. Stay tuned for updates.
|
|
661
|
+
*/
|
|
662
|
+
export const SettingsView = createAndRegisterRemoteReactComponent('SettingsView');
|
|
663
|
+
/**
|
|
664
|
+
* The `ExpandableText` component renders a text that can be expanded or collapsed based on a maximum height.
|
|
665
|
+
*
|
|
666
|
+
* @experimental This component is experimental. Avoid using it in production due to potential breaking changes. Your feedback is valuable for improvements. Stay tuned for updates.
|
|
667
|
+
*
|
|
668
|
+
* **Links:**
|
|
669
|
+
*
|
|
670
|
+
* - {@link https://developers.hubspot.com/docs/reference/ui-components/standard-components/expandable-text ExpandableText Docs}
|
|
671
|
+
*/
|
|
672
|
+
export const ExpandableText = createAndRegisterRemoteReactComponent('ExpandableText');
|
|
673
|
+
/**
|
|
674
|
+
* The `Popover` component renders a popover overlay that can contain other components.
|
|
675
|
+
*
|
|
676
|
+
* @experimental This component is experimental. Avoid using it in production due to potential breaking changes. Your feedback is valuable for improvements. Stay tuned for updates.
|
|
677
|
+
*
|
|
678
|
+
* **Links:**
|
|
679
|
+
*
|
|
680
|
+
* - {@link https://developers.hubspot.com/docs/reference/ui-components/standard-components/popover Popover Docs}
|
|
681
|
+
*/
|
|
682
|
+
export const Popover = createAndRegisterRemoteReactComponent('Popover');
|
|
683
|
+
/**
|
|
684
|
+
* @experimental This component is experimental. Avoid using it in production due to potential breaking changes. Your feedback is valuable for improvements. Stay tuned for updates.
|
|
685
|
+
*/
|
|
686
|
+
export const FileInput = createAndRegisterRemoteReactComponent('FileInput');
|
|
@@ -38,6 +38,12 @@ export interface BaseButtonProps {
|
|
|
38
38
|
* @defaultValue `"md"`
|
|
39
39
|
*/
|
|
40
40
|
size?: TShirtSizes['xs'] | TShirtSizes['sm'] | TShirtSizes['md'];
|
|
41
|
+
/**
|
|
42
|
+
* When set to `true`, long button text will be truncated with an ellipsis (`...`) and the full text will appear in a tooltip on hover.
|
|
43
|
+
*
|
|
44
|
+
* @defaultValue `false`
|
|
45
|
+
*/
|
|
46
|
+
truncate?: boolean;
|
|
41
47
|
}
|
|
42
48
|
/**
|
|
43
49
|
* The props type for {@link !components.Button}.
|
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import { renderHook, waitFor } from '@testing-library/react';
|
|
2
|
+
import { vi } from 'vitest';
|
|
2
3
|
import { useAssociations } from '../../../crm/hooks/useAssociations';
|
|
3
4
|
import { fetchAssociations } from '../../../crm/utils/fetchAssociations';
|
|
4
5
|
// Mock the logger module
|
|
5
|
-
|
|
6
|
+
vi.mock('../../../logger', () => ({
|
|
6
7
|
logger: {
|
|
7
|
-
debug:
|
|
8
|
-
info:
|
|
9
|
-
warn:
|
|
10
|
-
error:
|
|
8
|
+
debug: vi.fn(),
|
|
9
|
+
info: vi.fn(),
|
|
10
|
+
warn: vi.fn(),
|
|
11
|
+
error: vi.fn(),
|
|
11
12
|
},
|
|
12
13
|
}));
|
|
13
14
|
// Mock the fetchAssociations function, keep utility functions
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
vi.mock('../../../crm/utils/fetchAssociations', async (importOriginal) => {
|
|
16
|
+
const actual = (await importOriginal());
|
|
17
|
+
return {
|
|
18
|
+
...actual,
|
|
19
|
+
fetchAssociations: vi.fn(),
|
|
20
|
+
};
|
|
21
|
+
});
|
|
18
22
|
// Get reference to the mocked function
|
|
19
23
|
const mockFetchAssociations = fetchAssociations;
|
|
20
24
|
describe('useAssociations with Pagination', () => {
|
|
@@ -45,7 +49,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
45
49
|
hasMore: false,
|
|
46
50
|
nextOffset: 0,
|
|
47
51
|
},
|
|
48
|
-
cleanup:
|
|
52
|
+
cleanup: vi.fn(),
|
|
49
53
|
});
|
|
50
54
|
const { result } = renderHook(() => useAssociations({
|
|
51
55
|
toObjectType: '0-1',
|
|
@@ -69,7 +73,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
69
73
|
hasMore: false,
|
|
70
74
|
nextOffset: 0,
|
|
71
75
|
},
|
|
72
|
-
cleanup:
|
|
76
|
+
cleanup: vi.fn(),
|
|
73
77
|
});
|
|
74
78
|
const { result } = renderHook(() => useAssociations({
|
|
75
79
|
toObjectType: '0-1',
|
|
@@ -99,7 +103,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
99
103
|
hasMore: true,
|
|
100
104
|
nextOffset: 10,
|
|
101
105
|
},
|
|
102
|
-
cleanup:
|
|
106
|
+
cleanup: vi.fn(),
|
|
103
107
|
});
|
|
104
108
|
const { result } = renderHook(() => useAssociations({
|
|
105
109
|
toObjectType: '0-1',
|
|
@@ -128,7 +132,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
128
132
|
hasMore: false,
|
|
129
133
|
nextOffset: 0,
|
|
130
134
|
},
|
|
131
|
-
cleanup:
|
|
135
|
+
cleanup: vi.fn(),
|
|
132
136
|
});
|
|
133
137
|
const { result } = renderHook(() => useAssociations({
|
|
134
138
|
toObjectType: '0-1',
|
|
@@ -153,7 +157,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
153
157
|
hasMore: true,
|
|
154
158
|
nextOffset: 10,
|
|
155
159
|
},
|
|
156
|
-
cleanup:
|
|
160
|
+
cleanup: vi.fn(),
|
|
157
161
|
});
|
|
158
162
|
// Second page response
|
|
159
163
|
mockFetchAssociations.mockResolvedValueOnce({
|
|
@@ -162,7 +166,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
162
166
|
hasMore: false,
|
|
163
167
|
nextOffset: 20,
|
|
164
168
|
},
|
|
165
|
-
cleanup:
|
|
169
|
+
cleanup: vi.fn(),
|
|
166
170
|
});
|
|
167
171
|
const { result } = renderHook(() => useAssociations({
|
|
168
172
|
toObjectType: '0-1',
|
|
@@ -193,7 +197,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
193
197
|
hasMore: true,
|
|
194
198
|
nextOffset: 10,
|
|
195
199
|
},
|
|
196
|
-
cleanup:
|
|
200
|
+
cleanup: vi.fn(),
|
|
197
201
|
});
|
|
198
202
|
// Second call: page 2 with hasMore: false
|
|
199
203
|
mockFetchAssociations.mockResolvedValueOnce({
|
|
@@ -202,7 +206,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
202
206
|
hasMore: false,
|
|
203
207
|
nextOffset: 20,
|
|
204
208
|
},
|
|
205
|
-
cleanup:
|
|
209
|
+
cleanup: vi.fn(),
|
|
206
210
|
});
|
|
207
211
|
// Third call: back to page 1
|
|
208
212
|
mockFetchAssociations.mockResolvedValueOnce({
|
|
@@ -211,7 +215,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
211
215
|
hasMore: true,
|
|
212
216
|
nextOffset: 10,
|
|
213
217
|
},
|
|
214
|
-
cleanup:
|
|
218
|
+
cleanup: vi.fn(),
|
|
215
219
|
});
|
|
216
220
|
const { result } = renderHook(() => useAssociations({
|
|
217
221
|
toObjectType: '0-1',
|
|
@@ -243,7 +247,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
243
247
|
hasMore: true,
|
|
244
248
|
nextOffset: 10,
|
|
245
249
|
},
|
|
246
|
-
cleanup:
|
|
250
|
+
cleanup: vi.fn(),
|
|
247
251
|
});
|
|
248
252
|
const { result } = renderHook(() => useAssociations({
|
|
249
253
|
toObjectType: '0-1',
|
|
@@ -277,7 +281,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
277
281
|
hasMore: false,
|
|
278
282
|
nextOffset: 10,
|
|
279
283
|
},
|
|
280
|
-
cleanup:
|
|
284
|
+
cleanup: vi.fn(),
|
|
281
285
|
});
|
|
282
286
|
const { result } = renderHook(() => useAssociations({
|
|
283
287
|
toObjectType: '0-1',
|
|
@@ -320,7 +324,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
320
324
|
hasMore: false,
|
|
321
325
|
nextOffset: 0,
|
|
322
326
|
},
|
|
323
|
-
cleanup:
|
|
327
|
+
cleanup: vi.fn(),
|
|
324
328
|
});
|
|
325
329
|
// @ts-expect-error - intentional type issue to check the failure state
|
|
326
330
|
const { result } = renderHook(() => useAssociations(null));
|
|
@@ -343,7 +347,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
343
347
|
hasMore: false,
|
|
344
348
|
nextOffset: 0,
|
|
345
349
|
},
|
|
346
|
-
cleanup:
|
|
350
|
+
cleanup: vi.fn(),
|
|
347
351
|
});
|
|
348
352
|
// @ts-expect-error - intentional type issue to check the failure state
|
|
349
353
|
const { result } = renderHook(() => useAssociations(undefined));
|
|
@@ -366,7 +370,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
366
370
|
hasMore: false,
|
|
367
371
|
nextOffset: 0,
|
|
368
372
|
},
|
|
369
|
-
cleanup:
|
|
373
|
+
cleanup: vi.fn(),
|
|
370
374
|
});
|
|
371
375
|
// @ts-expect-error - intentional type issue to check the failure state
|
|
372
376
|
const { result } = renderHook(() => useAssociations({}));
|
|
@@ -389,7 +393,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
389
393
|
hasMore: false,
|
|
390
394
|
nextOffset: 0,
|
|
391
395
|
},
|
|
392
|
-
cleanup:
|
|
396
|
+
cleanup: vi.fn(),
|
|
393
397
|
});
|
|
394
398
|
const { result } = renderHook(() =>
|
|
395
399
|
// @ts-expect-error - intentional type issue to check the failure state
|
|
@@ -415,7 +419,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
415
419
|
hasMore: false,
|
|
416
420
|
nextOffset: 0,
|
|
417
421
|
},
|
|
418
|
-
cleanup:
|
|
422
|
+
cleanup: vi.fn(),
|
|
419
423
|
});
|
|
420
424
|
const { result } = renderHook(() => useAssociations({
|
|
421
425
|
toObjectType: '0-1',
|
|
@@ -441,7 +445,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
441
445
|
hasMore: false,
|
|
442
446
|
nextOffset: 0,
|
|
443
447
|
},
|
|
444
|
-
cleanup:
|
|
448
|
+
cleanup: vi.fn(),
|
|
445
449
|
});
|
|
446
450
|
const config = {
|
|
447
451
|
toObjectType: '0-1',
|
|
@@ -469,7 +473,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
469
473
|
hasMore: false,
|
|
470
474
|
nextOffset: 0,
|
|
471
475
|
},
|
|
472
|
-
cleanup:
|
|
476
|
+
cleanup: vi.fn(),
|
|
473
477
|
});
|
|
474
478
|
const config = {
|
|
475
479
|
toObjectType: '0-1',
|
|
@@ -484,7 +488,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
484
488
|
});
|
|
485
489
|
describe('lifecycle management', () => {
|
|
486
490
|
it('should call cleanup function on unmount', async () => {
|
|
487
|
-
const mockCleanup =
|
|
491
|
+
const mockCleanup = vi.fn();
|
|
488
492
|
mockFetchAssociations.mockResolvedValue({
|
|
489
493
|
data: {
|
|
490
494
|
results: [],
|
|
@@ -514,7 +518,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
514
518
|
hasMore: false,
|
|
515
519
|
nextOffset: 0,
|
|
516
520
|
},
|
|
517
|
-
cleanup:
|
|
521
|
+
cleanup: vi.fn(),
|
|
518
522
|
});
|
|
519
523
|
const config = {
|
|
520
524
|
toObjectType: '0-1',
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { renderHook, waitFor } from '@testing-library/react';
|
|
2
|
+
import { vi } from 'vitest';
|
|
2
3
|
import { useCrmProperties } from '../../../crm/hooks/useCrmProperties';
|
|
4
|
+
import * as fetchCrmPropertiesModule from '../../../crm/utils/fetchCrmProperties';
|
|
3
5
|
// Mock the logger module
|
|
4
|
-
|
|
6
|
+
vi.mock('../../../logger', () => ({
|
|
5
7
|
logger: {
|
|
6
|
-
debug:
|
|
7
|
-
info:
|
|
8
|
-
warn:
|
|
9
|
-
error:
|
|
8
|
+
debug: vi.fn(),
|
|
9
|
+
info: vi.fn(),
|
|
10
|
+
warn: vi.fn(),
|
|
11
|
+
error: vi.fn(),
|
|
10
12
|
},
|
|
11
13
|
}));
|
|
12
14
|
// Mock the fetchCrmProperties module
|
|
13
|
-
|
|
14
|
-
const mockFetchCrmProperties =
|
|
15
|
-
import * as fetchCrmPropertiesModule from '../../../crm/utils/fetchCrmProperties';
|
|
15
|
+
vi.mock('../../../crm/utils/fetchCrmProperties');
|
|
16
|
+
const mockFetchCrmProperties = vi.fn();
|
|
16
17
|
fetchCrmPropertiesModule.fetchCrmProperties = mockFetchCrmProperties;
|
|
17
18
|
describe('useCrmProperties', () => {
|
|
18
19
|
let originalError;
|
|
@@ -46,7 +47,7 @@ describe('useCrmProperties', () => {
|
|
|
46
47
|
firstname: 'Test value for firstname',
|
|
47
48
|
lastname: 'Test value for lastname',
|
|
48
49
|
},
|
|
49
|
-
cleanup:
|
|
50
|
+
cleanup: vi.fn(),
|
|
50
51
|
});
|
|
51
52
|
const propertyNames = ['firstname', 'lastname'];
|
|
52
53
|
const { result } = renderHook(() => useCrmProperties(propertyNames));
|
|
@@ -78,7 +79,7 @@ describe('useCrmProperties', () => {
|
|
|
78
79
|
capturedCallback = propertiesUpdatedCallback;
|
|
79
80
|
return {
|
|
80
81
|
data: { firstname: 'Initial', lastname: 'Initial' },
|
|
81
|
-
cleanup:
|
|
82
|
+
cleanup: vi.fn(),
|
|
82
83
|
};
|
|
83
84
|
});
|
|
84
85
|
const propertyNames = ['firstname', 'lastname'];
|
|
@@ -105,7 +106,7 @@ describe('useCrmProperties', () => {
|
|
|
105
106
|
capturedCallback = propertiesUpdatedCallback;
|
|
106
107
|
return {
|
|
107
108
|
data: { firstname: 'Initial', lastname: null },
|
|
108
|
-
cleanup:
|
|
109
|
+
cleanup: vi.fn(),
|
|
109
110
|
};
|
|
110
111
|
});
|
|
111
112
|
const propertyNames = ['firstname', 'lastname'];
|
|
@@ -132,7 +133,7 @@ describe('useCrmProperties', () => {
|
|
|
132
133
|
firstname: 'John',
|
|
133
134
|
lastname: 'Doe',
|
|
134
135
|
},
|
|
135
|
-
cleanup:
|
|
136
|
+
cleanup: vi.fn(),
|
|
136
137
|
});
|
|
137
138
|
const propertyNames = ['firstname', 'lastname'];
|
|
138
139
|
const options = {
|
|
@@ -148,7 +149,7 @@ describe('useCrmProperties', () => {
|
|
|
148
149
|
data: {
|
|
149
150
|
firstname: 'John',
|
|
150
151
|
},
|
|
151
|
-
cleanup:
|
|
152
|
+
cleanup: vi.fn(),
|
|
152
153
|
});
|
|
153
154
|
const propertyNames = ['firstname'];
|
|
154
155
|
const defaultOptions = {};
|
|
@@ -162,7 +163,7 @@ describe('useCrmProperties', () => {
|
|
|
162
163
|
data: {
|
|
163
164
|
firstname: 'John',
|
|
164
165
|
},
|
|
165
|
-
cleanup:
|
|
166
|
+
cleanup: vi.fn(),
|
|
166
167
|
});
|
|
167
168
|
const propertyNames = ['firstname'];
|
|
168
169
|
const initialOptions = { propertiesToFormat: ['firstname'] };
|
|
@@ -181,7 +182,7 @@ describe('useCrmProperties', () => {
|
|
|
181
182
|
data: {
|
|
182
183
|
firstname: 'John',
|
|
183
184
|
},
|
|
184
|
-
cleanup:
|
|
185
|
+
cleanup: vi.fn(),
|
|
185
186
|
});
|
|
186
187
|
const propertyNames = ['firstname'];
|
|
187
188
|
const initialOptions = { propertiesToFormat: ['firstname'] };
|
|
@@ -201,7 +202,7 @@ describe('useCrmProperties', () => {
|
|
|
201
202
|
});
|
|
202
203
|
});
|
|
203
204
|
it('should call cleanup function when component unmounts', async () => {
|
|
204
|
-
const mockCleanup =
|
|
205
|
+
const mockCleanup = vi.fn();
|
|
205
206
|
mockFetchCrmProperties.mockResolvedValue({
|
|
206
207
|
data: {
|
|
207
208
|
firstname: 'John',
|
|
@@ -217,8 +218,8 @@ describe('useCrmProperties', () => {
|
|
|
217
218
|
expect(mockCleanup).toHaveBeenCalledTimes(1);
|
|
218
219
|
});
|
|
219
220
|
it('should call cleanup function when dependencies change', async () => {
|
|
220
|
-
const mockCleanup1 =
|
|
221
|
-
const mockCleanup2 =
|
|
221
|
+
const mockCleanup1 = vi.fn();
|
|
222
|
+
const mockCleanup2 = vi.fn();
|
|
222
223
|
mockFetchCrmProperties
|
|
223
224
|
.mockResolvedValueOnce({
|
|
224
225
|
data: { firstname: 'John' },
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { vi } from 'vitest';
|
|
1
2
|
// Set up the mock before importing the module
|
|
2
|
-
const mockFetchAssociations =
|
|
3
|
+
const mockFetchAssociations = vi.fn();
|
|
3
4
|
const mockSelf = {
|
|
4
5
|
fetchAssociations: mockFetchAssociations,
|
|
5
6
|
};
|
|
@@ -13,13 +14,13 @@ describe('fetchAssociations', () => {
|
|
|
13
14
|
// Helper functions
|
|
14
15
|
const createMockResponse = (data, overrides = {}) => ({
|
|
15
16
|
ok: true,
|
|
16
|
-
json:
|
|
17
|
+
json: vi.fn().mockResolvedValue({ data, cleanup: vi.fn() }),
|
|
17
18
|
...overrides,
|
|
18
19
|
});
|
|
19
20
|
const createErrorResponse = (statusText) => ({
|
|
20
21
|
ok: false,
|
|
21
22
|
statusText,
|
|
22
|
-
json:
|
|
23
|
+
json: vi.fn().mockResolvedValue({}),
|
|
23
24
|
});
|
|
24
25
|
const expectError = async (request, expectedMessage) => {
|
|
25
26
|
await expect(fetchAssociations(request)).rejects.toThrow(expectedMessage);
|
|
@@ -30,7 +31,7 @@ describe('fetchAssociations', () => {
|
|
|
30
31
|
...overrides,
|
|
31
32
|
});
|
|
32
33
|
beforeEach(() => {
|
|
33
|
-
|
|
34
|
+
vi.clearAllMocks();
|
|
34
35
|
// Set up dynamic mock that responds to request parameters
|
|
35
36
|
mockFetchAssociations.mockImplementation((request) => {
|
|
36
37
|
const { pageLength = 100, offset = 0, properties = [] } = request;
|
|
@@ -296,12 +297,12 @@ describe('fetchAssociations', () => {
|
|
|
296
297
|
expect(mockFetchAssociations).toHaveBeenCalledWith(request, undefined);
|
|
297
298
|
});
|
|
298
299
|
it('should return cleanup function from API response', async () => {
|
|
299
|
-
const mockCleanup =
|
|
300
|
+
const mockCleanup = vi.fn();
|
|
300
301
|
const emptyData = { results: [], hasMore: false, nextOffset: 0 };
|
|
301
302
|
const mockApiResponse = { data: emptyData, cleanup: mockCleanup };
|
|
302
303
|
mockFetchAssociations.mockResolvedValueOnce({
|
|
303
304
|
ok: true,
|
|
304
|
-
json:
|
|
305
|
+
json: vi.fn().mockResolvedValue(mockApiResponse),
|
|
305
306
|
});
|
|
306
307
|
const result = await fetchAssociations(createBasicRequest());
|
|
307
308
|
expect(result.cleanup).toBe(mockCleanup);
|
|
@@ -313,7 +314,7 @@ describe('fetchAssociations', () => {
|
|
|
313
314
|
const mockApiResponse = { data: emptyData }; // no cleanup function provided
|
|
314
315
|
mockFetchAssociations.mockResolvedValueOnce({
|
|
315
316
|
ok: true,
|
|
316
|
-
json:
|
|
317
|
+
json: vi.fn().mockResolvedValue(mockApiResponse),
|
|
317
318
|
});
|
|
318
319
|
const result = await fetchAssociations(createBasicRequest());
|
|
319
320
|
expect(typeof result.cleanup).toBe('function');
|