@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.
Files changed (155) hide show
  1. package/dist/__tests__/crm/hooks/useAssociations.spec.js +96 -0
  2. package/dist/__tests__/crm/hooks/useCrmProperties.spec.js +170 -1
  3. package/dist/crm/hooks/useAssociations.d.ts +2 -0
  4. package/dist/crm/hooks/useAssociations.js +87 -0
  5. package/dist/crm/hooks/useCrmProperties.d.ts +5 -1
  6. package/dist/crm/hooks/useCrmProperties.js +81 -2
  7. package/dist/hooks/useExtensionActions.d.ts +4 -0
  8. package/dist/hooks/useExtensionActions.js +6 -0
  9. package/dist/hooks/useExtensionContext.d.ts +4 -0
  10. package/dist/hooks/useExtensionContext.js +6 -0
  11. package/dist/index.d.ts +2 -0
  12. package/dist/index.js +2 -0
  13. package/dist/internal/global-utils.js +4 -0
  14. package/dist/internal/hook-utils.d.ts +10 -3
  15. package/dist/internal/hook-utils.js +10 -1
  16. package/dist/shared/types/components/accordion.d.ts +5 -5
  17. package/dist/shared/types/components/alert.d.ts +2 -2
  18. package/dist/shared/types/components/button-row.d.ts +5 -2
  19. package/dist/shared/types/components/button.d.ts +16 -10
  20. package/dist/shared/types/components/chart.d.ts +3 -3
  21. package/dist/shared/types/components/description-list.d.ts +2 -2
  22. package/dist/shared/types/components/dropdown.d.ts +8 -8
  23. package/dist/shared/types/components/empty-state.d.ts +5 -7
  24. package/dist/shared/types/components/error-state.d.ts +2 -2
  25. package/dist/shared/types/components/form.d.ts +2 -2
  26. package/dist/shared/types/components/heading.d.ts +1 -1
  27. package/dist/shared/types/components/icon.d.ts +4 -5
  28. package/dist/shared/types/components/illustration.d.ts +12 -0
  29. package/dist/shared/types/components/image.d.ts +9 -4
  30. package/dist/shared/types/components/inputs.d.ts +51 -64
  31. package/dist/shared/types/components/layouts.d.ts +17 -24
  32. package/dist/shared/types/components/link.d.ts +8 -5
  33. package/dist/shared/types/components/loading-spinner.d.ts +3 -3
  34. package/dist/shared/types/components/modal.d.ts +5 -5
  35. package/dist/shared/types/components/panel.d.ts +7 -7
  36. package/dist/shared/types/components/progress-bar.d.ts +4 -4
  37. package/dist/shared/types/components/selects.d.ts +11 -20
  38. package/dist/shared/types/components/statistics.d.ts +2 -2
  39. package/dist/shared/types/components/status-tag.d.ts +5 -5
  40. package/dist/shared/types/components/step-indicator.d.ts +5 -7
  41. package/dist/shared/types/components/table.d.ts +22 -12
  42. package/dist/shared/types/components/tabs.d.ts +10 -10
  43. package/dist/shared/types/components/tag.d.ts +2 -2
  44. package/dist/shared/types/components/text.d.ts +15 -21
  45. package/dist/shared/types/components/tile.d.ts +2 -2
  46. package/dist/shared/types/components/toggle.d.ts +12 -14
  47. package/dist/shared/types/components/toggleInputs.d.ts +26 -19
  48. package/dist/shared/types/components/tooltip.d.ts +1 -1
  49. package/dist/shared/types/crm.d.ts +52 -0
  50. package/dist/shared/types/http-requests.d.ts +2 -2
  51. package/dist/shared/types/shared.d.ts +123 -78
  52. package/dist/shared/types/shared.js +123 -78
  53. package/dist/shared/types/worker-globals.d.ts +15 -0
  54. package/dist/{experimental/testing → testing}/__tests__/debug.spec.js +1 -1
  55. package/dist/{experimental/testing → testing}/__tests__/find.spec.js +1 -1
  56. package/dist/{experimental/testing → testing}/__tests__/findAll.spec.js +1 -1
  57. package/dist/{experimental/testing → testing}/__tests__/findAllChildren.spec.js +1 -1
  58. package/dist/{experimental/testing → testing}/__tests__/findByTestId.spec.js +1 -1
  59. package/dist/{experimental/testing → testing}/__tests__/findChild.spec.js +1 -1
  60. package/dist/{experimental/testing → testing}/__tests__/fragments.spec.js +1 -1
  61. package/dist/{experimental/testing → testing}/__tests__/invalid-components.spec.js +1 -1
  62. package/dist/{experimental/testing → testing}/__tests__/isMatch.spec.js +1 -1
  63. package/dist/{experimental/testing → testing}/__tests__/logger.spec.js +1 -1
  64. package/dist/{experimental/testing → testing}/__tests__/maybeFind.spec.js +1 -1
  65. package/dist/{experimental/testing → testing}/__tests__/maybeFindByTestId.spec.js +1 -1
  66. package/dist/{experimental/testing → testing}/__tests__/maybeFindChild.spec.js +1 -1
  67. package/dist/{experimental/testing → testing}/__tests__/mocks.runServerlessFunction.spec.js +1 -1
  68. package/dist/testing/__tests__/mocks.useAssociations.spec.js +135 -0
  69. package/dist/testing/__tests__/mocks.useCrmProperties.spec.js +106 -0
  70. package/dist/testing/__tests__/mocks.useExtensionActions.spec.js +32 -0
  71. package/dist/testing/__tests__/mocks.useExtensionContext.spec.js +46 -0
  72. package/dist/{experimental/testing → testing}/__tests__/props.spec.js +1 -1
  73. package/dist/{experimental/testing → testing}/__tests__/testId.spec.js +1 -1
  74. package/dist/{experimental/testing → testing}/__tests__/trigger.spec.js +1 -1
  75. package/dist/{experimental/testing → testing}/__tests__/type-utils.spec.js +1 -1
  76. package/dist/testing/__tests__/waitFor.spec.d.ts +1 -0
  77. package/dist/{experimental/testing → testing}/__tests__/waitFor.spec.js +1 -1
  78. package/dist/{experimental/testing → testing}/internal/convert.js +1 -1
  79. package/dist/{experimental/testing → testing}/internal/element.d.ts +1 -1
  80. package/dist/{experimental/testing → testing}/internal/errors.js +1 -1
  81. package/dist/{experimental/testing → testing}/internal/match.d.ts +1 -1
  82. package/dist/{experimental/testing → testing}/internal/mocks/index.d.ts +1 -1
  83. package/dist/{experimental/testing → testing}/internal/mocks/mock-extension-point-api.d.ts +1 -1
  84. package/dist/{experimental/testing → testing}/internal/mocks/mock-extension-point-api.js +1 -1
  85. package/dist/testing/internal/mocks/mock-hooks.d.ts +3 -0
  86. package/dist/{experimental/testing → testing}/internal/mocks/mock-hooks.js +14 -0
  87. package/dist/{experimental/testing → testing}/internal/print.js +1 -1
  88. package/dist/{experimental/testing → testing}/internal/query.d.ts +1 -1
  89. package/dist/{experimental/testing → testing}/internal/query.js +1 -1
  90. package/dist/{experimental/testing → testing}/internal/types-internal.d.ts +7 -3
  91. package/dist/testing/internal/types-internal.js +1 -0
  92. package/dist/{experimental/testing → testing}/render.d.ts +1 -1
  93. package/dist/{experimental/testing → testing}/render.js +7 -7
  94. package/dist/{experimental/testing → testing}/types.d.ts +25 -5
  95. package/dist/{experimental/testing → testing}/utils.d.ts +1 -1
  96. package/dist/{experimental/testing → testing}/utils.js +1 -1
  97. package/package.json +3 -3
  98. package/dist/experimental/testing/__tests__/mocks.useAssociations.spec.js +0 -47
  99. package/dist/experimental/testing/__tests__/mocks.useCrmProperties.spec.js +0 -58
  100. package/dist/experimental/testing/internal/mocks/mock-hooks.d.ts +0 -2
  101. /package/dist/{experimental/testing → testing}/__tests__/createRenderer.spec.d.ts +0 -0
  102. /package/dist/{experimental/testing → testing}/__tests__/createRenderer.spec.js +0 -0
  103. /package/dist/{experimental/testing → testing}/__tests__/debug.spec.d.ts +0 -0
  104. /package/dist/{experimental/testing → testing}/__tests__/find.spec.d.ts +0 -0
  105. /package/dist/{experimental/testing → testing}/__tests__/findAll.spec.d.ts +0 -0
  106. /package/dist/{experimental/testing → testing}/__tests__/findAllChildren.spec.d.ts +0 -0
  107. /package/dist/{experimental/testing → testing}/__tests__/findByTestId.spec.d.ts +0 -0
  108. /package/dist/{experimental/testing → testing}/__tests__/findChild.spec.d.ts +0 -0
  109. /package/dist/{experimental/testing → testing}/__tests__/fragments.spec.d.ts +0 -0
  110. /package/dist/{experimental/testing → testing}/__tests__/invalid-components.spec.d.ts +0 -0
  111. /package/dist/{experimental/testing → testing}/__tests__/isMatch.spec.d.ts +0 -0
  112. /package/dist/{experimental/testing → testing}/__tests__/logger.spec.d.ts +0 -0
  113. /package/dist/{experimental/testing → testing}/__tests__/maybeFind.spec.d.ts +0 -0
  114. /package/dist/{experimental/testing → testing}/__tests__/maybeFindByTestId.spec.d.ts +0 -0
  115. /package/dist/{experimental/testing → testing}/__tests__/maybeFindChild.spec.d.ts +0 -0
  116. /package/dist/{experimental/testing → testing}/__tests__/mocks.actions.spec.d.ts +0 -0
  117. /package/dist/{experimental/testing → testing}/__tests__/mocks.actions.spec.js +0 -0
  118. /package/dist/{experimental/testing → testing}/__tests__/mocks.context.spec.d.ts +0 -0
  119. /package/dist/{experimental/testing → testing}/__tests__/mocks.context.spec.js +0 -0
  120. /package/dist/{experimental/testing → testing}/__tests__/mocks.runServerlessFunction.spec.d.ts +0 -0
  121. /package/dist/{experimental/testing → testing}/__tests__/mocks.useAssociations.spec.d.ts +0 -0
  122. /package/dist/{experimental/testing → testing}/__tests__/mocks.useCrmProperties.spec.d.ts +0 -0
  123. /package/dist/{experimental/testing/__tests__/props.spec.d.ts → testing/__tests__/mocks.useExtensionActions.spec.d.ts} +0 -0
  124. /package/dist/{experimental/testing/__tests__/testId.spec.d.ts → testing/__tests__/mocks.useExtensionContext.spec.d.ts} +0 -0
  125. /package/dist/{experimental/testing/__tests__/trigger.spec.d.ts → testing/__tests__/props.spec.d.ts} +0 -0
  126. /package/dist/{experimental/testing/__tests__/type-utils.spec.d.ts → testing/__tests__/testId.spec.d.ts} +0 -0
  127. /package/dist/{experimental/testing/__tests__/waitFor.spec.d.ts → testing/__tests__/trigger.spec.d.ts} +0 -0
  128. /package/dist/{experimental/testing/internal/types-internal.js → testing/__tests__/type-utils.spec.d.ts} +0 -0
  129. /package/dist/{experimental/testing → testing}/index.d.ts +0 -0
  130. /package/dist/{experimental/testing → testing}/index.js +0 -0
  131. /package/dist/{experimental/testing → testing}/internal/constants.d.ts +0 -0
  132. /package/dist/{experimental/testing → testing}/internal/constants.js +0 -0
  133. /package/dist/{experimental/testing → testing}/internal/convert.d.ts +0 -0
  134. /package/dist/{experimental/testing → testing}/internal/debug.d.ts +0 -0
  135. /package/dist/{experimental/testing → testing}/internal/debug.js +0 -0
  136. /package/dist/{experimental/testing → testing}/internal/document.d.ts +0 -0
  137. /package/dist/{experimental/testing → testing}/internal/document.js +0 -0
  138. /package/dist/{experimental/testing → testing}/internal/element.js +0 -0
  139. /package/dist/{experimental/testing → testing}/internal/errors.d.ts +0 -0
  140. /package/dist/{experimental/testing → testing}/internal/fragment.d.ts +0 -0
  141. /package/dist/{experimental/testing → testing}/internal/fragment.js +0 -0
  142. /package/dist/{experimental/testing → testing}/internal/match.js +0 -0
  143. /package/dist/{experimental/testing → testing}/internal/mocks/index.js +0 -0
  144. /package/dist/{experimental/testing → testing}/internal/print.d.ts +0 -0
  145. /package/dist/{experimental/testing → testing}/internal/root.d.ts +0 -0
  146. /package/dist/{experimental/testing → testing}/internal/root.js +0 -0
  147. /package/dist/{experimental/testing → testing}/internal/text.d.ts +0 -0
  148. /package/dist/{experimental/testing → testing}/internal/text.js +0 -0
  149. /package/dist/{experimental/testing → testing}/internal/type-utils-internal.d.ts +0 -0
  150. /package/dist/{experimental/testing → testing}/internal/type-utils-internal.js +0 -0
  151. /package/dist/{experimental/testing → testing}/internal/utils/promise-utils.d.ts +0 -0
  152. /package/dist/{experimental/testing → testing}/internal/utils/promise-utils.js +0 -0
  153. /package/dist/{experimental/testing → testing}/type-utils.d.ts +0 -0
  154. /package/dist/{experimental/testing → testing}/type-utils.js +0 -0
  155. /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 '../../../shared/types/extension-points.ts';
