@hubspot/ui-extensions 0.11.4 → 0.11.6
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 +96 -0
- package/dist/__tests__/crm/hooks/useCrmProperties.spec.js +170 -1
- package/dist/crm/hooks/useAssociations.d.ts +2 -0
- package/dist/crm/hooks/useAssociations.js +87 -0
- package/dist/crm/hooks/useCrmProperties.d.ts +5 -1
- package/dist/crm/hooks/useCrmProperties.js +81 -2
- package/dist/hooks/useExtensionActions.d.ts +4 -0
- package/dist/hooks/useExtensionActions.js +6 -0
- package/dist/hooks/useExtensionContext.d.ts +4 -0
- package/dist/hooks/useExtensionContext.js +6 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/internal/global-utils.js +4 -0
- package/dist/internal/hook-utils.d.ts +10 -3
- package/dist/internal/hook-utils.js +10 -1
- package/dist/shared/types/components/accordion.d.ts +5 -5
- package/dist/shared/types/components/alert.d.ts +2 -2
- package/dist/shared/types/components/button-row.d.ts +5 -2
- package/dist/shared/types/components/button.d.ts +16 -10
- package/dist/shared/types/components/chart.d.ts +3 -3
- package/dist/shared/types/components/description-list.d.ts +2 -2
- package/dist/shared/types/components/dropdown.d.ts +8 -8
- package/dist/shared/types/components/empty-state.d.ts +5 -7
- package/dist/shared/types/components/error-state.d.ts +2 -2
- package/dist/shared/types/components/form.d.ts +2 -2
- package/dist/shared/types/components/heading.d.ts +1 -1
- package/dist/shared/types/components/icon.d.ts +4 -5
- package/dist/shared/types/components/illustration.d.ts +12 -0
- package/dist/shared/types/components/image.d.ts +9 -4
- package/dist/shared/types/components/inputs.d.ts +51 -64
- package/dist/shared/types/components/layouts.d.ts +17 -24
- package/dist/shared/types/components/link.d.ts +8 -5
- package/dist/shared/types/components/loading-spinner.d.ts +3 -3
- package/dist/shared/types/components/modal.d.ts +5 -5
- package/dist/shared/types/components/panel.d.ts +7 -7
- package/dist/shared/types/components/progress-bar.d.ts +4 -4
- package/dist/shared/types/components/selects.d.ts +11 -20
- package/dist/shared/types/components/statistics.d.ts +2 -2
- package/dist/shared/types/components/status-tag.d.ts +5 -5
- package/dist/shared/types/components/step-indicator.d.ts +5 -7
- package/dist/shared/types/components/table.d.ts +22 -12
- package/dist/shared/types/components/tabs.d.ts +10 -10
- package/dist/shared/types/components/tag.d.ts +2 -2
- package/dist/shared/types/components/text.d.ts +15 -21
- package/dist/shared/types/components/tile.d.ts +2 -2
- package/dist/shared/types/components/toggle.d.ts +12 -14
- package/dist/shared/types/components/toggleInputs.d.ts +26 -19
- package/dist/shared/types/components/tooltip.d.ts +1 -1
- package/dist/shared/types/crm.d.ts +52 -0
- package/dist/shared/types/http-requests.d.ts +2 -2
- package/dist/shared/types/shared.d.ts +123 -78
- package/dist/shared/types/shared.js +123 -78
- package/dist/shared/types/worker-globals.d.ts +15 -0
- package/dist/{experimental/testing → testing}/__tests__/debug.spec.js +1 -1
- package/dist/{experimental/testing → testing}/__tests__/find.spec.js +1 -1
- package/dist/{experimental/testing → testing}/__tests__/findAll.spec.js +1 -1
- package/dist/{experimental/testing → testing}/__tests__/findAllChildren.spec.js +1 -1
- package/dist/{experimental/testing → testing}/__tests__/findByTestId.spec.js +1 -1
- package/dist/{experimental/testing → testing}/__tests__/findChild.spec.js +1 -1
- package/dist/{experimental/testing → testing}/__tests__/fragments.spec.js +1 -1
- package/dist/{experimental/testing → testing}/__tests__/invalid-components.spec.js +1 -1
- package/dist/{experimental/testing → testing}/__tests__/isMatch.spec.js +1 -1
- package/dist/{experimental/testing → testing}/__tests__/logger.spec.js +1 -1
- package/dist/{experimental/testing → testing}/__tests__/maybeFind.spec.js +1 -1
- package/dist/{experimental/testing → testing}/__tests__/maybeFindByTestId.spec.js +1 -1
- package/dist/{experimental/testing → testing}/__tests__/maybeFindChild.spec.js +1 -1
- package/dist/{experimental/testing → testing}/__tests__/mocks.runServerlessFunction.spec.js +1 -1
- package/dist/testing/__tests__/mocks.useAssociations.spec.js +135 -0
- package/dist/testing/__tests__/mocks.useCrmProperties.spec.js +106 -0
- package/dist/testing/__tests__/mocks.useExtensionActions.spec.js +32 -0
- package/dist/testing/__tests__/mocks.useExtensionContext.spec.js +46 -0
- package/dist/{experimental/testing → testing}/__tests__/props.spec.js +1 -1
- package/dist/{experimental/testing → testing}/__tests__/testId.spec.js +1 -1
- package/dist/{experimental/testing → testing}/__tests__/trigger.spec.js +1 -1
- package/dist/{experimental/testing → testing}/__tests__/type-utils.spec.js +1 -1
- package/dist/testing/__tests__/waitFor.spec.d.ts +1 -0
- package/dist/{experimental/testing → testing}/__tests__/waitFor.spec.js +1 -1
- package/dist/{experimental/testing → testing}/internal/convert.js +1 -1
- package/dist/{experimental/testing → testing}/internal/element.d.ts +1 -1
- package/dist/{experimental/testing → testing}/internal/errors.js +1 -1
- package/dist/{experimental/testing → testing}/internal/match.d.ts +1 -1
- package/dist/{experimental/testing → testing}/internal/mocks/index.d.ts +1 -1
- package/dist/{experimental/testing → testing}/internal/mocks/mock-extension-point-api.d.ts +1 -1
- package/dist/{experimental/testing → testing}/internal/mocks/mock-extension-point-api.js +1 -1
- package/dist/testing/internal/mocks/mock-hooks.d.ts +3 -0
- package/dist/{experimental/testing → testing}/internal/mocks/mock-hooks.js +14 -0
- package/dist/{experimental/testing → testing}/internal/print.js +1 -1
- package/dist/{experimental/testing → testing}/internal/query.d.ts +1 -1
- package/dist/{experimental/testing → testing}/internal/query.js +1 -1
- package/dist/{experimental/testing → testing}/internal/types-internal.d.ts +7 -3
- package/dist/testing/internal/types-internal.js +1 -0
- package/dist/{experimental/testing → testing}/render.d.ts +1 -1
- package/dist/{experimental/testing → testing}/render.js +7 -7
- package/dist/{experimental/testing → testing}/types.d.ts +25 -5
- package/dist/{experimental/testing → testing}/utils.d.ts +1 -1
- package/dist/{experimental/testing → testing}/utils.js +1 -1
- package/package.json +3 -3
- package/dist/experimental/testing/__tests__/mocks.useAssociations.spec.js +0 -47
- package/dist/experimental/testing/__tests__/mocks.useCrmProperties.spec.js +0 -58
- package/dist/experimental/testing/internal/mocks/mock-hooks.d.ts +0 -2
- /package/dist/{experimental/testing → testing}/__tests__/createRenderer.spec.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/__tests__/createRenderer.spec.js +0 -0
- /package/dist/{experimental/testing → testing}/__tests__/debug.spec.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/__tests__/find.spec.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/__tests__/findAll.spec.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/__tests__/findAllChildren.spec.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/__tests__/findByTestId.spec.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/__tests__/findChild.spec.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/__tests__/fragments.spec.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/__tests__/invalid-components.spec.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/__tests__/isMatch.spec.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/__tests__/logger.spec.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/__tests__/maybeFind.spec.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/__tests__/maybeFindByTestId.spec.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/__tests__/maybeFindChild.spec.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/__tests__/mocks.actions.spec.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/__tests__/mocks.actions.spec.js +0 -0
- /package/dist/{experimental/testing → testing}/__tests__/mocks.context.spec.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/__tests__/mocks.context.spec.js +0 -0
- /package/dist/{experimental/testing → testing}/__tests__/mocks.runServerlessFunction.spec.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/__tests__/mocks.useAssociations.spec.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/__tests__/mocks.useCrmProperties.spec.d.ts +0 -0
- /package/dist/{experimental/testing/__tests__/props.spec.d.ts → testing/__tests__/mocks.useExtensionActions.spec.d.ts} +0 -0
- /package/dist/{experimental/testing/__tests__/testId.spec.d.ts → testing/__tests__/mocks.useExtensionContext.spec.d.ts} +0 -0
- /package/dist/{experimental/testing/__tests__/trigger.spec.d.ts → testing/__tests__/props.spec.d.ts} +0 -0
- /package/dist/{experimental/testing/__tests__/type-utils.spec.d.ts → testing/__tests__/testId.spec.d.ts} +0 -0
- /package/dist/{experimental/testing/__tests__/waitFor.spec.d.ts → testing/__tests__/trigger.spec.d.ts} +0 -0
- /package/dist/{experimental/testing/internal/types-internal.js → testing/__tests__/type-utils.spec.d.ts} +0 -0
- /package/dist/{experimental/testing → testing}/index.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/index.js +0 -0
- /package/dist/{experimental/testing → testing}/internal/constants.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/internal/constants.js +0 -0
- /package/dist/{experimental/testing → testing}/internal/convert.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/internal/debug.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/internal/debug.js +0 -0
- /package/dist/{experimental/testing → testing}/internal/document.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/internal/document.js +0 -0
- /package/dist/{experimental/testing → testing}/internal/element.js +0 -0
- /package/dist/{experimental/testing → testing}/internal/errors.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/internal/fragment.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/internal/fragment.js +0 -0
- /package/dist/{experimental/testing → testing}/internal/match.js +0 -0
- /package/dist/{experimental/testing → testing}/internal/mocks/index.js +0 -0
- /package/dist/{experimental/testing → testing}/internal/print.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/internal/root.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/internal/root.js +0 -0
- /package/dist/{experimental/testing → testing}/internal/text.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/internal/text.js +0 -0
- /package/dist/{experimental/testing → testing}/internal/type-utils-internal.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/internal/type-utils-internal.js +0 -0
- /package/dist/{experimental/testing → testing}/internal/utils/promise-utils.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/internal/utils/promise-utils.js +0 -0
- /package/dist/{experimental/testing → testing}/type-utils.d.ts +0 -0
- /package/dist/{experimental/testing → testing}/type-utils.js +0 -0
- /package/dist/{experimental/testing → testing}/types.js +0 -0
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { RemoteComponent, RemoteFragment, RemoteRoot, RemoteText } from '@remote-ui/core';
|
|
2
|
-
import { ExtensionPointApi, ExtensionPointLocation } from '
|
|
3
|
-
import { HubSpotReactComponent, UnknownComponentProps } from '
|
|
4
|
-
import { useAssociations, useCrmProperties } from '
|
|
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 { useExtensionContext } from '../../hooks/useExtensionContext.tsx';
|
|
6
|
+
import { useExtensionActions } from '../../hooks/useExtensionActions.tsx';
|
|
5
7
|
import type { ElementMatcher, RenderedElementNode, RenderedFragmentNode, RenderedNode, RenderedParentNode, RenderedRootNode, RenderedTextNode } from '../types.ts';
|
|
6
8
|
export type RemoteChildNode = RemoteComponent<any, RemoteRoot> | RemoteText<RemoteRoot>;
|
|
7
9
|
export type RemoteParentNode = RemoteRoot | RemoteComponent<any, RemoteRoot> | RemoteFragment;
|
|
@@ -59,6 +61,8 @@ export type RenderedNodeInternal = RenderedElementNodeInternal | RenderedTextNod
|
|
|
59
61
|
export interface RendererMockHooksInternal {
|
|
60
62
|
useCrmProperties: typeof useCrmProperties;
|
|
61
63
|
useAssociations: typeof useAssociations;
|
|
64
|
+
useExtensionContext: typeof useExtensionContext;
|
|
65
|
+
useExtensionActions: typeof useExtensionActions;
|
|
62
66
|
}
|
|
63
67
|
export type RendererMocksInternal<TExtensionPointLocationName extends ExtensionPointLocation = ExtensionPointLocation> = RendererMockHooksInternal & ExtensionPointApi<TExtensionPointLocationName>;
|
|
64
68
|
export type AnyFunction = (...args: any[]) => any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ExtensionPointLocation } from '
|
|
1
|
+
import { ExtensionPointLocation } from '../shared/types/extension-points.ts';
|
|
2
2
|
import { Renderer } from './types.ts';
|
|
3
3
|
/**
|
|
4
4
|
* Creates a renderer object with methods for rendering and testing UI extension components.
|
|
@@ -4,8 +4,8 @@ import { createRoot as createReactRoot } from '@remote-ui/react';
|
|
|
4
4
|
import { convertRemoteRoot } from "./internal/convert.js";
|
|
5
5
|
import { createDocument } from "./internal/document.js";
|
|
6
6
|
import { InvalidComponentsError, InvalidExtensionPointLocationError, WaitForTimeoutError, } from "./internal/errors.js";
|
|
7
|
-
import { EXTENSION_POINT_LOCATIONS, } from "
|
|
8
|
-
import { MocksContextProvider } from "
|
|
7
|
+
import { EXTENSION_POINT_LOCATIONS, } from "../shared/types/extension-points.js";
|
|
8
|
+
import { MocksContextProvider } from "../internal/hook-utils.js";
|
|
9
9
|
import { createMocksWithSpies } from "./internal/mocks/index.js";
|
|
10
10
|
import { find, findAll, findAllChildren, findByTestId, findChild, maybeFind, maybeFindByTestId, maybeFindChild, } from "./internal/query.js";
|
|
11
11
|
import { createRootNode } from "./internal/root.js";
|
|
@@ -21,7 +21,7 @@ const DEFAULT_WAIT_FOR_OPTIONS = {
|
|
|
21
21
|
* @param node The React node to render.
|
|
22
22
|
* @returns A render result object
|
|
23
23
|
*/
|
|
24
|
-
const render = (node,
|
|
24
|
+
const render = (node, mocksWithSpies) => {
|
|
25
25
|
let dirty = true;
|
|
26
26
|
let waitForChecksQueued = false;
|
|
27
27
|
let waitForList = [];
|
|
@@ -75,7 +75,7 @@ const render = (node, mocks) => {
|
|
|
75
75
|
};
|
|
76
76
|
const remoteRoot = createRemoteRoot(remoteChannel);
|
|
77
77
|
const reactRoot = createReactRoot(remoteRoot);
|
|
78
|
-
reactRoot.render(_jsx(MocksContextProvider, { value:
|
|
78
|
+
reactRoot.render(_jsx(MocksContextProvider, { value: mocksWithSpies, children: node }));
|
|
79
79
|
remoteRoot.mount();
|
|
80
80
|
let maybeRenderedRootNode;
|
|
81
81
|
/**
|
|
@@ -175,13 +175,13 @@ export const createRenderer = (extensionPointLocation) => {
|
|
|
175
175
|
return renderResult;
|
|
176
176
|
};
|
|
177
177
|
const getLatestRootNode = () => getRenderResult().getLatestRootNode();
|
|
178
|
-
const {
|
|
178
|
+
const { spies: mocksWithSpies } = createMocksWithSpies(extensionPointLocation);
|
|
179
179
|
return {
|
|
180
180
|
render: (node) => {
|
|
181
|
-
renderResult = render(node,
|
|
181
|
+
renderResult = render(node, mocksWithSpies);
|
|
182
182
|
return asRenderedRootNode(renderResult.getLatestRootNode());
|
|
183
183
|
},
|
|
184
|
-
mocks:
|
|
184
|
+
mocks: mocksWithSpies,
|
|
185
185
|
find: (component, matcher) => {
|
|
186
186
|
return find(getLatestRootNode(), component, matcher);
|
|
187
187
|
},
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { ExtensionPointApi, ExtensionPointApiActions, ExtensionPointLocation } from '
|
|
2
|
-
import { ServerlessFuncRunner } from '
|
|
1
|
+
import { ExtensionPointApi, ExtensionPointApiActions, ExtensionPointLocation } from '../shared/types/extension-points.ts';
|
|
2
|
+
import { ServerlessFuncRunner } from '../shared/types/http-requests.ts';
|
|
3
3
|
import { SpyImpl } from 'tinyspy';
|
|
4
|
-
import { HubSpotReactComponent, HubSpotReactFragmentProp, UnknownComponentProps } from '
|
|
5
|
-
import { useAssociations, useCrmProperties } from '
|
|
4
|
+
import { HubSpotReactComponent, HubSpotReactFragmentProp, UnknownComponentProps } from '../shared/types/shared.ts';
|
|
5
|
+
import { useAssociations, useCrmProperties } from '../crm/index.ts';
|
|
6
|
+
import { useExtensionContext } from '../hooks/useExtensionContext.tsx';
|
|
6
7
|
import { AnyFunction } from './internal/types-internal.ts';
|
|
8
|
+
import { useExtensionActions } from '../hooks/useExtensionActions.tsx';
|
|
7
9
|
/**
|
|
8
10
|
* The type of a rendered node.
|
|
9
11
|
*/
|
|
@@ -258,7 +260,7 @@ export type ExtensionPointApiActionSpies<TExtensionPointLocation extends Extensi
|
|
|
258
260
|
/**
|
|
259
261
|
* An object containing the spies for the various functions.
|
|
260
262
|
*/
|
|
261
|
-
export interface RendererSpies<TExtensionPointLocation extends ExtensionPointLocation> {
|
|
263
|
+
export interface RendererSpies<TExtensionPointLocation extends ExtensionPointLocation = ExtensionPointLocation> {
|
|
262
264
|
/**
|
|
263
265
|
* A spy for the `useCrmProperties` hook function.
|
|
264
266
|
* The spy can be used to track the calls to the hook function and also control the
|
|
@@ -277,6 +279,24 @@ export interface RendererSpies<TExtensionPointLocation extends ExtensionPointLoc
|
|
|
277
279
|
* information about spies and the supported API.
|
|
278
280
|
*/
|
|
279
281
|
useAssociations: FunctionSpy<typeof useAssociations>;
|
|
282
|
+
/**
|
|
283
|
+
* A spy for the `useExtensionContext` hook function.
|
|
284
|
+
* The spy can be used to track the calls to the hook function and also control the
|
|
285
|
+
* return result of the hook function.
|
|
286
|
+
*
|
|
287
|
+
* See the [tinyspy](https://github.com/tiny-spy/tinyspy) library for more
|
|
288
|
+
* information about spies and the supported API.
|
|
289
|
+
*/
|
|
290
|
+
useExtensionContext: FunctionSpy<typeof useExtensionContext>;
|
|
291
|
+
/**
|
|
292
|
+
* A spy for the `useExtensionActions` hook function.
|
|
293
|
+
* The spy can be used to track the calls to the hook function and also control the
|
|
294
|
+
* return result of the hook function.
|
|
295
|
+
*
|
|
296
|
+
* See the [tinyspy](https://github.com/tiny-spy/tinyspy) library for more
|
|
297
|
+
* information about spies and the supported API.
|
|
298
|
+
*/
|
|
299
|
+
useExtensionActions: FunctionSpy<typeof useExtensionActions>;
|
|
280
300
|
/**
|
|
281
301
|
* Mock context object that contains fake context data for the extension point API.
|
|
282
302
|
*/
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type HubSpotReactComponent, type UnknownComponentProps } from '
|
|
1
|
+
import { type HubSpotReactComponent, type UnknownComponentProps } from '../shared/types/shared.ts';
|
|
2
2
|
import { type ElementMatcher, type RenderedElementNode, type RenderedNode } from './types.ts';
|
|
3
3
|
/**
|
|
4
4
|
* Checks if the node matches the component and matcher.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RenderedNodeType, } from "./types.js";
|
|
2
|
-
import { __hubSpotComponentRegistry } from "
|
|
2
|
+
import { __hubSpotComponentRegistry } from "../shared/remoteComponents.js";
|
|
3
3
|
import { checkElementMatches } from "./internal/match.js";
|
|
4
4
|
/**
|
|
5
5
|
* Checks if the node matches the component and matcher.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hubspot/ui-extensions",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"./crm": "./dist/crm/index.js",
|
|
29
29
|
"./pages/home": "./dist/pages/home/index.js",
|
|
30
30
|
"./experimental": "./dist/experimental/index.js",
|
|
31
|
-
"./
|
|
31
|
+
"./testing": "./dist/testing/index.js"
|
|
32
32
|
},
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
"tsd": {
|
|
75
75
|
"directory": "src/__tests__/test-d"
|
|
76
76
|
},
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "12a14abf6ad776b12204dc37467a7c665a806adb"
|
|
78
78
|
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { describe, expect, it } from 'vitest';
|
|
3
|
-
import { Text } from "../../../index.js";
|
|
4
|
-
import { createRenderer } from "../index.js";
|
|
5
|
-
import { useAssociations } from "../../../crm/index.js";
|
|
6
|
-
function MyComponent() {
|
|
7
|
-
const { results, isLoading, error } = useAssociations({
|
|
8
|
-
toObjectType: '0-1',
|
|
9
|
-
properties: ['firstname', 'lastname'],
|
|
10
|
-
pageLength: 10,
|
|
11
|
-
});
|
|
12
|
-
if (isLoading) {
|
|
13
|
-
return _jsx(Text, { children: "Loading..." });
|
|
14
|
-
}
|
|
15
|
-
if (error) {
|
|
16
|
-
return _jsx(Text, { children: "Something went wrong!" });
|
|
17
|
-
}
|
|
18
|
-
return (_jsx(_Fragment, { children: results.map((result) => (_jsxs(Text, { children: [result.properties.firstname, " ", result.properties.lastname] }, result.toObjectId))) }));
|
|
19
|
-
}
|
|
20
|
-
describe('mock useAssociations', () => {
|
|
21
|
-
it('should provide a default mock implementation', () => {
|
|
22
|
-
const { render } = createRenderer('crm.record.tab');
|
|
23
|
-
const { findAll } = render(_jsx(MyComponent, {}));
|
|
24
|
-
const textNodes = findAll(Text);
|
|
25
|
-
expect(textNodes.length).toEqual(1);
|
|
26
|
-
expect(textNodes[0].text).toEqual('fake_firstname fake_lastname');
|
|
27
|
-
});
|
|
28
|
-
it('should allow mocking the next function result', () => {
|
|
29
|
-
const { render, mocks } = createRenderer('crm.record.tab');
|
|
30
|
-
mocks.useAssociations.nextResult({
|
|
31
|
-
results: [],
|
|
32
|
-
error: new Error('Something went wrong!'),
|
|
33
|
-
isLoading: false,
|
|
34
|
-
pagination: {
|
|
35
|
-
hasNextPage: false,
|
|
36
|
-
hasPreviousPage: false,
|
|
37
|
-
currentPage: 1,
|
|
38
|
-
pageSize: 10,
|
|
39
|
-
nextPage: () => { },
|
|
40
|
-
previousPage: () => { },
|
|
41
|
-
reset: () => { },
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
const { find } = render(_jsx(MyComponent, {}));
|
|
45
|
-
expect(find(Text).text).toEqual('Something went wrong!');
|
|
46
|
-
});
|
|
47
|
-
});
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { describe, expect, it } from 'vitest';
|
|
3
|
-
import { Text } from "../../../index.js";
|
|
4
|
-
import { createRenderer } from "../index.js";
|
|
5
|
-
import { useCrmProperties } from "../../../crm/index.js";
|
|
6
|
-
function MyComponent() {
|
|
7
|
-
const { properties, isLoading, error } = useCrmProperties([
|
|
8
|
-
'firstname',
|
|
9
|
-
'lastname',
|
|
10
|
-
]);
|
|
11
|
-
if (isLoading) {
|
|
12
|
-
return _jsx(Text, { children: "Loading..." });
|
|
13
|
-
}
|
|
14
|
-
if (error) {
|
|
15
|
-
return _jsx(Text, { children: "Something went wrong!" });
|
|
16
|
-
}
|
|
17
|
-
return (_jsxs(_Fragment, { children: [_jsxs(Text, { children: ["First name: ", properties.firstname] }), _jsxs(Text, { children: ["Last name: ", properties.lastname] })] }));
|
|
18
|
-
}
|
|
19
|
-
describe('mock useCrmProperties', () => {
|
|
20
|
-
it('should provide a default mock implementation', () => {
|
|
21
|
-
const { render } = createRenderer('crm.record.tab');
|
|
22
|
-
const { findAll } = render(_jsx(MyComponent, {}));
|
|
23
|
-
const textNodes = findAll(Text);
|
|
24
|
-
expect(textNodes.length).toEqual(2);
|
|
25
|
-
expect(textNodes[0].text).toEqual('First name: fake_firstname');
|
|
26
|
-
expect(textNodes[1].text).toEqual('Last name: fake_lastname');
|
|
27
|
-
});
|
|
28
|
-
it('should allow mocking the next function result', () => {
|
|
29
|
-
const { render, mocks } = createRenderer('crm.record.tab');
|
|
30
|
-
mocks.useCrmProperties.nextResult({
|
|
31
|
-
properties: {},
|
|
32
|
-
error: new Error('Something went wrong!'),
|
|
33
|
-
isLoading: false,
|
|
34
|
-
});
|
|
35
|
-
const { find } = render(_jsx(MyComponent, {}));
|
|
36
|
-
expect(find(Text).text).toEqual('Something went wrong!');
|
|
37
|
-
});
|
|
38
|
-
it('should allow providing a custom mock function', () => {
|
|
39
|
-
const { render, mocks, findAll } = createRenderer('crm.record.tab');
|
|
40
|
-
mocks.useCrmProperties.willCall((propertyNames) => {
|
|
41
|
-
const properties = propertyNames.reduce((acc, propertyName) => {
|
|
42
|
-
acc[propertyName] = propertyName.toUpperCase();
|
|
43
|
-
return acc;
|
|
44
|
-
}, {});
|
|
45
|
-
return {
|
|
46
|
-
properties,
|
|
47
|
-
error: null,
|
|
48
|
-
isLoading: false,
|
|
49
|
-
};
|
|
50
|
-
});
|
|
51
|
-
render(_jsx(MyComponent, {}));
|
|
52
|
-
const textNodes = findAll(Text);
|
|
53
|
-
const firstNameText = textNodes[0];
|
|
54
|
-
const lastNameText = textNodes[1];
|
|
55
|
-
expect(firstNameText.isMatch(Text) && firstNameText.text).toEqual('First name: FIRSTNAME');
|
|
56
|
-
expect(lastNameText.isMatch(Text) && lastNameText.text).toEqual('Last name: LASTNAME');
|
|
57
|
-
});
|
|
58
|
-
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/{experimental/testing → testing}/__tests__/mocks.runServerlessFunction.spec.d.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/{experimental/testing/__tests__/trigger.spec.d.ts → testing/__tests__/props.spec.d.ts}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|