@hubspot/ui-extensions 0.11.2 → 0.11.3
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 +5 -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,12 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
2
|
import { createRemoteRoot } from '@remote-ui/core';
|
|
2
3
|
import { createRoot as createReactRoot } from '@remote-ui/react';
|
|
3
|
-
import { convertRemoteRoot } from
|
|
4
|
-
import { createDocument } from
|
|
5
|
-
import { InvalidComponentsError, WaitForTimeoutError } from
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
4
|
+
import { convertRemoteRoot } from "./internal/convert.js";
|
|
5
|
+
import { createDocument } from "./internal/document.js";
|
|
6
|
+
import { InvalidComponentsError, InvalidExtensionPointLocationError, WaitForTimeoutError, } from "./internal/errors.js";
|
|
7
|
+
import { EXTENSION_POINT_LOCATIONS, } from "../../shared/types/extension-points.js";
|
|
8
|
+
import { MocksContextProvider } from "../../internal/hook-utils.js";
|
|
9
|
+
import { createMocksWithSpies } from "./internal/mocks/index.js";
|
|
10
|
+
import { find, findAll, findAllChildren, findByTestId, findChild, maybeFind, maybeFindByTestId, maybeFindChild, } from "./internal/query.js";
|
|
11
|
+
import { createRootNode } from "./internal/root.js";
|
|
12
|
+
import { asRenderedRootNode } from "./internal/type-utils-internal.js";
|
|
13
|
+
import { createDeferred, } from "./internal/utils/promise-utils.js";
|
|
10
14
|
const DEFAULT_WAIT_FOR_TIMEOUT_IN_MS = 1000;
|
|
11
15
|
const DEFAULT_WAIT_FOR_OPTIONS = {
|
|
12
16
|
timeoutInMs: DEFAULT_WAIT_FOR_TIMEOUT_IN_MS,
|
|
@@ -15,9 +19,9 @@ const DEFAULT_WAIT_FOR_OPTIONS = {
|
|
|
15
19
|
* Renders a UI extension component using React so that assertions can be made against the rendered output.
|
|
16
20
|
*
|
|
17
21
|
* @param node The React node to render.
|
|
18
|
-
* @returns A render result object
|
|
22
|
+
* @returns A render result object
|
|
19
23
|
*/
|
|
20
|
-
|
|
24
|
+
const render = (node, mocks) => {
|
|
21
25
|
let dirty = true;
|
|
22
26
|
let waitForChecksQueued = false;
|
|
23
27
|
let waitForList = [];
|
|
@@ -71,7 +75,7 @@ export const render = (node) => {
|
|
|
71
75
|
};
|
|
72
76
|
const remoteRoot = createRemoteRoot(remoteChannel);
|
|
73
77
|
const reactRoot = createReactRoot(remoteRoot);
|
|
74
|
-
reactRoot.render(node);
|
|
78
|
+
reactRoot.render(_jsx(MocksContextProvider, { value: mocks, children: node }));
|
|
75
79
|
remoteRoot.mount();
|
|
76
80
|
let maybeRenderedRootNode;
|
|
77
81
|
/**
|
|
@@ -100,24 +104,7 @@ export const render = (node) => {
|
|
|
100
104
|
throw new InvalidComponentsError(initialRenderedRootNode);
|
|
101
105
|
}
|
|
102
106
|
return {
|
|
103
|
-
|
|
104
|
-
return find(getLatestRootNode(), component, matcher);
|
|
105
|
-
},
|
|
106
|
-
findAll: (component, matcher) => {
|
|
107
|
-
return findAll(getLatestRootNode(), component, matcher);
|
|
108
|
-
},
|
|
109
|
-
findChild: (component, matcher) => {
|
|
110
|
-
return findChild(getLatestRootNode(), component, matcher);
|
|
111
|
-
},
|
|
112
|
-
findAllChildren: (component, matcher) => {
|
|
113
|
-
return findAllChildren(getLatestRootNode(), component, matcher);
|
|
114
|
-
},
|
|
115
|
-
maybeFindChild: (component, matcher) => {
|
|
116
|
-
return maybeFindChild(getLatestRootNode(), component, matcher);
|
|
117
|
-
},
|
|
118
|
-
maybeFind: (component, matcher) => {
|
|
119
|
-
return maybeFind(getLatestRootNode(), component, matcher);
|
|
120
|
-
},
|
|
107
|
+
getLatestRootNode,
|
|
121
108
|
waitFor: (check, options = DEFAULT_WAIT_FOR_OPTIONS) => {
|
|
122
109
|
const { timeoutInMs = DEFAULT_WAIT_FOR_TIMEOUT_IN_MS } = options;
|
|
123
110
|
try {
|
|
@@ -142,14 +129,91 @@ export const render = (node) => {
|
|
|
142
129
|
}
|
|
143
130
|
return deferred.promise;
|
|
144
131
|
},
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Creates a renderer object with methods for rendering and testing UI extension components.
|
|
136
|
+
* Mocks for supported React hooks and the Extension Point API are automatically provided based on the extension point location.
|
|
137
|
+
*
|
|
138
|
+
* Example usage:
|
|
139
|
+
*
|
|
140
|
+
* ```tsx
|
|
141
|
+
* import { createRenderer } from '@hubspot/ui-extensions/testing';
|
|
142
|
+
* import { Alert, Button, ButtonRow } from '@hubspot/ui-extensions';
|
|
143
|
+
*
|
|
144
|
+
* const { render, find } = createRenderer('crm.record.tab');
|
|
145
|
+
* render(
|
|
146
|
+
* <>
|
|
147
|
+
* <ButtonRow>
|
|
148
|
+
* <Button variant="secondary">Button 1</Button>
|
|
149
|
+
* <Button variant="primary">Button 2</Button>
|
|
150
|
+
* </ButtonRow>
|
|
151
|
+
* <Alert title="My Alert" />
|
|
152
|
+
* </>
|
|
153
|
+
* );
|
|
154
|
+
*
|
|
155
|
+
* // Find any button
|
|
156
|
+
* const button = find(Button);
|
|
157
|
+
*
|
|
158
|
+
* // Assertions
|
|
159
|
+
* expect(button.props.variant).toEqual('primary');
|
|
160
|
+
* expect(button.text).toEqual('Button 2');
|
|
161
|
+
* ```
|
|
162
|
+
*
|
|
163
|
+
* @param extensionPointLocation The extension point location.
|
|
164
|
+
* @returns A renderer object with methods for rendering and testing UI extension components.
|
|
165
|
+
*/
|
|
166
|
+
export const createRenderer = (extensionPointLocation) => {
|
|
167
|
+
if (!EXTENSION_POINT_LOCATIONS.includes(extensionPointLocation)) {
|
|
168
|
+
throw new InvalidExtensionPointLocationError(extensionPointLocation);
|
|
169
|
+
}
|
|
170
|
+
let renderResult = null;
|
|
171
|
+
const getRenderResult = () => {
|
|
172
|
+
if (!renderResult) {
|
|
173
|
+
throw new Error('Renderer not initialized');
|
|
174
|
+
}
|
|
175
|
+
return renderResult;
|
|
176
|
+
};
|
|
177
|
+
const getLatestRootNode = () => getRenderResult().getLatestRootNode();
|
|
178
|
+
const { mocks, spies } = createMocksWithSpies(extensionPointLocation);
|
|
179
|
+
return {
|
|
180
|
+
render: (node) => {
|
|
181
|
+
renderResult = render(node, mocks);
|
|
182
|
+
return asRenderedRootNode(renderResult.getLatestRootNode());
|
|
183
|
+
},
|
|
184
|
+
mocks: spies,
|
|
185
|
+
find: (component, matcher) => {
|
|
186
|
+
return find(getLatestRootNode(), component, matcher);
|
|
187
|
+
},
|
|
188
|
+
findAll: (component, matcher) => {
|
|
189
|
+
return findAll(getLatestRootNode(), component, matcher);
|
|
190
|
+
},
|
|
191
|
+
findChild: (component, matcher) => {
|
|
192
|
+
return findChild(getLatestRootNode(), component, matcher);
|
|
193
|
+
},
|
|
194
|
+
findAllChildren: (component, matcher) => {
|
|
195
|
+
return findAllChildren(getLatestRootNode(), component, matcher);
|
|
196
|
+
},
|
|
197
|
+
maybeFindChild: (component, matcher) => {
|
|
198
|
+
return maybeFindChild(getLatestRootNode(), component, matcher);
|
|
199
|
+
},
|
|
200
|
+
maybeFind: (component, matcher) => {
|
|
201
|
+
return maybeFind(getLatestRootNode(), component, matcher);
|
|
202
|
+
},
|
|
203
|
+
findByTestId: (component, testId) => {
|
|
204
|
+
return findByTestId(getLatestRootNode().document, component, testId);
|
|
205
|
+
},
|
|
206
|
+
maybeFindByTestId: (component, testId) => {
|
|
207
|
+
return maybeFindByTestId(getLatestRootNode().document, component, testId);
|
|
208
|
+
},
|
|
209
|
+
waitFor: (check, options = DEFAULT_WAIT_FOR_OPTIONS) => {
|
|
210
|
+
return getRenderResult().waitFor(check, options);
|
|
211
|
+
},
|
|
145
212
|
debugLog: (label) => {
|
|
146
213
|
return getLatestRootNode().debugLog(label);
|
|
147
214
|
},
|
|
148
215
|
getRootNode: () => {
|
|
149
|
-
return getLatestRootNode();
|
|
150
|
-
},
|
|
151
|
-
isMatch: (targetNode, component, matcher) => {
|
|
152
|
-
return isMatch(targetNode, component, matcher);
|
|
216
|
+
return asRenderedRootNode(getLatestRootNode());
|
|
153
217
|
},
|
|
154
218
|
};
|
|
155
219
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { type RenderedElementNode, type RenderedFragmentNode, type RenderedNode, type RenderedRootNode, type RenderedTextNode } from './types';
|
|
1
|
+
import { type RenderedElementNode, type RenderedFragmentNode, type RenderedNode, type RenderedRootNode, type RenderedTextNode } from './types.ts';
|
|
2
2
|
/**
|
|
3
3
|
* Type guard to check if a node is a rendered element node.
|
|
4
4
|
*
|
|
5
5
|
* @param node The node to check.
|
|
6
6
|
* @returns `true` if the node is a rendered element node.
|
|
7
7
|
*/
|
|
8
|
-
export declare const isRenderedElementNode: (node: RenderedNode | null | undefined) => node is RenderedElementNode
|
|
8
|
+
export declare const isRenderedElementNode: (node: RenderedNode | null | undefined) => node is RenderedElementNode;
|
|
9
9
|
/**
|
|
10
10
|
* Type guard to check if a node is a rendered text node.
|
|
11
11
|
*
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ExtensionPointApi, ExtensionPointApiActions, ExtensionPointLocation } from '../../shared/types/extension-points.ts';
|
|
2
|
+
import { ServerlessFuncRunner } from '../../shared/types/http-requests.ts';
|
|
3
|
+
import { SpyImpl } from 'tinyspy';
|
|
4
|
+
import { HubSpotReactComponent, HubSpotReactFragmentProp, UnknownComponentProps } from '../../shared/types/shared.ts';
|
|
5
|
+
import { useAssociations, useCrmProperties } from '../../crm/index.ts';
|
|
6
|
+
import { AnyFunction } from './internal/types-internal.ts';
|
|
2
7
|
/**
|
|
3
8
|
* The type of a rendered node.
|
|
4
9
|
*/
|
|
@@ -64,18 +69,40 @@ interface CommonQueryMethods {
|
|
|
64
69
|
*/
|
|
65
70
|
findAllChildren<TProps extends UnknownComponentProps>(component: HubSpotReactComponent<TProps>, matcher?: ElementMatcher<TProps>): RenderedElementNode<TProps>[];
|
|
66
71
|
}
|
|
72
|
+
interface BaseRenderedNode {
|
|
73
|
+
/**
|
|
74
|
+
* The type of the node.
|
|
75
|
+
*/
|
|
76
|
+
nodeType: RenderedNodeType;
|
|
77
|
+
/**
|
|
78
|
+
* Logs a string representation of the node as a console log. This is useful for debugging.
|
|
79
|
+
*/
|
|
80
|
+
debugLog: (label?: string) => void;
|
|
81
|
+
/**
|
|
82
|
+
* Checks if a node matches a specific component and optional matcher criteria.
|
|
83
|
+
*
|
|
84
|
+
* @param component The component to check.
|
|
85
|
+
* @param matcher An optional matcher to filter the elements.
|
|
86
|
+
* @returns Whether the node matches the component and matcher.
|
|
87
|
+
*/
|
|
88
|
+
isMatch<TComponentProps extends UnknownComponentProps>(this: BaseRenderedNode, component: HubSpotReactComponent<TComponentProps>, matcher?: ElementMatcher<TComponentProps>): this is RenderedElementNode<TComponentProps>;
|
|
89
|
+
/**
|
|
90
|
+
* Returns a string representation of the node.
|
|
91
|
+
*/
|
|
92
|
+
toString: () => string;
|
|
93
|
+
}
|
|
67
94
|
interface BaseRenderedParentNode {
|
|
68
95
|
/**
|
|
69
96
|
* The child nodes
|
|
70
97
|
*/
|
|
71
|
-
|
|
98
|
+
childNodes: RenderedChildNode[];
|
|
72
99
|
}
|
|
73
100
|
/**
|
|
74
101
|
* Represents a root node of a rendered component.
|
|
75
102
|
*
|
|
76
103
|
* NOTE: Rendered root nodes are immutable and are part of a snapshot for a single render cycle. They become immediately stale when a new render occurs.
|
|
77
104
|
*/
|
|
78
|
-
export interface RenderedRootNode extends BaseRenderedParentNode, CommonQueryMethods {
|
|
105
|
+
export interface RenderedRootNode extends BaseRenderedParentNode, BaseRenderedNode, CommonQueryMethods {
|
|
79
106
|
/**
|
|
80
107
|
* The type of the node (always `RenderedNodeType.Root` for a root node).
|
|
81
108
|
*/
|
|
@@ -100,7 +127,7 @@ export interface RenderedRootNode extends BaseRenderedParentNode, CommonQueryMet
|
|
|
100
127
|
*
|
|
101
128
|
* NOTE: Rendered fragment nodes are immutable and are part of a snapshot for a single render cycle. They become immediately stale when a new render occurs.
|
|
102
129
|
*/
|
|
103
|
-
export interface RenderedFragmentNode extends BaseRenderedParentNode, CommonQueryMethods {
|
|
130
|
+
export interface RenderedFragmentNode extends BaseRenderedParentNode, BaseRenderedNode, CommonQueryMethods {
|
|
104
131
|
/**
|
|
105
132
|
* The type of the node (always `RenderedNodeType.Fragment` for a fragment node).
|
|
106
133
|
*/
|
|
@@ -118,15 +145,20 @@ export interface RenderedFragmentNode extends BaseRenderedParentNode, CommonQuer
|
|
|
118
145
|
*/
|
|
119
146
|
toString: () => string;
|
|
120
147
|
}
|
|
121
|
-
|
|
148
|
+
/**
|
|
149
|
+
* Converts the component props to the props that will be attached to the rendered element node.
|
|
150
|
+
* Component props that are of type `ReactNode` are mapped to the `RenderedFragmentNode` type.
|
|
151
|
+
* `props.children` is removed from the props object since it becomes `childNodes` on the rendered element node.
|
|
152
|
+
*/
|
|
153
|
+
type RenderPropsFromComponentProps<TProps extends UnknownComponentProps> = Omit<{
|
|
122
154
|
[K in keyof TProps]: HubSpotReactFragmentProp extends TProps[K] ? RenderedFragmentNode : TProps[K];
|
|
123
|
-
}
|
|
155
|
+
}, 'children'>;
|
|
124
156
|
/**
|
|
125
157
|
* Represents an element node of a rendered component.
|
|
126
158
|
*
|
|
127
159
|
* NOTE: Rendered elements are immutable and are part of a snapshot for a single render cycle. They become immediately stale when a new render occurs.
|
|
128
160
|
*/
|
|
129
|
-
export interface RenderedElementNode<TProps extends UnknownComponentProps = UnknownComponentProps> extends BaseRenderedParentNode, CommonQueryMethods {
|
|
161
|
+
export interface RenderedElementNode<TProps extends UnknownComponentProps = UnknownComponentProps> extends BaseRenderedParentNode, BaseRenderedNode, CommonQueryMethods {
|
|
130
162
|
/**
|
|
131
163
|
* The type of the node (always `RenderedNodeType.Element` for an element node).
|
|
132
164
|
*/
|
|
@@ -166,7 +198,7 @@ export interface RenderedElementNode<TProps extends UnknownComponentProps = Unkn
|
|
|
166
198
|
*
|
|
167
199
|
* NOTE: Rendered text nodes are immutable and are part of a snapshot for a single render cycle. They become immediately stale when a new render occurs.
|
|
168
200
|
*/
|
|
169
|
-
export interface RenderedTextNode {
|
|
201
|
+
export interface RenderedTextNode extends BaseRenderedNode {
|
|
170
202
|
/**
|
|
171
203
|
* The type of the node (always `RenderedNodeType.Text` for a text node).
|
|
172
204
|
*/
|
|
@@ -212,10 +244,73 @@ export interface WaitForOptions {
|
|
|
212
244
|
*/
|
|
213
245
|
timeoutInMs?: number;
|
|
214
246
|
}
|
|
247
|
+
/**
|
|
248
|
+
* Represents a spy for a function. A function spy can be used to track the calls to a
|
|
249
|
+
* function and also control the return result of a function.
|
|
250
|
+
*
|
|
251
|
+
* See the [tinyspy](https://github.com/tiny-spy/tinyspy) library for more
|
|
252
|
+
* information about spies and the supported API.
|
|
253
|
+
*/
|
|
254
|
+
export type FunctionSpy<TFunction extends AnyFunction> = SpyImpl<Parameters<TFunction>, ReturnType<TFunction>>;
|
|
255
|
+
export type ExtensionPointApiActionSpies<TExtensionPointLocation extends ExtensionPointLocation> = {
|
|
256
|
+
[TActionName in keyof ExtensionPointApiActions<TExtensionPointLocation>]: ExtensionPointApiActions<TExtensionPointLocation>[TActionName] extends AnyFunction ? FunctionSpy<ExtensionPointApiActions<TExtensionPointLocation>[TActionName]> : never;
|
|
257
|
+
};
|
|
258
|
+
/**
|
|
259
|
+
* An object containing the spies for the various functions.
|
|
260
|
+
*/
|
|
261
|
+
export interface RendererSpies<TExtensionPointLocation extends ExtensionPointLocation> {
|
|
262
|
+
/**
|
|
263
|
+
* A spy for the `useCrmProperties` hook function.
|
|
264
|
+
* The spy can be used to track the calls to the hook function and also control the
|
|
265
|
+
* return result of the hook function.
|
|
266
|
+
*
|
|
267
|
+
* See the [tinyspy](https://github.com/tiny-spy/tinyspy) library for more
|
|
268
|
+
* information about spies and the supported API.
|
|
269
|
+
*/
|
|
270
|
+
useCrmProperties: FunctionSpy<typeof useCrmProperties>;
|
|
271
|
+
/**
|
|
272
|
+
* A spy for the `useAssociations` hook function.
|
|
273
|
+
* The spy can be used to track the calls to the hook function and also control the
|
|
274
|
+
* return result of the hook function.
|
|
275
|
+
*
|
|
276
|
+
* See the [tinyspy](https://github.com/tiny-spy/tinyspy) library for more
|
|
277
|
+
* information about spies and the supported API.
|
|
278
|
+
*/
|
|
279
|
+
useAssociations: FunctionSpy<typeof useAssociations>;
|
|
280
|
+
/**
|
|
281
|
+
* Mock context object that contains fake context data for the extension point API.
|
|
282
|
+
*/
|
|
283
|
+
context: ExtensionPointApi<TExtensionPointLocation>['context'];
|
|
284
|
+
/**
|
|
285
|
+
* A spy for the actions of the extension point API.
|
|
286
|
+
* The spy can be used to track the calls to the actions function and also control the
|
|
287
|
+
* return result of the actions function.
|
|
288
|
+
*
|
|
289
|
+
* See the [tinyspy](https://github.com/tiny-spy/tinyspy) library for more
|
|
290
|
+
* information about spies and the supported API.
|
|
291
|
+
*/
|
|
292
|
+
actions: ExtensionPointApiActionSpies<TExtensionPointLocation>;
|
|
293
|
+
/**
|
|
294
|
+
* A spy for the `runServerlessFunction` function.
|
|
295
|
+
* The spy can be used to track the calls to the function and also control the
|
|
296
|
+
* return result of the function.
|
|
297
|
+
*
|
|
298
|
+
* See the [tinyspy](https://github.com/tiny-spy/tinyspy) library for more
|
|
299
|
+
* information about spies and the supported API.
|
|
300
|
+
*/
|
|
301
|
+
runServerlessFunction: FunctionSpy<ServerlessFuncRunner>;
|
|
302
|
+
}
|
|
215
303
|
/**
|
|
216
304
|
* A result of a render operation.
|
|
217
305
|
*/
|
|
218
|
-
export interface
|
|
306
|
+
export interface Renderer<TExtensionPointLocation extends ExtensionPointLocation> extends CommonQueryMethods {
|
|
307
|
+
/**
|
|
308
|
+
* Renders a UI extension component using React so that assertions can be made against the rendered output.
|
|
309
|
+
*
|
|
310
|
+
* @param node The React node to render.
|
|
311
|
+
* @returns The root node of the rendered component.
|
|
312
|
+
*/
|
|
313
|
+
render: (node: React.ReactNode) => RenderedRootNode;
|
|
219
314
|
/**
|
|
220
315
|
* Waits for the given check to pass. If the check does not pass within the allowed amount of time, an error will be thrown.
|
|
221
316
|
*
|
|
@@ -235,7 +330,29 @@ export interface RenderResult extends CommonQueryMethods {
|
|
|
235
330
|
* @returns The root node.
|
|
236
331
|
*/
|
|
237
332
|
getRootNode: () => RenderedRootNode;
|
|
238
|
-
|
|
333
|
+
/**
|
|
334
|
+
* The mocks that can be used to control the behavior of the various functions.
|
|
335
|
+
*/
|
|
336
|
+
mocks: RendererSpies<TExtensionPointLocation>;
|
|
337
|
+
/**
|
|
338
|
+
* Finds the first descendant element node that matches the given component and test ID.
|
|
339
|
+
*
|
|
340
|
+
* @param component The component to find.
|
|
341
|
+
* @param testId The test ID to find.
|
|
342
|
+
* @returns The first element node that matches the given component and test ID.
|
|
343
|
+
*/
|
|
344
|
+
findByTestId<TProps extends UnknownComponentProps>(component: HubSpotReactComponent<TProps>, testId: string): RenderedElementNode<TProps>;
|
|
345
|
+
/**
|
|
346
|
+
* Finds the first descendant element node that matches the given component and test ID. If no match is found, `null` is returned.
|
|
347
|
+
*
|
|
348
|
+
* @param component The component to find.
|
|
349
|
+
* @param testId The test ID to find.
|
|
350
|
+
* @returns The first element node that matches the given component and test ID or `null` if no match is found.
|
|
351
|
+
*/
|
|
352
|
+
maybeFindByTestId<TProps extends UnknownComponentProps>(component: HubSpotReactComponent<TProps>, testId: string): RenderedElementNode<TProps> | null;
|
|
239
353
|
}
|
|
354
|
+
/**
|
|
355
|
+
* Represents one of the four supported node types that include element, root, fragment, and text nodes.
|
|
356
|
+
*/
|
|
240
357
|
export type RenderedNode = RenderedElementNode<any> | RenderedRootNode | RenderedFragmentNode | RenderedTextNode;
|
|
241
358
|
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type HubSpotReactComponent, type UnknownComponentProps } from '../../shared/types/shared.ts';
|
|
2
|
+
import { type ElementMatcher, type RenderedElementNode, type RenderedNode } from './types.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Checks if the node matches the component and matcher.
|
|
5
|
+
*
|
|
6
|
+
* @param node The node to check.
|
|
7
|
+
* @param component The component to check.
|
|
8
|
+
* @param matcher An optional matcher to filter the elements.
|
|
9
|
+
* @returns Whether the node matches the component and matcher.
|
|
10
|
+
*/
|
|
11
|
+
export declare const isMatch: <TComponentProps extends UnknownComponentProps>(node: RenderedNode | null | undefined, component: HubSpotReactComponent<TComponentProps>, matcher?: ElementMatcher<TComponentProps>) => node is RenderedElementNode<TComponentProps>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { RenderedNodeType, } from "./types.js";
|
|
2
|
+
import { __hubSpotComponentRegistry } from "../../shared/remoteComponents.js";
|
|
3
|
+
import { checkElementMatches } from "./internal/match.js";
|
|
4
|
+
/**
|
|
5
|
+
* Checks if the node matches the component and matcher.
|
|
6
|
+
*
|
|
7
|
+
* @param node The node to check.
|
|
8
|
+
* @param component The component to check.
|
|
9
|
+
* @param matcher An optional matcher to filter the elements.
|
|
10
|
+
* @returns Whether the node matches the component and matcher.
|
|
11
|
+
*/
|
|
12
|
+
export const isMatch = (node, component, matcher) => {
|
|
13
|
+
if (node == null) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
if (node.nodeType !== RenderedNodeType.Element) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
const targetComponentName = __hubSpotComponentRegistry.getComponentName(component);
|
|
20
|
+
if (node.name !== targetComponentName) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return checkElementMatches(node, matcher);
|
|
24
|
+
};
|
package/dist/hubspot.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { ExtensionPoints, ExtensionPointApi, ServerlessRunnerParams, HubSpotFetchRequestURI, HubSpotFetchOptions } from './__synced__/types/index.synced';
|
|
3
|
-
export declare function extend_V2<ExtensionPointName extends keyof ExtensionPoints>(renderExtensionCallback: (api: ExtensionPointApi<ExtensionPointName>) => ReactElement<any>): any;
|
|
1
|
+
import type { HubSpotFetchOptions, HubSpotFetchRequestURI, ServerlessRunnerParams } from './shared/types/index.ts';
|
|
4
2
|
export declare function serverless<T = any>(name: ServerlessRunnerParams['name'], options?: Omit<ServerlessRunnerParams, 'name'>): Promise<T>;
|
|
5
3
|
export declare function fetch(url: HubSpotFetchRequestURI, options?: HubSpotFetchOptions): Promise<Response>;
|
|
6
4
|
export declare const hubspot: {
|
|
7
|
-
extend:
|
|
5
|
+
extend: import("./shared/types/extend.ts").HubspotExtendFunction;
|
|
8
6
|
serverless: typeof serverless;
|
|
9
7
|
fetch: typeof fetch;
|
|
10
8
|
};
|
package/dist/hubspot.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/* eslint-disable hubspot-dev/no-confusing-browser-globals */
|
|
2
|
+
import { getWorkerGlobals } from "./internal/global-utils.js";
|
|
3
|
+
const extend_V2 = getWorkerGlobals().extend_V2;
|
|
4
4
|
export function serverless(name, options) {
|
|
5
5
|
return self.serverless(name, options);
|
|
6
6
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import './clientTypes';
|
|
2
|
-
export { hubspot } from './hubspot';
|
|
3
|
-
export { logger } from './logger';
|
|
4
|
-
export * from './
|
|
5
|
-
export { Accordion, Alert, AutoGrid, BarChart, Box, Button, ButtonRow, Card, Checkbox, CurrencyInput, DateInput, DescriptionList, DescriptionListItem, Divider, Dropdown, EmptyState, ErrorState, Flex, Form, Heading, Icon, Illustration, Image, Inline, Input, LineChart, Link, List, LoadingButton, LoadingSpinner, Modal, ModalBody, ModalFooter, MultiSelect, NumberInput, Panel, PanelBody, PanelFooter, PanelSection, ProgressBar, RadioButton, SearchInput, Select, Stack, Statistics, StatisticsItem, StatisticsTrend, StatusTag, StepIndicator, StepperInput, Tab, Table, TableBody, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, Tag, Text, TextArea, Textarea, Tile, TimeInput, Toggle, ToggleGroup, Tooltip, } from './
|
|
1
|
+
import './clientTypes.ts';
|
|
2
|
+
export { hubspot } from './hubspot.ts';
|
|
3
|
+
export { logger } from './logger.ts';
|
|
4
|
+
export * from './shared/types/index.ts';
|
|
5
|
+
export { Accordion, Alert, AutoGrid, BarChart, Box, Button, ButtonRow, Card, Checkbox, CurrencyInput, DateInput, DescriptionList, DescriptionListItem, Divider, Dropdown, EmptyState, ErrorState, Flex, Form, Heading, Icon, Illustration, Image, Inline, Input, LineChart, Link, List, LoadingButton, LoadingSpinner, Modal, ModalBody, ModalFooter, MultiSelect, NumberInput, Panel, PanelBody, PanelFooter, PanelSection, ProgressBar, RadioButton, SearchInput, Select, Stack, Statistics, StatisticsItem, StatisticsTrend, StatusTag, StepIndicator, StepperInput, Tab, Table, TableBody, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, Tag, Text, TextArea, Textarea, Tile, TimeInput, Toggle, ToggleGroup, Tooltip, } from './shared/remoteComponents.tsx';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// In order to easily fix [this issue](https://git.hubteam.com/HubSpot/ui-extensibility/issues/2587) we are temporarily importing a manually created subset of Vite client types. This should be removed once we have a proper solution for this issue.
|
|
2
|
-
import
|
|
3
|
-
export { hubspot } from
|
|
4
|
-
export { logger } from
|
|
5
|
-
export * from
|
|
6
|
-
export { Accordion, Alert, AutoGrid, BarChart, Box, Button, ButtonRow, Card, Checkbox, CurrencyInput, DateInput, DescriptionList, DescriptionListItem, Divider, Dropdown, EmptyState, ErrorState, Flex, Form, Heading, Icon, Illustration, Image, Inline, Input, LineChart, Link, List, LoadingButton, LoadingSpinner, Modal, ModalBody, ModalFooter, MultiSelect, NumberInput, Panel, PanelBody, PanelFooter, PanelSection, ProgressBar, RadioButton, SearchInput, Select, Stack, Statistics, StatisticsItem, StatisticsTrend, StatusTag, StepIndicator, StepperInput, Tab, Table, TableBody, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, Tag, Text, TextArea, Textarea, Tile, TimeInput, Toggle, ToggleGroup, Tooltip, } from
|
|
2
|
+
import "./clientTypes.js";
|
|
3
|
+
export { hubspot } from "./hubspot.js";
|
|
4
|
+
export { logger } from "./logger.js";
|
|
5
|
+
export * from "./shared/types/index.js";
|
|
6
|
+
export { Accordion, Alert, AutoGrid, BarChart, Box, Button, ButtonRow, Card, Checkbox, CurrencyInput, DateInput, DescriptionList, DescriptionListItem, Divider, Dropdown, EmptyState, ErrorState, Flex, Form, Heading, Icon, Illustration, Image, Inline, Input, LineChart, Link, List, LoadingButton, LoadingSpinner, Modal, ModalBody, ModalFooter, MultiSelect, NumberInput, Panel, PanelBody, PanelFooter, PanelSection, ProgressBar, RadioButton, SearchInput, Select, Stack, Statistics, StatisticsItem, StatisticsTrend, StatusTag, StepIndicator, StepperInput, Tab, Table, TableBody, TableCell, TableFooter, TableHead, TableHeader, TableRow, Tabs, Tag, Text, TextArea, Textarea, Tile, TimeInput, Toggle, ToggleGroup, Tooltip, } from "./shared/remoteComponents.js";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the current environment is a HubSpot extension worker.
|
|
3
|
+
* @returns True if the current environment is a HubSpot extension worker.
|
|
4
|
+
*/
|
|
5
|
+
const isRunningInWorker = () => typeof self !== 'undefined' &&
|
|
6
|
+
self.__HUBSPOT_EXTENSION_WORKER__ === true;
|
|
7
|
+
/**
|
|
8
|
+
* A fake worker globals object for use in test environments.
|
|
9
|
+
*/
|
|
10
|
+
const fakeWorkerGlobals = {
|
|
11
|
+
logger: {
|
|
12
|
+
debug: (data) => {
|
|
13
|
+
console.log(data);
|
|
14
|
+
},
|
|
15
|
+
info: (data) => {
|
|
16
|
+
console.info(data);
|
|
17
|
+
},
|
|
18
|
+
warn: (data) => {
|
|
19
|
+
console.warn(data);
|
|
20
|
+
},
|
|
21
|
+
error: (data) => {
|
|
22
|
+
console.error(data);
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
extend_V2: () => {
|
|
26
|
+
// No-op in test environment
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Gets the worker globals object for the current environment.
|
|
31
|
+
* @returns The worker globals object.
|
|
32
|
+
*/
|
|
33
|
+
export const getWorkerGlobals = () => {
|
|
34
|
+
return isRunningInWorker()
|
|
35
|
+
? self
|
|
36
|
+
: fakeWorkerGlobals;
|
|
37
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { RendererMocksInternal } from '../experimental/testing/internal/types-internal.ts';
|
|
2
|
+
type AnyFunction = (...args: any[]) => any;
|
|
3
|
+
/**
|
|
4
|
+
* Creates a mock-aware hook function that can be used to mock the original hook function.
|
|
5
|
+
* The mock-aware hook function will return the mocked hook function if a mock is found, otherwise it will return the original hook function.
|
|
6
|
+
*
|
|
7
|
+
* @param hookName The name of the hook to mock that corresponds to the key in the Mocks interface
|
|
8
|
+
* @param originalHookFunction The original hook function to call if no mock is found
|
|
9
|
+
* @returns The mocked hook function or the original hook function if no mock is found
|
|
10
|
+
*/
|
|
11
|
+
export declare const createMockAwareHook: <THookName extends keyof RendererMocksInternal, THookFunction extends AnyFunction>(hookName: THookName, originalHookFunction: THookFunction) => THookFunction;
|
|
12
|
+
/**
|
|
13
|
+
* A React component that provides the Mocks context that can be used to provide mocks to the mock-aware hook functions.
|
|
14
|
+
*
|
|
15
|
+
* @param children The children to render.
|
|
16
|
+
* @returns The children wrapped in the Mocks context provider.
|
|
17
|
+
*/
|
|
18
|
+
export declare const MocksContextProvider: import("react").Provider<RendererMocksInternal | null>;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
const MocksContext = createContext(null);
|
|
3
|
+
/**
|
|
4
|
+
* Creates a mock-aware hook function that can be used to mock the original hook function.
|
|
5
|
+
* The mock-aware hook function will return the mocked hook function if a mock is found, otherwise it will return the original hook function.
|
|
6
|
+
*
|
|
7
|
+
* @param hookName The name of the hook to mock that corresponds to the key in the Mocks interface
|
|
8
|
+
* @param originalHookFunction The original hook function to call if no mock is found
|
|
9
|
+
* @returns The mocked hook function or the original hook function if no mock is found
|
|
10
|
+
*/
|
|
11
|
+
export const createMockAwareHook = (hookName, originalHookFunction) => {
|
|
12
|
+
const useWrapper = (...args) => {
|
|
13
|
+
const mocks = useContext(MocksContext);
|
|
14
|
+
if (!mocks) {
|
|
15
|
+
// If no mocks are provided, call the original hook function
|
|
16
|
+
return originalHookFunction(...args);
|
|
17
|
+
}
|
|
18
|
+
// When a mock is provided by the testing utilities (via <MocksContextProvider>), return the mocked hook function
|
|
19
|
+
const mockHook = mocks[hookName];
|
|
20
|
+
if (!mockHook) {
|
|
21
|
+
throw new Error(`Illegal State: Mock for hook ${hookName} not found.`);
|
|
22
|
+
}
|
|
23
|
+
// Call the mocked hook function with the same arguments as the original hook function and return the result
|
|
24
|
+
return mockHook(...args);
|
|
25
|
+
};
|
|
26
|
+
return useWrapper;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* A React component that provides the Mocks context that can be used to provide mocks to the mock-aware hook functions.
|
|
30
|
+
*
|
|
31
|
+
* @param children The children to render.
|
|
32
|
+
* @returns The children wrapped in the Mocks context provider.
|
|
33
|
+
*/
|
|
34
|
+
export const MocksContextProvider = MocksContext.Provider;
|
package/dist/logger.d.ts
CHANGED
|
@@ -1,8 +1 @@
|
|
|
1
|
-
|
|
2
|
-
debug: (value: string) => void;
|
|
3
|
-
info: (value: string) => void;
|
|
4
|
-
warn: (value: string) => void;
|
|
5
|
-
error: (value: string) => void;
|
|
6
|
-
}
|
|
7
|
-
export declare const logger: Logger;
|
|
8
|
-
export {};
|
|
1
|
+
export declare const logger: import("./shared/types/logger.ts").Logger;
|
package/dist/logger.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { getWorkerGlobals } from "./internal/global-utils.js";
|
|
2
|
+
const workerGlobals = getWorkerGlobals();
|
|
3
|
+
export const logger = workerGlobals.logger;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { HeaderActions, PrimaryHeaderActionButton, SecondaryHeaderActionButton, } from '../../
|
|
1
|
+
export { HeaderActions, PrimaryHeaderActionButton, SecondaryHeaderActionButton, } from '../../shared/remoteComponents.tsx';
|
package/dist/pages/home/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { HeaderActions, PrimaryHeaderActionButton, SecondaryHeaderActionButton, } from
|
|
1
|
+
export { HeaderActions, PrimaryHeaderActionButton, SecondaryHeaderActionButton, } from "../../shared/remoteComponents.js";
|