3
- import { HubSpotReactComponent, UnknownComponentProps } from '../../../shared/types/shared.ts';
4
- import { useAssociations, useCrmProperties } from '../../../crm/index.ts';
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 '../../shared/types/extension-points.ts';
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 "../../shared/types/extension-points.js";
8
- import { MocksContextProvider } from "../../internal/hook-utils.js";
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, mocks) => {
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: mocks, children: node }));
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 { mocks, spies } = createMocksWithSpies(extensionPointLocation);
178
+ const { spies: mocksWithSpies } = createMocksWithSpies(extensionPointLocation);
179
179
  return {
180
180
  render: (node) => {
181
- renderResult = render(node, mocks);
181
+ renderResult = render(node, mocksWithSpies);
182
182
  return asRenderedRootNode(renderResult.getLatestRootNode());
183
183
  },
184
- mocks: spies,
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 '../../shared/types/extension-points.ts';
2
- import { ServerlessFuncRunner } from '../../shared/types/http-requests.ts';
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 '../../shared/types/shared.ts';
5
- import { useAssociations, useCrmProperties } from '../../crm/index.ts';
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 '../../shared/types/shared.ts';
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 "../../shared/remoteComponents.js";
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.4",
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
- "./experimental/testing": "./dist/experimental/testing/index.js"
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": "87edb81155e7376caa159611e6f2fd8e8c3dfdec"
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
- });
@@ -1,2 +0,0 @@
1
- import { RendererMockHooksInternal } from '../types-internal.ts';
2
- export declare const createMockHooks: () => RendererMockHooksInternal;
File without changes
File without changes