@hubspot/ui-extensions 0.11.2 → 0.11.4
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/__tests__/crm/hooks/useAssociations.spec.js +4 -4
- package/dist/__tests__/crm/hooks/useCrmProperties.spec.js +2 -2
- package/dist/__tests__/crm/utils/fetchAssociations.spec.js +5 -5
- package/dist/__tests__/crm/utils/fetchCrmProperties.spec.js +4 -4
- package/dist/clientTypes.d.ts +1 -0
- package/dist/clientTypes.js +1 -1
- package/dist/crm/hooks/useAssociations.d.ts +5 -3
- package/dist/crm/hooks/useAssociations.js +4 -2
- package/dist/crm/hooks/useCrmProperties.d.ts +4 -2
- package/dist/crm/hooks/useCrmProperties.js +4 -2
- package/dist/crm/index.d.ts +4 -4
- package/dist/crm/index.js +3 -3
- package/dist/crm/utils/fetchAssociations.d.ts +1 -1
- package/dist/experimental/index.d.ts +4 -4
- package/dist/experimental/index.js +3 -3
- package/dist/experimental/testing/__tests__/createRenderer.spec.js +23 -0
- package/dist/experimental/testing/__tests__/debug.spec.js +21 -7
- package/dist/experimental/testing/__tests__/find.spec.js +23 -8
- package/dist/experimental/testing/__tests__/findAll.spec.js +4 -3
- package/dist/experimental/testing/__tests__/findAllChildren.spec.js +14 -8
- package/dist/experimental/testing/__tests__/findByTestId.spec.js +126 -0
- package/dist/experimental/testing/__tests__/findChild.spec.js +11 -7
- package/dist/experimental/testing/__tests__/fragments.spec.js +17 -10
- package/dist/experimental/testing/__tests__/invalid-components.spec.js +16 -8
- package/dist/experimental/testing/__tests__/isMatch.spec.js +106 -53
- package/dist/experimental/testing/__tests__/logger.spec.js +10 -0
- package/dist/experimental/testing/__tests__/maybeFind.spec.js +20 -11
- package/dist/experimental/testing/__tests__/maybeFindByTestId.spec.js +65 -0
- package/dist/experimental/testing/__tests__/maybeFindChild.spec.js +22 -12
- package/dist/experimental/testing/__tests__/mocks.actions.spec.js +19 -0
- package/dist/experimental/testing/__tests__/mocks.context.spec.js +24 -0
- package/dist/experimental/testing/__tests__/mocks.runServerlessFunction.spec.js +35 -0
- package/dist/experimental/testing/__tests__/mocks.useAssociations.spec.js +47 -0
- package/dist/experimental/testing/__tests__/mocks.useCrmProperties.spec.js +58 -0
- package/dist/experimental/testing/__tests__/props.spec.js +13 -0
- package/dist/experimental/testing/__tests__/testId.spec.js +18 -0
- package/dist/experimental/testing/__tests__/trigger.spec.js +9 -6
- package/dist/experimental/testing/__tests__/type-utils.spec.js +12 -10
- package/dist/experimental/testing/__tests__/waitFor.spec.js +7 -5
- package/dist/experimental/testing/index.d.ts +4 -3
- package/dist/experimental/testing/index.js +4 -3
- package/dist/experimental/testing/internal/constants.d.ts +2 -2
- package/dist/experimental/testing/internal/constants.js +1 -1
- package/dist/experimental/testing/internal/convert.d.ts +2 -2
- package/dist/experimental/testing/internal/convert.js +42 -24
- package/dist/experimental/testing/internal/debug.d.ts +3 -3
- package/dist/experimental/testing/internal/debug.js +4 -5
- package/dist/experimental/testing/internal/document.d.ts +1 -1
- package/dist/experimental/testing/internal/document.js +4 -1
- package/dist/experimental/testing/internal/element.d.ts +4 -3
- package/dist/experimental/testing/internal/element.js +15 -10
- package/dist/experimental/testing/internal/errors.d.ts +45 -2
- package/dist/experimental/testing/internal/errors.js +44 -2
- package/dist/experimental/testing/internal/fragment.d.ts +3 -2
- package/dist/experimental/testing/internal/fragment.js +13 -9
- package/dist/experimental/testing/internal/match.d.ts +3 -12
- package/dist/experimental/testing/internal/match.js +0 -23
- package/dist/experimental/testing/internal/mocks/index.d.ts +17 -0
- package/dist/experimental/testing/internal/mocks/index.js +46 -0
- package/dist/experimental/testing/internal/mocks/mock-extension-point-api.d.ts +2 -0
- package/dist/experimental/testing/internal/mocks/mock-extension-point-api.js +166 -0
- package/dist/experimental/testing/internal/mocks/mock-hooks.d.ts +2 -0
- package/dist/experimental/testing/internal/mocks/mock-hooks.js +59 -0
- package/dist/experimental/testing/internal/print.d.ts +2 -2
- package/dist/experimental/testing/internal/print.js +17 -11
- package/dist/experimental/testing/internal/query.d.ts +19 -9
- package/dist/experimental/testing/internal/query.js +91 -28
- package/dist/experimental/testing/internal/root.d.ts +1 -1
- package/dist/experimental/testing/internal/root.js +12 -8
- package/dist/experimental/testing/internal/text.d.ts +3 -2
- package/dist/experimental/testing/internal/text.js +12 -3
- package/dist/experimental/testing/internal/type-utils-internal.d.ts +44 -0
- package/dist/experimental/testing/internal/type-utils-internal.js +54 -0
- package/dist/experimental/testing/internal/types-internal.d.ts +20 -2
- package/dist/experimental/testing/render.d.ts +32 -6
- package/dist/experimental/testing/render.js +96 -32
- package/dist/experimental/testing/type-utils.d.ts +2 -2
- package/dist/experimental/testing/type-utils.js +1 -1
- package/dist/experimental/testing/types.d.ts +127 -10
- package/dist/experimental/testing/utils.d.ts +11 -0
- package/dist/experimental/testing/utils.js +24 -0
- package/dist/hubspot.d.ts +2 -4
- package/dist/hubspot.js +3 -3
- package/dist/index.d.ts +5 -5
- package/dist/index.js +5 -5
- package/dist/internal/global-utils.d.ts +6 -0
- package/dist/internal/global-utils.js +37 -0
- package/dist/internal/hook-utils.d.ts +19 -0
- package/dist/internal/hook-utils.js +34 -0
- package/dist/logger.d.ts +1 -8
- package/dist/logger.js +3 -2
- package/dist/pages/home/index.d.ts +1 -1
- package/dist/pages/home/index.js +1 -1
- package/dist/{__synced__/remoteComponents.synced.d.ts → shared/remoteComponents.d.ts} +103 -103
- package/dist/{__synced__/remoteComponents.synced.js → shared/remoteComponents.js} +1 -1
- package/dist/{__synced__/types/components/accordion.synced.d.ts → shared/types/components/accordion.d.ts} +2 -2
- package/dist/{__synced__/types/components/alert.synced.d.ts → shared/types/components/alert.d.ts} +2 -1
- package/dist/{__synced__/types/components/app-home-header-actions.synced.d.ts → shared/types/components/app-home-header-actions.d.ts} +4 -4
- package/dist/{__synced__/types/components/button-row.synced.d.ts → shared/types/components/button-row.d.ts} +2 -2
- package/dist/{__synced__/types/components/button.synced.d.ts → shared/types/components/button.d.ts} +3 -3
- package/dist/{__synced__/types/components/card.synced.d.ts → shared/types/components/card.d.ts} +2 -1
- package/dist/{__synced__/types/components/chart.synced.d.ts → shared/types/components/chart.d.ts} +2 -1
- package/dist/{__synced__/types/components/description-list.synced.d.ts → shared/types/components/description-list.d.ts} +3 -2
- package/dist/{__synced__/types/components/divider.synced.d.ts → shared/types/components/divider.d.ts} +2 -2
- package/dist/{__synced__/types/components/dropdown.synced.d.ts → shared/types/components/dropdown.d.ts} +5 -5
- package/dist/{__synced__/types/components/empty-state.synced.d.ts → shared/types/components/empty-state.d.ts} +2 -1
- package/dist/{__synced__/types/components/error-state.synced.d.ts → shared/types/components/error-state.d.ts} +2 -1
- package/dist/{__synced__/types/components/form.synced.d.ts → shared/types/components/form.d.ts} +3 -3
- package/dist/{__synced__/types/components/heading.synced.d.ts → shared/types/components/heading.d.ts} +2 -1
- package/dist/{__synced__/types/components/icon.synced.d.ts → shared/types/components/icon.d.ts} +2 -2
- package/dist/{__synced__/types/components/iframe.synced.d.ts → shared/types/components/iframe.d.ts} +2 -2
- package/dist/{__synced__/types/components/illustration.synced.d.ts → shared/types/components/illustration.d.ts} +2 -1
- package/dist/{__synced__/types/components/image.synced.d.ts → shared/types/components/image.d.ts} +3 -3
- package/dist/shared/types/components/index.d.ts +38 -0
- package/dist/{__synced__/types/components/inputs.synced.d.ts → shared/types/components/inputs.d.ts} +2 -1
- package/dist/{__synced__/types/components/layouts.synced.d.ts → shared/types/components/layouts.d.ts} +6 -6
- package/dist/{__synced__/types/components/link.synced.d.ts → shared/types/components/link.d.ts} +3 -3
- package/dist/{__synced__/types/components/list.synced.d.ts → shared/types/components/list.d.ts} +2 -1
- package/dist/{__synced__/types/components/loading-spinner.synced.d.ts → shared/types/components/loading-spinner.d.ts} +2 -2
- package/dist/{__synced__/types/components/modal.synced.d.ts → shared/types/components/modal.d.ts} +4 -4
- package/dist/{__synced__/types/components/panel.synced.d.ts → shared/types/components/panel.d.ts} +5 -5
- package/dist/{__synced__/types/components/progress-bar.synced.d.ts → shared/types/components/progress-bar.d.ts} +2 -1
- package/dist/{__synced__/types/components/selects.synced.d.ts → shared/types/components/selects.d.ts} +2 -1
- package/dist/{__synced__/types/components/statistics.synced.d.ts → shared/types/components/statistics.d.ts} +4 -3
- package/dist/{__synced__/types/components/status-tag.synced.d.ts → shared/types/components/status-tag.d.ts} +2 -1
- package/dist/{__synced__/types/components/step-indicator.synced.d.ts → shared/types/components/step-indicator.d.ts} +2 -2
- package/dist/{__synced__/types/components/table.synced.d.ts → shared/types/components/table.d.ts} +5 -4
- package/dist/shared/types/components/table.js +1 -0
- package/dist/{__synced__/types/components/tabs.synced.d.ts → shared/types/components/tabs.d.ts} +3 -2
- package/dist/shared/types/components/tabs.js +1 -0
- package/dist/{__synced__/types/components/tag.synced.d.ts → shared/types/components/tag.d.ts} +3 -3
- package/dist/shared/types/components/tag.js +1 -0
- package/dist/{__synced__/types/components/text.synced.d.ts → shared/types/components/text.d.ts} +2 -1
- package/dist/shared/types/components/text.js +1 -0
- package/dist/{__synced__/types/components/tile.synced.d.ts → shared/types/components/tile.d.ts} +2 -1
- package/dist/shared/types/components/tile.js +1 -0
- package/dist/{__synced__/types/components/toggle.synced.d.ts → shared/types/components/toggle.d.ts} +2 -2
- package/dist/shared/types/components/toggle.js +1 -0
- package/dist/{__synced__/types/components/toggleInputs.synced.d.ts → shared/types/components/toggleInputs.d.ts} +4 -4
- package/dist/shared/types/components/toggleInputs.js +1 -0
- package/dist/{__synced__/types/components/tooltip.synced.d.ts → shared/types/components/tooltip.d.ts} +2 -1
- package/dist/shared/types/components/tooltip.js +1 -0
- package/dist/{__synced__/types/context.synced.d.ts → shared/types/context.d.ts} +1 -1
- package/dist/shared/types/context.js +1 -0
- package/dist/{__synced__/types/crm.synced.d.ts → shared/types/crm.d.ts} +13 -13
- package/dist/shared/types/crm.js +1 -0
- package/dist/{__synced__/experimental/types.synced.d.ts → shared/types/experimental.d.ts} +10 -14
- package/dist/shared/types/experimental.js +1 -0
- package/dist/shared/types/extend.d.ts +4 -0
- package/dist/shared/types/extend.js +1 -0
- package/dist/{__synced__/types/extension-points.synced.d.ts → shared/types/extension-points.d.ts} +18 -10
- package/dist/{__synced__/types/http-requests.synced.d.ts → shared/types/http-requests.d.ts} +1 -1
- package/dist/shared/types/index.d.ts +8 -0
- package/dist/shared/types/index.js +1 -0
- package/dist/shared/types/logger.d.ts +7 -0
- package/dist/shared/types/logger.js +1 -0
- package/dist/shared/types/reactions.js +1 -0
- package/dist/{__synced__/types/shared.synced.d.ts → shared/types/shared.d.ts} +3 -0
- package/dist/shared/types/worker-globals.d.ts +17 -0
- package/dist/shared/types/worker-globals.js +1 -0
- package/dist/{__synced__/utils/remote-component-registry.synced.d.ts → shared/utils/remote-component-registry.d.ts} +1 -1
- package/dist/{__synced__/utils/remote-component-registry.synced.js → shared/utils/remote-component-registry.js} +0 -1
- package/package.json +6 -4
- package/dist/__synced__/experimental/types.synced.js +0 -5
- package/dist/__synced__/types/components/index.synced.d.ts +0 -38
- package/dist/__synced__/types/index.synced.d.ts +0 -8
- package/dist/__synced__/types/index.synced.js +0 -1
- /package/dist/{__synced__/types/actions.synced.js → experimental/testing/__tests__/createRenderer.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/accordion.synced.js → experimental/testing/__tests__/findByTestId.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/alert.synced.js → experimental/testing/__tests__/logger.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/app-home-header-actions.synced.js → experimental/testing/__tests__/maybeFindByTestId.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/button-row.synced.js → experimental/testing/__tests__/mocks.actions.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/button.synced.js → experimental/testing/__tests__/mocks.context.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/card.synced.js → experimental/testing/__tests__/mocks.runServerlessFunction.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/description-list.synced.js → experimental/testing/__tests__/mocks.useAssociations.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/divider.synced.js → experimental/testing/__tests__/mocks.useCrmProperties.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/dropdown.synced.js → experimental/testing/__tests__/props.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/empty-state.synced.js → experimental/testing/__tests__/testId.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/actions.synced.d.ts → shared/types/actions.d.ts} +0 -0
- /package/dist/{__synced__/types/components/error-state.synced.js → shared/types/actions.js} +0 -0
- /package/dist/{__synced__/types/components/form.synced.js → shared/types/components/accordion.js} +0 -0
- /package/dist/{__synced__/types/components/heading.synced.js → shared/types/components/alert.js} +0 -0
- /package/dist/{__synced__/types/components/icon.synced.js → shared/types/components/app-home-header-actions.js} +0 -0
- /package/dist/{__synced__/types/components/iframe.synced.js → shared/types/components/button-row.js} +0 -0
- /package/dist/{__synced__/types/components/image.synced.js → shared/types/components/button.js} +0 -0
- /package/dist/{__synced__/types/components/index.synced.js → shared/types/components/card.js} +0 -0
- /package/dist/{__synced__/types/components/chart.synced.js → shared/types/components/chart.js} +0 -0
- /package/dist/{__synced__/types/components/inputs.synced.js → shared/types/components/description-list.js} +0 -0
- /package/dist/{__synced__/types/components/layouts.synced.js → shared/types/components/divider.js} +0 -0
- /package/dist/{__synced__/types/components/link.synced.js → shared/types/components/dropdown.js} +0 -0
- /package/dist/{__synced__/types/components/list.synced.js → shared/types/components/empty-state.js} +0 -0
- /package/dist/{__synced__/types/components/loading-spinner.synced.js → shared/types/components/error-state.js} +0 -0
- /package/dist/{__synced__/types/components/modal.synced.js → shared/types/components/form.js} +0 -0
- /package/dist/{__synced__/types/components/panel.synced.js → shared/types/components/heading.js} +0 -0
- /package/dist/{__synced__/types/components/progress-bar.synced.js → shared/types/components/icon.js} +0 -0
- /package/dist/{__synced__/types/components/selects.synced.js → shared/types/components/iframe.js} +0 -0
- /package/dist/{__synced__/types/components/illustration.synced.js → shared/types/components/illustration.js} +0 -0
- /package/dist/{__synced__/types/components/statistics.synced.js → shared/types/components/image.js} +0 -0
- /package/dist/{__synced__/types/components/status-tag.synced.js → shared/types/components/index.js} +0 -0
- /package/dist/{__synced__/types/components/step-indicator.synced.js → shared/types/components/inputs.js} +0 -0
- /package/dist/{__synced__/types/components/table.synced.js → shared/types/components/layouts.js} +0 -0
- /package/dist/{__synced__/types/components/tabs.synced.js → shared/types/components/link.js} +0 -0
- /package/dist/{__synced__/types/components/tag.synced.js → shared/types/components/list.js} +0 -0
- /package/dist/{__synced__/types/components/text.synced.js → shared/types/components/loading-spinner.js} +0 -0
- /package/dist/{__synced__/types/components/tile.synced.js → shared/types/components/modal.js} +0 -0
- /package/dist/{__synced__/types/components/toggle.synced.js → shared/types/components/panel.js} +0 -0
- /package/dist/{__synced__/types/components/toggleInputs.synced.js → shared/types/components/progress-bar.js} +0 -0
- /package/dist/{__synced__/types/components/tooltip.synced.js → shared/types/components/selects.js} +0 -0
- /package/dist/{__synced__/types/context.synced.js → shared/types/components/statistics.js} +0 -0
- /package/dist/{__synced__/types/crm.synced.js → shared/types/components/status-tag.js} +0 -0
- /package/dist/{__synced__/types/reactions.synced.js → shared/types/components/step-indicator.js} +0 -0
- /package/dist/{__synced__/types/extension-points.synced.js → shared/types/extension-points.js} +0 -0
- /package/dist/{__synced__/types/http-requests.synced.js → shared/types/http-requests.js} +0 -0
- /package/dist/{__synced__/types/reactions.synced.d.ts → shared/types/reactions.d.ts} +0 -0
- /package/dist/{__synced__/types/shared.synced.js → shared/types/shared.js} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { HubSpotReactComponent, UnknownComponentProps } from '../../../
|
|
2
|
-
import type { ElementMatcher, RenderedElementNode } from '../types';
|
|
3
|
-
import type { RenderedParentNodeInternal } from './types-internal';
|
|
1
|
+
import type { HubSpotReactComponent, UnknownComponentProps } from '../../../shared/types/shared.ts';
|
|
2
|
+
import type { ElementMatcher, RenderedElementNode } from '../types.ts';
|
|
3
|
+
import type { RenderedDocumentInternal, RenderedParentNodeInternal } from './types-internal.ts';
|
|
4
4
|
/**
|
|
5
5
|
* Finds the first descendant element node that matches the given component.
|
|
6
6
|
*
|
|
@@ -9,7 +9,7 @@ import type { RenderedParentNodeInternal } from './types-internal';
|
|
|
9
9
|
* @param matcher An optional matcher to filter the elements.
|
|
10
10
|
* @returns The first element node that matches the given component or `null` if no match is found.
|
|
11
11
|
*/
|
|
12
|
-
export declare const maybeFind: <TProps extends UnknownComponentProps>(parentNode: RenderedParentNodeInternal, targetComponent: HubSpotReactComponent<TProps>, matcher?: ElementMatcher<TProps>
|
|
12
|
+
export declare const maybeFind: <TProps extends UnknownComponentProps>(parentNode: RenderedParentNodeInternal, targetComponent: HubSpotReactComponent<TProps>, matcher?: ElementMatcher<TProps>) => RenderedElementNode<TProps> | null;
|
|
13
13
|
/**
|
|
14
14
|
* Finds the first descendant element node that matches the given component.
|
|
15
15
|
*
|
|
@@ -18,7 +18,7 @@ export declare const maybeFind: <TProps extends UnknownComponentProps>(parentNod
|
|
|
18
18
|
* @param matcher An optional matcher to filter the elements.
|
|
19
19
|
* @returns The first element node that matches the given component.
|
|
20
20
|
*/
|
|
21
|
-
export declare const find: <TProps extends UnknownComponentProps>(parentNode: RenderedParentNodeInternal, targetComponent: HubSpotReactComponent<TProps>, matcher?: ElementMatcher<TProps>
|
|
21
|
+
export declare const find: <TProps extends UnknownComponentProps>(parentNode: RenderedParentNodeInternal, targetComponent: HubSpotReactComponent<TProps>, matcher?: ElementMatcher<TProps>) => RenderedElementNode<TProps>;
|
|
22
22
|
/**
|
|
23
23
|
* Finds all descendant element nodes that match the given component.
|
|
24
24
|
*
|
|
@@ -27,7 +27,7 @@ export declare const find: <TProps extends UnknownComponentProps>(parentNode: Re
|
|
|
27
27
|
* @param matcher An optional matcher to filter the elements.
|
|
28
28
|
* @returns An array of element nodes that match the given component.
|
|
29
29
|
*/
|
|
30
|
-
export declare const findAll: <TProps extends UnknownComponentProps>(parentNode: RenderedParentNodeInternal, targetComponent: HubSpotReactComponent<TProps>, matcher?: ElementMatcher<TProps>
|
|
30
|
+
export declare const findAll: <TProps extends UnknownComponentProps>(parentNode: RenderedParentNodeInternal, targetComponent: HubSpotReactComponent<TProps>, matcher?: ElementMatcher<TProps>) => RenderedElementNode<TProps>[];
|
|
31
31
|
/**
|
|
32
32
|
* Finds the first direct child element node that matches the given component.
|
|
33
33
|
*
|
|
@@ -36,7 +36,7 @@ export declare const findAll: <TProps extends UnknownComponentProps>(parentNode:
|
|
|
36
36
|
* @param matcher An optional matcher to filter the elements.
|
|
37
37
|
* @returns The first child element node that matches the given component.
|
|
38
38
|
*/
|
|
39
|
-
export declare const findChild: <TProps extends UnknownComponentProps>(parentNode: RenderedParentNodeInternal, targetComponent: HubSpotReactComponent<TProps>, matcher?: ElementMatcher<TProps>
|
|
39
|
+
export declare const findChild: <TProps extends UnknownComponentProps>(parentNode: RenderedParentNodeInternal, targetComponent: HubSpotReactComponent<TProps>, matcher?: ElementMatcher<TProps>) => RenderedElementNode<TProps>;
|
|
40
40
|
/**
|
|
41
41
|
* Finds the first direct child element node that matches the given component.
|
|
42
42
|
*
|
|
@@ -45,7 +45,7 @@ export declare const findChild: <TProps extends UnknownComponentProps>(parentNod
|
|
|
45
45
|
* @param matcher An optional matcher to filter the elements.
|
|
46
46
|
* @returns The first child element node that matches the given component.
|
|
47
47
|
*/
|
|
48
|
-
export declare const maybeFindChild: <TProps extends UnknownComponentProps>(parentNode: RenderedParentNodeInternal, targetComponent: HubSpotReactComponent<TProps>, matcher?: ElementMatcher<TProps>
|
|
48
|
+
export declare const maybeFindChild: <TProps extends UnknownComponentProps>(parentNode: RenderedParentNodeInternal, targetComponent: HubSpotReactComponent<TProps>, matcher?: ElementMatcher<TProps>) => RenderedElementNode<TProps> | null;
|
|
49
49
|
/**
|
|
50
50
|
* Finds all direct child element nodes that match the given component.
|
|
51
51
|
*
|
|
@@ -54,4 +54,14 @@ export declare const maybeFindChild: <TProps extends UnknownComponentProps>(pare
|
|
|
54
54
|
* @param matcher An optional matcher to filter the elements.
|
|
55
55
|
* @returns An array of child element nodes that match the given component.
|
|
56
56
|
*/
|
|
57
|
-
export declare const findAllChildren: <TProps extends UnknownComponentProps>(parentNode: RenderedParentNodeInternal, targetComponent: HubSpotReactComponent<TProps>, matcher?: ElementMatcher<TProps>
|
|
57
|
+
export declare const findAllChildren: <TProps extends UnknownComponentProps>(parentNode: RenderedParentNodeInternal, targetComponent: HubSpotReactComponent<TProps>, matcher?: ElementMatcher<TProps>) => RenderedElementNode<TProps>[];
|
|
58
|
+
/**
|
|
59
|
+
* Finds the first descendant element node that matches the given component and test ID.
|
|
60
|
+
*
|
|
61
|
+
* @param parentNode The parent node to search in.
|
|
62
|
+
* @param targetComponent The component to find.
|
|
63
|
+
* @param testId The test ID to find.
|
|
64
|
+
* @returns The first element node that matches the given component and test ID.
|
|
65
|
+
*/
|
|
66
|
+
export declare const maybeFindByTestId: <TProps extends UnknownComponentProps>(document: RenderedDocumentInternal, targetComponent: HubSpotReactComponent<TProps>, testId: string) => RenderedElementNode<TProps> | null;
|
|
67
|
+
export declare const findByTestId: <TProps extends UnknownComponentProps>(document: RenderedDocumentInternal, targetComponent: HubSpotReactComponent<TProps>, testId: string) => RenderedElementNode<TProps>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { __hubSpotComponentRegistry } from
|
|
2
|
-
import { isRenderedElementNode
|
|
3
|
-
import { ComponentNotFoundError, FindInvalidComponentError, InvalidComponentsError, } from
|
|
4
|
-
import { checkElementMatches } from
|
|
1
|
+
import { __hubSpotComponentRegistry } from "../../../shared/remoteComponents.js";
|
|
2
|
+
import { isRenderedElementNode } from "../type-utils.js";
|
|
3
|
+
import { ComponentMismatchedByTestIdError, ComponentNotFoundByTestIdError, ComponentNotFoundError, FindInvalidComponentError, InvalidComponentsError, } from "./errors.js";
|
|
4
|
+
import { checkElementMatches } from "./match.js";
|
|
5
|
+
import { asRenderedParentNode } from "./type-utils-internal.js";
|
|
5
6
|
const addMatchToFindResult = (findResult, match, options) => {
|
|
6
7
|
if (options.findFirstOnly) {
|
|
7
8
|
findResult.match = match;
|
|
@@ -19,32 +20,32 @@ const addMatchToFindResult = (findResult, match, options) => {
|
|
|
19
20
|
* @param findResult The find result to mutate.
|
|
20
21
|
*/
|
|
21
22
|
const findInternalHelper = (parentNode, options, findResult) => {
|
|
22
|
-
const {
|
|
23
|
+
const { childNodes } = parentNode;
|
|
23
24
|
const { targetComponent, matcher, findFirstOnly, findDirectChildrenOnly } = options;
|
|
24
25
|
const targetComponentName = __hubSpotComponentRegistry.getComponentName(targetComponent);
|
|
25
|
-
for (const
|
|
26
|
-
if (!isRenderedElementNode(
|
|
26
|
+
for (const childNode of childNodes) {
|
|
27
|
+
if (!isRenderedElementNode(childNode)) {
|
|
27
28
|
// Skip over non-element child nodes (just text nodes)
|
|
28
29
|
continue;
|
|
29
30
|
}
|
|
30
|
-
if (
|
|
31
|
-
checkElementMatches(
|
|
31
|
+
if (childNode.name === targetComponentName &&
|
|
32
|
+
checkElementMatches(childNode, matcher)) {
|
|
32
33
|
// We found a match, so add it to the find result
|
|
33
|
-
addMatchToFindResult(findResult,
|
|
34
|
+
addMatchToFindResult(findResult, childNode, options);
|
|
34
35
|
if (findFirstOnly) {
|
|
35
36
|
return;
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
|
-
// We only search in nested
|
|
39
|
+
// We only search in nested child nodes and fragment props if we're not only looking for children
|
|
39
40
|
if (!findDirectChildrenOnly) {
|
|
40
41
|
// Search for the component in the fragment props
|
|
41
|
-
const { props } =
|
|
42
|
-
const fragmentProps = __hubSpotComponentRegistry.getComponentFragmentPropNames(
|
|
42
|
+
const { props } = childNode;
|
|
43
|
+
const fragmentProps = __hubSpotComponentRegistry.getComponentFragmentPropNames(childNode.name);
|
|
43
44
|
for (const fragmentPropName of fragmentProps) {
|
|
44
45
|
const maybeFragment = props[fragmentPropName];
|
|
45
46
|
// NOTE: As part of the conversion process of converting remote nodes to rendered nodes, we
|
|
46
47
|
// create a RenderedFragmentNode for each fragment prop and put that into the props object.
|
|
47
|
-
if (
|
|
48
|
+
if (maybeFragment) {
|
|
48
49
|
findInternalHelper(maybeFragment, options, findResult);
|
|
49
50
|
if (findFirstOnly && findResult.match) {
|
|
50
51
|
return;
|
|
@@ -52,7 +53,7 @@ const findInternalHelper = (parentNode, options, findResult) => {
|
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
// Search for the component in the child
|
|
55
|
-
findInternalHelper(
|
|
56
|
+
findInternalHelper(childNode, options, findResult);
|
|
56
57
|
if (findFirstOnly && findResult.match) {
|
|
57
58
|
return;
|
|
58
59
|
}
|
|
@@ -60,6 +61,22 @@ const findInternalHelper = (parentNode, options, findResult) => {
|
|
|
60
61
|
}
|
|
61
62
|
return;
|
|
62
63
|
};
|
|
64
|
+
const validateComponent = (targetComponent, findMethodName) => {
|
|
65
|
+
const targetComponentName = __hubSpotComponentRegistry.getComponentName(targetComponent);
|
|
66
|
+
if (!targetComponentName) {
|
|
67
|
+
throw new FindInvalidComponentError({
|
|
68
|
+
findMethodName,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
targetComponentName,
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
const validateRenderedDocument = (document) => {
|
|
76
|
+
if (document.hasInvalidComponentNames()) {
|
|
77
|
+
throw new InvalidComponentsError(document.rootNode);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
63
80
|
/**
|
|
64
81
|
* Internal utility that centralizes finding elements in the rendered tree (including error handling).
|
|
65
82
|
*
|
|
@@ -70,28 +87,19 @@ const findInternalHelper = (parentNode, options, findResult) => {
|
|
|
70
87
|
const findInternal = (parentNode, options) => {
|
|
71
88
|
const { document } = parentNode;
|
|
72
89
|
const { targetComponent, findMethodName, shouldThrowErrorIfNotFound } = options;
|
|
73
|
-
const targetComponentName =
|
|
74
|
-
|
|
75
|
-
throw new FindInvalidComponentError({
|
|
76
|
-
findMethodName,
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
// We always validate the document before running the find operation since the document may
|
|
80
|
-
// have been updated asynchronously in the background.
|
|
81
|
-
if (document.hasInvalidComponentNames()) {
|
|
82
|
-
throw new InvalidComponentsError(document.rootNode);
|
|
83
|
-
}
|
|
90
|
+
const { targetComponentName } = validateComponent(targetComponent, findMethodName);
|
|
91
|
+
validateRenderedDocument(document);
|
|
84
92
|
// Initialize the find result that will be mutated in place
|
|
85
93
|
const findResult = {
|
|
86
94
|
match: null,
|
|
87
95
|
allMatches: [],
|
|
88
96
|
};
|
|
89
97
|
// Run the internal find helper to recursively search the rendered tree
|
|
90
|
-
findInternalHelper(parentNode, options, findResult);
|
|
98
|
+
findInternalHelper(asRenderedParentNode(parentNode), options, findResult);
|
|
91
99
|
if (findResult.match === null && shouldThrowErrorIfNotFound) {
|
|
92
100
|
throw new ComponentNotFoundError({
|
|
93
101
|
findMethodName: options.findMethodName,
|
|
94
|
-
parentNode,
|
|
102
|
+
parentNode: asRenderedParentNode(parentNode),
|
|
95
103
|
componentName: targetComponentName,
|
|
96
104
|
});
|
|
97
105
|
}
|
|
@@ -211,3 +219,58 @@ export const findAllChildren = (parentNode, targetComponent, matcher) => {
|
|
|
211
219
|
});
|
|
212
220
|
return allMatches;
|
|
213
221
|
};
|
|
222
|
+
const findByTestIdHelper = (options) => {
|
|
223
|
+
const { document, targetComponent, testId, findMethodName, shouldThrowErrorIfNotFound, } = options;
|
|
224
|
+
const { targetComponentName } = validateComponent(targetComponent, findMethodName);
|
|
225
|
+
validateRenderedDocument(document);
|
|
226
|
+
const matchingElement = document.testIdToElementMap.get(testId);
|
|
227
|
+
if (!matchingElement) {
|
|
228
|
+
if (shouldThrowErrorIfNotFound) {
|
|
229
|
+
throw new ComponentNotFoundByTestIdError({
|
|
230
|
+
findMethodName,
|
|
231
|
+
componentName: targetComponentName,
|
|
232
|
+
testId,
|
|
233
|
+
rootNode: document.rootNode,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
if (!matchingElement.isMatch(targetComponent)) {
|
|
239
|
+
throw new ComponentMismatchedByTestIdError({
|
|
240
|
+
findMethodName,
|
|
241
|
+
actualComponentName: matchingElement.name,
|
|
242
|
+
expectedComponentName: targetComponentName,
|
|
243
|
+
testId,
|
|
244
|
+
rootNode: document.rootNode,
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
return matchingElement;
|
|
248
|
+
};
|
|
249
|
+
/**
|
|
250
|
+
* Finds the first descendant element node that matches the given component and test ID.
|
|
251
|
+
*
|
|
252
|
+
* @param parentNode The parent node to search in.
|
|
253
|
+
* @param targetComponent The component to find.
|
|
254
|
+
* @param testId The test ID to find.
|
|
255
|
+
* @returns The first element node that matches the given component and test ID.
|
|
256
|
+
*/
|
|
257
|
+
export const maybeFindByTestId = (document, targetComponent, testId) => {
|
|
258
|
+
const maybeMatchingElement = findByTestIdHelper({
|
|
259
|
+
document,
|
|
260
|
+
targetComponent,
|
|
261
|
+
testId,
|
|
262
|
+
findMethodName: 'maybeFindByTestId',
|
|
263
|
+
shouldThrowErrorIfNotFound: false,
|
|
264
|
+
});
|
|
265
|
+
return maybeMatchingElement;
|
|
266
|
+
};
|
|
267
|
+
export const findByTestId = (document, targetComponent, testId) => {
|
|
268
|
+
const matchingElement = findByTestIdHelper({
|
|
269
|
+
document,
|
|
270
|
+
targetComponent,
|
|
271
|
+
testId,
|
|
272
|
+
findMethodName: 'findByTestId',
|
|
273
|
+
shouldThrowErrorIfNotFound: true,
|
|
274
|
+
});
|
|
275
|
+
return matchingElement;
|
|
276
|
+
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { RenderedNodeType } from
|
|
2
|
-
import {
|
|
3
|
-
import { debugLog } from
|
|
4
|
-
import { printNode } from
|
|
5
|
-
import { find, findAll, findAllChildren, findChild, maybeFind, maybeFindChild, } from
|
|
1
|
+
import { RenderedNodeType } from "../types.js";
|
|
2
|
+
import { EMPTY_RENDERED_CHILD_NODES } from "./constants.js";
|
|
3
|
+
import { debugLog } from "./debug.js";
|
|
4
|
+
import { printNode } from "./print.js";
|
|
5
|
+
import { find, findAll, findAllChildren, findChild, maybeFind, maybeFindChild, } from "./query.js";
|
|
6
|
+
import { asRenderedNode } from "./type-utils-internal.js";
|
|
6
7
|
/**
|
|
7
8
|
* Creates a rendered root node.
|
|
8
9
|
*
|
|
@@ -13,10 +14,10 @@ export const createRootNode = (document) => {
|
|
|
13
14
|
const rootNode = {
|
|
14
15
|
nodeType: RenderedNodeType.Root,
|
|
15
16
|
text: null,
|
|
16
|
-
|
|
17
|
+
childNodes: EMPTY_RENDERED_CHILD_NODES,
|
|
17
18
|
document,
|
|
18
19
|
debugLog: (label) => {
|
|
19
|
-
debugLog(rootNode, label);
|
|
20
|
+
debugLog(asRenderedNode(rootNode), label);
|
|
20
21
|
},
|
|
21
22
|
find: (targetComponent, matcher) => {
|
|
22
23
|
return find(rootNode, targetComponent, matcher);
|
|
@@ -37,7 +38,10 @@ export const createRootNode = (document) => {
|
|
|
37
38
|
return maybeFindChild(rootNode, targetComponent, matcher);
|
|
38
39
|
},
|
|
39
40
|
toString: () => {
|
|
40
|
-
return printNode(rootNode);
|
|
41
|
+
return printNode(asRenderedNode(rootNode));
|
|
42
|
+
},
|
|
43
|
+
isMatch(__component, __matcher) {
|
|
44
|
+
return false;
|
|
41
45
|
},
|
|
42
46
|
};
|
|
43
47
|
return rootNode;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { type RemoteRoot, type RemoteText } from '@remote-ui/core';
|
|
2
|
-
import {
|
|
2
|
+
import { RenderedTextNode } from '../types.ts';
|
|
3
|
+
import { RenderedDocumentInternal } from './types-internal.ts';
|
|
3
4
|
/**
|
|
4
5
|
* Creates a rendered text node.
|
|
5
6
|
*
|
|
6
7
|
* @param remoteText The remote text node or string to create a text node from.
|
|
7
8
|
* @returns A rendered text node.
|
|
8
9
|
*/
|
|
9
|
-
export declare const createTextNode: (remoteText: RemoteText<RemoteRoot> | string) => RenderedTextNode;
|
|
10
|
+
export declare const createTextNode: (document: RenderedDocumentInternal, remoteText: RemoteText<RemoteRoot> | string) => RenderedTextNode;
|
|
@@ -1,16 +1,25 @@
|
|
|
1
|
-
import { RenderedNodeType } from
|
|
1
|
+
import { RenderedNodeType } from "../types.js";
|
|
2
|
+
import { debugLog } from "./debug.js";
|
|
3
|
+
import { asRenderedNode, asRenderedTextNode } from "./type-utils-internal.js";
|
|
2
4
|
/**
|
|
3
5
|
* Creates a rendered text node.
|
|
4
6
|
*
|
|
5
7
|
* @param remoteText The remote text node or string to create a text node from.
|
|
6
8
|
* @returns A rendered text node.
|
|
7
9
|
*/
|
|
8
|
-
export const createTextNode = (remoteText) => {
|
|
10
|
+
export const createTextNode = (document, remoteText) => {
|
|
9
11
|
const text = typeof remoteText === 'string' ? remoteText : remoteText.text;
|
|
10
12
|
const textNode = {
|
|
13
|
+
document,
|
|
11
14
|
nodeType: RenderedNodeType.Text,
|
|
12
15
|
text,
|
|
13
16
|
toString: () => text,
|
|
17
|
+
debugLog: (label) => {
|
|
18
|
+
debugLog(asRenderedNode(textNode), label);
|
|
19
|
+
},
|
|
20
|
+
isMatch(__component, __matcher) {
|
|
21
|
+
return false;
|
|
22
|
+
},
|
|
14
23
|
};
|
|
15
|
-
return textNode;
|
|
24
|
+
return asRenderedTextNode(textNode);
|
|
16
25
|
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { RenderedElementNode, RenderedFragmentNode, RenderedNode, RenderedParentNode, RenderedRootNode, RenderedTextNode } from '../types.ts';
|
|
2
|
+
import { RenderedElementNodeInternal, RenderedFragmentNodeInternal, RenderedNodeInternal, RenderedRootNodeInternal, RenderedParentNodeInternal, RenderedTextNodeInternal } from './types-internal.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Converts an internal rendered node to a public rendered node using a type assertion.
|
|
5
|
+
*
|
|
6
|
+
* @param node The node to convert.
|
|
7
|
+
* @returns The converted node.
|
|
8
|
+
*/
|
|
9
|
+
export declare const asRenderedNode: (node: RenderedNodeInternal) => RenderedNode;
|
|
10
|
+
/**
|
|
11
|
+
* Converts an internal rendered element node to a public rendered element node using a type assertion.
|
|
12
|
+
*
|
|
13
|
+
* @param node The node to convert.
|
|
14
|
+
* @returns The converted node.
|
|
15
|
+
*/
|
|
16
|
+
export declare const asRenderedElementNode: (node: RenderedElementNodeInternal) => RenderedElementNode;
|
|
17
|
+
/**
|
|
18
|
+
* Converts an internal rendered fragment node to a public rendered fragment node using a type assertion.
|
|
19
|
+
*
|
|
20
|
+
* @param node The node to convert.
|
|
21
|
+
* @returns The converted node.
|
|
22
|
+
*/
|
|
23
|
+
export declare const asRenderedFragmentNode: (node: RenderedFragmentNodeInternal) => RenderedFragmentNode;
|
|
24
|
+
/**
|
|
25
|
+
* Converts an internal rendered text node to a public rendered text node using a type assertion.
|
|
26
|
+
*
|
|
27
|
+
* @param node The node to convert.
|
|
28
|
+
* @returns The converted node.
|
|
29
|
+
*/
|
|
30
|
+
export declare const asRenderedTextNode: (node: RenderedTextNodeInternal) => RenderedTextNode;
|
|
31
|
+
/**
|
|
32
|
+
* Converts an internal rendered root node to a public rendered root node using a type assertion.
|
|
33
|
+
*
|
|
34
|
+
* @param node The node to convert.
|
|
35
|
+
* @returns The converted node.
|
|
36
|
+
*/
|
|
37
|
+
export declare const asRenderedRootNode: (node: RenderedRootNodeInternal) => RenderedRootNode;
|
|
38
|
+
/**
|
|
39
|
+
* Converts an internal rendered parent node to a public rendered parent node using a type assertion.
|
|
40
|
+
*
|
|
41
|
+
* @param node The node to convert.
|
|
42
|
+
* @returns The converted node.
|
|
43
|
+
*/
|
|
44
|
+
export declare const asRenderedParentNode: (node: RenderedParentNodeInternal) => RenderedParentNode;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts an internal rendered node to a public rendered node using a type assertion.
|
|
3
|
+
*
|
|
4
|
+
* @param node The node to convert.
|
|
5
|
+
* @returns The converted node.
|
|
6
|
+
*/
|
|
7
|
+
export const asRenderedNode = (node) => {
|
|
8
|
+
return node;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Converts an internal rendered element node to a public rendered element node using a type assertion.
|
|
12
|
+
*
|
|
13
|
+
* @param node The node to convert.
|
|
14
|
+
* @returns The converted node.
|
|
15
|
+
*/
|
|
16
|
+
export const asRenderedElementNode = (node) => {
|
|
17
|
+
return node;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Converts an internal rendered fragment node to a public rendered fragment node using a type assertion.
|
|
21
|
+
*
|
|
22
|
+
* @param node The node to convert.
|
|
23
|
+
* @returns The converted node.
|
|
24
|
+
*/
|
|
25
|
+
export const asRenderedFragmentNode = (node) => {
|
|
26
|
+
return node;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Converts an internal rendered text node to a public rendered text node using a type assertion.
|
|
30
|
+
*
|
|
31
|
+
* @param node The node to convert.
|
|
32
|
+
* @returns The converted node.
|
|
33
|
+
*/
|
|
34
|
+
export const asRenderedTextNode = (node) => {
|
|
35
|
+
return node;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Converts an internal rendered root node to a public rendered root node using a type assertion.
|
|
39
|
+
*
|
|
40
|
+
* @param node The node to convert.
|
|
41
|
+
* @returns The converted node.
|
|
42
|
+
*/
|
|
43
|
+
export const asRenderedRootNode = (node) => {
|
|
44
|
+
return node;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Converts an internal rendered parent node to a public rendered parent node using a type assertion.
|
|
48
|
+
*
|
|
49
|
+
* @param node The node to convert.
|
|
50
|
+
* @returns The converted node.
|
|
51
|
+
*/
|
|
52
|
+
export const asRenderedParentNode = (node) => {
|
|
53
|
+
return node;
|
|
54
|
+
};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { RemoteComponent, RemoteFragment, RemoteRoot, RemoteText } from '@remote-ui/core';
|
|
2
|
-
import
|
|
2
|
+
import { ExtensionPointApi, ExtensionPointLocation } from '../../../shared/types/extension-points.ts';
|
|
3
|
+
import { HubSpotReactComponent, UnknownComponentProps } from '../../../shared/types/shared.ts';
|
|
4
|
+
import { useAssociations, useCrmProperties } from '../../../crm/index.ts';
|
|
5
|
+
import type { ElementMatcher, RenderedElementNode, RenderedFragmentNode, RenderedNode, RenderedParentNode, RenderedRootNode, RenderedTextNode } from '../types.ts';
|
|
3
6
|
export type RemoteChildNode = RemoteComponent<any, RemoteRoot> | RemoteText<RemoteRoot>;
|
|
4
7
|
export type RemoteParentNode = RemoteRoot | RemoteComponent<any, RemoteRoot> | RemoteFragment;
|
|
5
8
|
/**
|
|
@@ -31,17 +34,32 @@ export interface RenderedDocumentInternal {
|
|
|
31
34
|
* @param run The function to execute.
|
|
32
35
|
*/
|
|
33
36
|
batchUpdate: (run: () => void) => void;
|
|
37
|
+
/**
|
|
38
|
+
* A lookup map of test IDs to elements.
|
|
39
|
+
*/
|
|
40
|
+
testIdToElementMap: Map<string, RenderedElementNode<UnknownComponentProps>>;
|
|
34
41
|
}
|
|
35
42
|
/**
|
|
36
43
|
* Adds the `document` property to the rendered node. We do not include this in the public types because it is not
|
|
37
44
|
* part of the public API, but we need it for internal use.
|
|
38
45
|
*/
|
|
39
|
-
type MakeRenderedNodeInternal<TRenderedNode extends RenderedNode> = TRenderedNode & {
|
|
46
|
+
type MakeRenderedNodeInternal<TRenderedNode extends RenderedNode> = Omit<TRenderedNode, 'isMatch'> & {
|
|
40
47
|
document: RenderedDocumentInternal;
|
|
48
|
+
isMatch(component: HubSpotReactComponent, matcher?: ElementMatcher<UnknownComponentProps>): boolean;
|
|
41
49
|
};
|
|
42
50
|
export type RenderedElementNodeInternal = MakeRenderedNodeInternal<RenderedElementNode>;
|
|
43
51
|
export type RenderedTextNodeInternal = MakeRenderedNodeInternal<RenderedTextNode>;
|
|
44
52
|
export type RenderedRootNodeInternal = MakeRenderedNodeInternal<RenderedRootNode>;
|
|
45
53
|
export type RenderedFragmentNodeInternal = MakeRenderedNodeInternal<RenderedFragmentNode>;
|
|
46
54
|
export type RenderedParentNodeInternal = MakeRenderedNodeInternal<RenderedParentNode>;
|
|
55
|
+
export type RenderedNodeInternal = RenderedElementNodeInternal | RenderedTextNodeInternal | RenderedRootNodeInternal | RenderedFragmentNodeInternal;
|
|
56
|
+
/**
|
|
57
|
+
* An object containing the mocks for the various functions that can be mocked.
|
|
58
|
+
*/
|
|
59
|
+
export interface RendererMockHooksInternal {
|
|
60
|
+
useCrmProperties: typeof useCrmProperties;
|
|
61
|
+
useAssociations: typeof useAssociations;
|
|
62
|
+
}
|
|
63
|
+
export type RendererMocksInternal<TExtensionPointLocationName extends ExtensionPointLocation = ExtensionPointLocation> = RendererMockHooksInternal & ExtensionPointApi<TExtensionPointLocationName>;
|
|
64
|
+
export type AnyFunction = (...args: any[]) => any;
|
|
47
65
|
export {};
|
|
@@ -1,9 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ExtensionPointLocation } from '../../shared/types/extension-points.ts';
|
|
2
|
+
import { Renderer } from './types.ts';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Creates a renderer object with methods for rendering and testing UI extension components.
|
|
5
|
+
* Mocks for supported React hooks and the Extension Point API are automatically provided based on the extension point location.
|
|
5
6
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
7
|
+
* Example usage:
|
|
8
|
+
*
|
|
9
|
+
* ```tsx
|
|
10
|
+
* import { createRenderer } from '@hubspot/ui-extensions/testing';
|
|
11
|
+
* import { Alert, Button, ButtonRow } from '@hubspot/ui-extensions';
|
|
12
|
+
*
|
|
13
|
+
* const { render, find } = createRenderer('crm.record.tab');
|
|
14
|
+
* render(
|
|
15
|
+
* <>
|
|
16
|
+
* <ButtonRow>
|
|
17
|
+
* <Button variant="secondary">Button 1</Button>
|
|
18
|
+
* <Button variant="primary">Button 2</Button>
|
|
19
|
+
* </ButtonRow>
|
|
20
|
+
* <Alert title="My Alert" />
|
|
21
|
+
* </>
|
|
22
|
+
* );
|
|
23
|
+
*
|
|
24
|
+
* // Find any button
|
|
25
|
+
* const button = find(Button);
|
|
26
|
+
*
|
|
27
|
+
* // Assertions
|
|
28
|
+
* expect(button.props.variant).toEqual('primary');
|
|
29
|
+
* expect(button.text).toEqual('Button 2');
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @param extensionPointLocation The extension point location.
|
|
33
|
+
* @returns A renderer object with methods for rendering and testing UI extension components.
|
|
8
34
|
*/
|
|
9
|
-
export declare const
|
|
35
|
+
export declare const createRenderer: <TExtensionPointLocation extends ExtensionPointLocation>(extensionPointLocation: TExtensionPointLocation) => Renderer<TExtensionPointLocation>;
|