@hubspot/ui-extensions 0.12.3 → 0.12.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/crm/utils/fetchAssociations.spec.js +2 -1
- package/dist/crm/hooks/useAssociations.d.ts +2 -10
- package/dist/crm/hooks/useAssociations.js +2 -1
- package/dist/crm/utils/fetchAssociations.d.ts +0 -8
- package/dist/crm/utils/fetchAssociations.js +0 -10
- package/dist/experimental/pages/components/index.d.ts +1 -0
- package/dist/experimental/pages/components/index.js +1 -0
- package/dist/experimental/pages/components/page-routes.d.ts +83 -0
- package/dist/experimental/pages/components/page-routes.js +66 -0
- package/dist/experimental/pages/create-page-router.d.ts +35 -0
- package/dist/experimental/pages/create-page-router.js +123 -0
- package/dist/experimental/pages/create-page-router.test.d.ts +1 -0
- package/dist/experimental/pages/create-page-router.test.js +296 -0
- package/dist/experimental/pages/hooks.d.ts +8 -0
- package/dist/experimental/pages/hooks.js +15 -0
- package/dist/experimental/pages/index.d.ts +5 -3
- package/dist/experimental/pages/index.js +4 -3
- package/dist/experimental/pages/internal/app-page-route-context.d.ts +16 -0
- package/dist/experimental/pages/internal/app-page-route-context.js +12 -0
- package/dist/experimental/pages/internal/convert-page-routes-react-elements.d.ts +9 -0
- package/dist/experimental/pages/internal/convert-page-routes-react-elements.js +138 -0
- package/dist/experimental/pages/internal/page-router-internal-types.d.ts +40 -0
- package/dist/experimental/pages/internal/page-router-internal-types.js +5 -0
- package/dist/experimental/pages/internal/trie-router.d.ts +31 -0
- package/dist/experimental/pages/internal/trie-router.js +141 -0
- package/dist/experimental/pages/internal/trie-router.test.d.ts +1 -0
- package/dist/experimental/pages/internal/trie-router.test.js +263 -0
- package/dist/experimental/pages/internal/useAppPageLocation.d.ts +1 -0
- package/dist/experimental/pages/internal/useAppPageLocation.js +13 -0
- package/dist/experimental/pages/types.d.ts +29 -0
- package/dist/experimental/pages/types.js +1 -0
- package/dist/internal/hook-utils.d.ts +7 -6
- package/dist/internal/hook-utils.js +8 -9
- package/dist/pages/index.d.ts +1 -0
- package/dist/pages/index.js +1 -0
- package/dist/shared/remoteComponents.d.ts +24 -0
- package/dist/shared/remoteComponents.js +28 -0
- package/dist/shared/types/components/button.d.ts +2 -2
- package/dist/shared/types/components/image.d.ts +2 -2
- package/dist/shared/types/components/inputs.d.ts +7 -1
- package/dist/shared/types/components/link.d.ts +2 -2
- package/dist/shared/types/pages/components/index.d.ts +3 -1
- package/dist/shared/types/pages/components/page-breadcrumbs.d.ts +34 -0
- package/dist/shared/types/pages/components/page-breadcrumbs.js +1 -0
- package/dist/shared/types/pages/components/page-header.d.ts +82 -0
- package/dist/shared/types/pages/components/page-header.js +1 -0
- package/dist/shared/types/pages/components/page-link.d.ts +4 -2
- package/dist/shared/types/pages/components/page-title.d.ts +12 -0
- package/dist/shared/types/pages/components/page-title.js +1 -0
- package/dist/shared/types/pages/index.d.ts +1 -0
- package/dist/shared/types/pages/index.js +1 -0
- package/dist/shared/types/pages.d.ts +1 -0
- package/dist/shared/types/pages.js +1 -0
- package/dist/shared/types/worker-globals.d.ts +3 -12
- package/dist/testing/internal/mocks/index.d.ts +14 -6
- package/dist/testing/internal/mocks/index.js +19 -5
- package/dist/testing/internal/mocks/mock-app-page-location.d.ts +7 -0
- package/dist/testing/internal/mocks/mock-app-page-location.js +35 -0
- package/dist/testing/internal/mocks/mock-hooks.js +12 -7
- package/dist/testing/render.js +7 -6
- package/dist/testing/types.d.ts +19 -3
- package/dist/utils/pagination.d.ts +17 -0
- package/dist/utils/pagination.js +10 -0
- package/package.json +1 -1
|
@@ -155,6 +155,12 @@ export interface NumberInputProps extends BaseInputForNumber {
|
|
|
155
155
|
formatStyle?: 'decimal' | 'percentage';
|
|
156
156
|
/** @deprecated use onChange instead. It doesn't guarantee valid format */
|
|
157
157
|
onInput?: (value: number) => void;
|
|
158
|
+
/**
|
|
159
|
+
* Sets the horizontal alignment of the text in the input.
|
|
160
|
+
*
|
|
161
|
+
* @defaultValue `"left"`
|
|
162
|
+
*/
|
|
163
|
+
textAlign?: 'left' | 'right';
|
|
158
164
|
}
|
|
159
165
|
/**
|
|
160
166
|
* The props type for [CurrencyInput](https://developers.hubspot.com/docs/apps/developer-platform/add-features/ui-extensibility/ui-components/standard-components/currency-input).
|
|
@@ -185,7 +191,7 @@ export interface CurrencyInputProps extends BaseInputForNumber {
|
|
|
185
191
|
*
|
|
186
192
|
* @category Component Props
|
|
187
193
|
*/
|
|
188
|
-
export interface StepperInputProps extends Omit<NumberInputProps, 'onInput'> {
|
|
194
|
+
export interface StepperInputProps extends Omit<NumberInputProps, 'onInput' | 'textAlign'> {
|
|
189
195
|
/** The amount that the current value will increase or decrease by. Default is `1`.
|
|
190
196
|
* @defaultValue `1`
|
|
191
197
|
*/
|
|
@@ -13,9 +13,9 @@ export interface LinkProps extends OverlayComponentProps, BaseComponentProps {
|
|
|
13
13
|
*/
|
|
14
14
|
children: ReactNode;
|
|
15
15
|
/**
|
|
16
|
-
* Sets the link's URL and open behavior.
|
|
16
|
+
* Sets the link's URL and open behavior. Can be set to a URL string or an object with the following fields:
|
|
17
17
|
* - `url` (string): the URL that will open on click.
|
|
18
|
-
* - `external` (boolean): set to `true` to open the URL in a new tab and display an external link icon. By default:
|
|
18
|
+
* - `external` (boolean, optional): set to `true` to open the URL in a new tab and display an external link icon. By default:
|
|
19
19
|
* - Links to HubSpot app pages will open in the same tab and will not include an icon.
|
|
20
20
|
* - Links to non-HubSpot app pages will open in a new tab and include the icon.
|
|
21
21
|
*/
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { BaseComponentProps } from '../../shared.ts';
|
|
3
|
+
/**
|
|
4
|
+
* The props type for [PageBreadcrumbs](https://developers.hubspot.com/docs/reference/ui-components/app-page-components/page-breadcrumbs)
|
|
5
|
+
*/
|
|
6
|
+
export interface PageBreadcrumbsProps extends BaseComponentProps {
|
|
7
|
+
/**
|
|
8
|
+
* The links and text to render as breadcrumbs.
|
|
9
|
+
* Use `PageBreadcrumbs.PageLink` for navigable crumbs and `PageBreadcrumbs.Current` for the current page.
|
|
10
|
+
*/
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
}
|
|
13
|
+
export interface PageBreadcrumbsPageLinkProps extends BaseComponentProps {
|
|
14
|
+
/**
|
|
15
|
+
* The path to navigate to when the link is clicked. Supports path parameters (e.g. `/view-contact/:contactId`).
|
|
16
|
+
*/
|
|
17
|
+
to: string;
|
|
18
|
+
/**
|
|
19
|
+
* Values for path parameters and query string entries.
|
|
20
|
+
* Parameters matching `:paramName` tokens in `to` are substituted into the path.
|
|
21
|
+
* Any remaining parameters are appended as query string entries.
|
|
22
|
+
*/
|
|
23
|
+
params?: Record<string, string>;
|
|
24
|
+
/**
|
|
25
|
+
* The visible text of the breadcrumb link.
|
|
26
|
+
*/
|
|
27
|
+
children: ReactNode;
|
|
28
|
+
}
|
|
29
|
+
export interface PageBreadcrumbsCurrentProps extends BaseComponentProps {
|
|
30
|
+
/**
|
|
31
|
+
* Label for the current location.
|
|
32
|
+
*/
|
|
33
|
+
children: ReactNode;
|
|
34
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import type { ReactionsHandler } from '../../reactions.ts';
|
|
3
|
+
import type { BaseComponentProps, ExtensionEvent } from '../../shared.ts';
|
|
4
|
+
/**
|
|
5
|
+
* The props type for [PageHeader](https://developers.hubspot.com/docs/apps/developer-platform/add-features/ui-extensibility/ui-components/app-page-components/page-header).
|
|
6
|
+
*
|
|
7
|
+
* @category Component Props
|
|
8
|
+
*/
|
|
9
|
+
export interface PageHeaderProps extends BaseComponentProps {
|
|
10
|
+
/**
|
|
11
|
+
* Sets the content that will render inside the component. Can contain only <code>PageHeader.PrimaryAction</code> and/or <code>PageHeader.SecondaryActions</code> components.
|
|
12
|
+
*/
|
|
13
|
+
children: ReactElement<PageHeaderPrimaryActionProps> | ReactElement<PageHeaderSecondaryActionsProps>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The props type for [PageHeader.PrimaryAction](https://developers.hubspot.com/docs/apps/developer-platform/add-features/ui-extensibility/ui-components/app-page-components/page-header#pageheader-primaryaction).
|
|
17
|
+
*
|
|
18
|
+
* @category Component Props
|
|
19
|
+
*/
|
|
20
|
+
export interface PageHeaderPrimaryActionProps extends BaseComponentProps {
|
|
21
|
+
/**
|
|
22
|
+
* Must be a <code>PageHeader.PageLink</code> component (for internal app pages) or a <code>PageHeader.Link</code> component (for URLs outside your app). No other component types are supported.
|
|
23
|
+
*/
|
|
24
|
+
children: ReactNode;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The props type for [PageHeader.SecondaryActions](https://developers.hubspot.com/docs/apps/developer-platform/add-features/ui-extensibility/ui-components/app-page-components/page-header#pageheader-secondaryactions).
|
|
28
|
+
*
|
|
29
|
+
* @category Component Props
|
|
30
|
+
*/
|
|
31
|
+
export interface PageHeaderSecondaryActionsProps extends BaseComponentProps {
|
|
32
|
+
/**
|
|
33
|
+
* Must contain one or more <code>PageHeader.PageLink</code> component (for internal app pages) or a <code>PageHeader.Link</code> component (for URLs outside your app). No other component types are supported.
|
|
34
|
+
*/
|
|
35
|
+
children: ReactNode;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The props type for [PageHeader.Link](https://developers.hubspot.com/docs/apps/developer-platform/add-features/ui-extensibility/ui-components/app-page-components/page-header#pageheader-link).
|
|
39
|
+
*
|
|
40
|
+
* @category Component Props
|
|
41
|
+
*/
|
|
42
|
+
export interface PageHeaderLinkProps extends BaseComponentProps {
|
|
43
|
+
/**
|
|
44
|
+
* A URL that will be opened when the button is clicked. If the value is a URL external to `hubspot.com` it will be opened in a new tab.
|
|
45
|
+
*/
|
|
46
|
+
href?: string;
|
|
47
|
+
/**
|
|
48
|
+
* A function that will be invoked when the button is clicked. Do not use this function for submitting a form; use Form's `onSubmit` function instead.
|
|
49
|
+
*
|
|
50
|
+
* @event
|
|
51
|
+
*/
|
|
52
|
+
onClick?: ReactionsHandler<ExtensionEvent>;
|
|
53
|
+
/**
|
|
54
|
+
* Determines whether or not the button should be disabled.
|
|
55
|
+
*/
|
|
56
|
+
disabled?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* The visible label of the link button. This prop is passed implicitly by providing sub-components.
|
|
59
|
+
*/
|
|
60
|
+
children: ReactNode;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The props type for [PageHeader.PageLink](https://developers.hubspot.com/docs/apps/developer-platform/add-features/ui-extensibility/ui-components/app-page-components/page-header#pageheader-pagelink).
|
|
64
|
+
*
|
|
65
|
+
* @category Component Props
|
|
66
|
+
*/
|
|
67
|
+
export interface PageHeaderPageLinkProps extends BaseComponentProps {
|
|
68
|
+
/**
|
|
69
|
+
* The path to navigate to when the link is clicked. Supports path parameters (e.g. `/view-contact/:contactId`).
|
|
70
|
+
*/
|
|
71
|
+
to: string;
|
|
72
|
+
/**
|
|
73
|
+
* Values for path parameters and query string entries.
|
|
74
|
+
* Parameters matching `:paramName` tokens in `to` are substituted into the path.
|
|
75
|
+
* Any remaining parameters are appended as query string entries.
|
|
76
|
+
*/
|
|
77
|
+
params?: Record<string, string>;
|
|
78
|
+
/**
|
|
79
|
+
* The visible label of the link button. This prop is passed implicitly by providing sub-components.
|
|
80
|
+
*/
|
|
81
|
+
children: ReactNode;
|
|
82
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -7,7 +7,9 @@ import type { BaseComponentProps } from '../../shared.ts';
|
|
|
7
7
|
*/
|
|
8
8
|
export interface PageLinkProps extends BaseComponentProps {
|
|
9
9
|
/**
|
|
10
|
-
* The path to navigate to
|
|
10
|
+
* The path to navigate to. Can be a simple path (e.g., <code>"/docs"</code>) or a path with parameters
|
|
11
|
+
* (e.g., <code>"/view-contact/:contactId"</code>). When using path parameters, provide the parameter
|
|
12
|
+
* values in the <code>params</code> prop.
|
|
11
13
|
*/
|
|
12
14
|
to: string;
|
|
13
15
|
/**
|
|
@@ -17,7 +19,7 @@ export interface PageLinkProps extends BaseComponentProps {
|
|
|
17
19
|
*/
|
|
18
20
|
params?: Record<string, string>;
|
|
19
21
|
/**
|
|
20
|
-
* The content to
|
|
22
|
+
* The content to display inside the link.
|
|
21
23
|
*/
|
|
22
24
|
children: ReactNode;
|
|
23
25
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { BaseComponentProps } from '../../shared.ts';
|
|
2
|
+
/**
|
|
3
|
+
* The props type for [PageTitle](https://developers.hubspot.com/docs/apps/developer-platform/add-features/ui-extensibility/ui-components/app-page-components/page-title).
|
|
4
|
+
*
|
|
5
|
+
* @category Component Props
|
|
6
|
+
*/
|
|
7
|
+
export interface PageTitleProps extends BaseComponentProps {
|
|
8
|
+
/**
|
|
9
|
+
* The text to display as the page heading. Also sets the browser tab title.
|
|
10
|
+
*/
|
|
11
|
+
children: string;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from './components/index.ts';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type * from './pages/index.ts';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { HubspotExtendFunction } from './extend.ts';
|
|
2
2
|
import type { ExtensionPointApiActions, ExtensionPointApiContext, ExtensionPointFullApi, ExtensionPoints } from './extension-points.ts';
|
|
3
3
|
import type { Logger } from './logger.ts';
|
|
4
|
-
import type {
|
|
5
|
-
import type { PageRoutesComponent } from './pages/components/page-routes.ts';
|
|
4
|
+
import type { AppPageLocation } from './shared.ts';
|
|
6
5
|
export interface WorkersApi {
|
|
7
6
|
/**
|
|
8
7
|
* Hook added to worker globals so customer code can access extension context at runtime.
|
|
@@ -17,17 +16,9 @@ export interface WorkersApi {
|
|
|
17
16
|
*/
|
|
18
17
|
useExtensionApi: <ExtensionPoint extends keyof ExtensionPoints>() => ExtensionPointFullApi<ExtensionPoint>;
|
|
19
18
|
/**
|
|
20
|
-
*
|
|
19
|
+
* Hook added to worker globals so page router can access the current app page location at runtime.
|
|
21
20
|
*/
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Hook added to worker globals so customer code can access the current page route at runtime.
|
|
25
|
-
*/
|
|
26
|
-
usePageRoute: UsePageRouteHook;
|
|
27
|
-
/**
|
|
28
|
-
* Function added to worker globals so customer code can create a page router at runtime.
|
|
29
|
-
*/
|
|
30
|
-
createPageRouter: CreatePageRouterFunction;
|
|
21
|
+
useAppPageLocation: () => AppPageLocation;
|
|
31
22
|
}
|
|
32
23
|
export interface WorkerGlobalsInternal {
|
|
33
24
|
/**
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
+
import { type useAppPageLocation } from '../../../experimental/pages/internal/useAppPageLocation.tsx';
|
|
1
2
|
import type { ExtensionPointLocation } from '../../../shared/types/extension-points.ts';
|
|
2
|
-
import type {
|
|
3
|
-
import type
|
|
3
|
+
import type { RendererMocks } from '../../types.ts';
|
|
4
|
+
import { type MocksAppPageLocationStore } from './mock-app-page-location.tsx';
|
|
4
5
|
/**
|
|
5
6
|
* An object containing the mocks and spies.
|
|
6
7
|
*/
|
|
7
|
-
export interface
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
export interface RendererMocksContext {
|
|
9
|
+
/**
|
|
10
|
+
* The mocks object provided by the testing utilities.
|
|
11
|
+
*/
|
|
12
|
+
mocks: RendererMocks<ExtensionPointLocation>;
|
|
13
|
+
/**
|
|
14
|
+
* The app page location store.
|
|
15
|
+
*/
|
|
16
|
+
appPageLocationStore: MocksAppPageLocationStore;
|
|
17
|
+
useAppPageLocation: typeof useAppPageLocation;
|
|
10
18
|
}
|
|
11
19
|
/**
|
|
12
20
|
* Creates a set of mocks and spies for the various functions such as the `useCrmProperties` and `useAssociations`
|
|
@@ -14,4 +22,4 @@ export interface MocksWithSpies<TExtensionPointLocation extends ExtensionPointLo
|
|
|
14
22
|
*
|
|
15
23
|
* @returns An object containing the mocks and spies.
|
|
16
24
|
*/
|
|
17
|
-
export declare const
|
|
25
|
+
export declare const createRendererMocksContext: <TExtensionPointLocation extends ExtensionPointLocation>(extensionPointLocation: TExtensionPointLocation) => RendererMocksContext;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { act as reactAct, useSyncExternalStore } from 'react';
|
|
1
2
|
import { spyOn } from 'tinyspy';
|
|
3
|
+
import { createMocksAppPageLocationStore, } from "./mock-app-page-location.js";
|
|
2
4
|
import { createMockExtensionPointApi } from "./mock-extension-point-api.js";
|
|
3
5
|
import { createMockHooks } from "./mock-hooks.js";
|
|
4
6
|
/**
|
|
@@ -29,7 +31,7 @@ const spyOnAllFunctionsRecursive = (object) => {
|
|
|
29
31
|
*
|
|
30
32
|
* @returns An object containing the mocks and spies.
|
|
31
33
|
*/
|
|
32
|
-
export const
|
|
34
|
+
export const createRendererMocksContext = (extensionPointLocation) => {
|
|
33
35
|
const mockExtensionPointApi = createMockExtensionPointApi(extensionPointLocation);
|
|
34
36
|
// Build a mocks object with the default mock functions.
|
|
35
37
|
// NOTE: The mock implementations can be overridden by tests using the spies that are provided in the returned `spies` object.
|
|
@@ -37,10 +39,22 @@ export const createMocksWithSpies = (extensionPointLocation) => {
|
|
|
37
39
|
...createMockHooks(),
|
|
38
40
|
...mockExtensionPointApi,
|
|
39
41
|
};
|
|
40
|
-
//
|
|
41
|
-
const
|
|
42
|
+
// Recursively create spies for all functions in the mocks object.
|
|
43
|
+
const mocksWithSpies = spyOnAllFunctionsRecursive(mocks);
|
|
44
|
+
const appPageLocationStore = createMocksAppPageLocationStore();
|
|
42
45
|
return {
|
|
43
|
-
mocks
|
|
44
|
-
|
|
46
|
+
mocks: {
|
|
47
|
+
// NOTE: These mocks are exposed as part of our public API.
|
|
48
|
+
...mocksWithSpies,
|
|
49
|
+
setPageLocation: (location) => {
|
|
50
|
+
reactAct(() => {
|
|
51
|
+
appPageLocationStore.setPageLocation(location);
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
appPageLocationStore,
|
|
56
|
+
useAppPageLocation: () => {
|
|
57
|
+
return useSyncExternalStore(appPageLocationStore.subscribe, appPageLocationStore.getSnapshot);
|
|
58
|
+
},
|
|
45
59
|
};
|
|
46
60
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AppPageLocation } from '../../../shared/types/shared.ts';
|
|
2
|
+
export interface MocksAppPageLocationStore {
|
|
3
|
+
getSnapshot: () => AppPageLocation;
|
|
4
|
+
setPageLocation: (location: AppPageLocation) => void;
|
|
5
|
+
subscribe: (listener: () => void) => () => void;
|
|
6
|
+
}
|
|
7
|
+
export declare const createMocksAppPageLocationStore: (initialLocation?: AppPageLocation) => MocksAppPageLocationStore;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const DEFAULT_PAGE_LOCATION = { path: '/', params: {} };
|
|
2
|
+
const areParamsEqual = (a, b) => {
|
|
3
|
+
const keysA = Object.keys(a);
|
|
4
|
+
const keysB = Object.keys(b);
|
|
5
|
+
if (keysA.length !== keysB.length)
|
|
6
|
+
return false;
|
|
7
|
+
for (const key of keysA) {
|
|
8
|
+
if (a[key] !== b[key])
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
return true;
|
|
12
|
+
};
|
|
13
|
+
const areAppPageLocationsEqual = (a, b) => a.path === b.path && areParamsEqual(a.params, b.params);
|
|
14
|
+
export const createMocksAppPageLocationStore = (initialLocation = DEFAULT_PAGE_LOCATION) => {
|
|
15
|
+
let currentLocation = initialLocation;
|
|
16
|
+
let listeners = [];
|
|
17
|
+
return {
|
|
18
|
+
getSnapshot: () => currentLocation,
|
|
19
|
+
setPageLocation: (location) => {
|
|
20
|
+
if (areAppPageLocationsEqual(location, currentLocation)) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
currentLocation = location;
|
|
24
|
+
for (const listener of listeners) {
|
|
25
|
+
listener();
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
subscribe: (listener) => {
|
|
29
|
+
listeners = [...listeners, listener];
|
|
30
|
+
return () => {
|
|
31
|
+
listeners = listeners.filter((l) => l !== listener);
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
};
|
|
@@ -15,6 +15,13 @@ const createFakeProperties = (propertyNames) => {
|
|
|
15
15
|
}, {});
|
|
16
16
|
};
|
|
17
17
|
export const createMockHooks = () => {
|
|
18
|
+
const useRequiredMocksContext = () => {
|
|
19
|
+
const mocksContext = useMocksContext();
|
|
20
|
+
if (!mocksContext) {
|
|
21
|
+
throw new Error('Illegal State: Mocks context not found.');
|
|
22
|
+
}
|
|
23
|
+
return mocksContext;
|
|
24
|
+
};
|
|
18
25
|
// Build a mocks object with the default mock functions.
|
|
19
26
|
// NOTE: The mock implementations can be overridden by tests using the spies that are provided in the returned `spies` object.
|
|
20
27
|
return {
|
|
@@ -61,20 +68,18 @@ export const createMockHooks = () => {
|
|
|
61
68
|
};
|
|
62
69
|
},
|
|
63
70
|
useExtensionContext: () => {
|
|
64
|
-
const mocks =
|
|
71
|
+
const { mocks } = useRequiredMocksContext();
|
|
65
72
|
return mocks.context;
|
|
66
73
|
},
|
|
67
74
|
useExtensionActions: () => {
|
|
68
|
-
const mocks =
|
|
69
|
-
return mocks
|
|
70
|
-
.actions;
|
|
75
|
+
const { mocks } = useRequiredMocksContext();
|
|
76
|
+
return mocks.actions;
|
|
71
77
|
},
|
|
72
78
|
useExtensionApi: () => {
|
|
73
|
-
const mocks =
|
|
79
|
+
const { mocks } = useRequiredMocksContext();
|
|
74
80
|
return {
|
|
75
81
|
context: mocks.context,
|
|
76
|
-
actions: mocks
|
|
77
|
-
.actions,
|
|
82
|
+
actions: mocks.actions,
|
|
78
83
|
runServerlessFunction: mocks.runServerlessFunction,
|
|
79
84
|
};
|
|
80
85
|
},
|
package/dist/testing/render.js
CHANGED
|
@@ -6,7 +6,7 @@ import { EXTENSION_POINT_LOCATIONS } from "../shared/types/extension-points.js";
|
|
|
6
6
|
import { convertRemoteRoot } from "./internal/convert.js";
|
|
7
7
|
import { createDocument } from "./internal/document.js";
|
|
8
8
|
import { InvalidComponentsError, InvalidExtensionPointLocationError, WaitForTimeoutError, } from "./internal/errors.js";
|
|
9
|
-
import {
|
|
9
|
+
import { createRendererMocksContext, } 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";
|
|
12
12
|
import { asRenderedRootNode } from "./internal/type-utils-internal.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, mocksContext) => {
|
|
25
25
|
let dirty = true;
|
|
26
26
|
let waitForChecksQueued = false;
|
|
27
27
|
let waitForList = [];
|
|
@@ -74,7 +74,7 @@ const render = (node, mocksWithSpies) => {
|
|
|
74
74
|
};
|
|
75
75
|
const remoteRoot = createRemoteRoot(remoteChannel);
|
|
76
76
|
const reactRoot = createReactRoot(remoteRoot);
|
|
77
|
-
reactRoot.render(_jsx(MocksContextProvider, { value:
|
|
77
|
+
reactRoot.render(_jsx(MocksContextProvider, { value: mocksContext, children: node }));
|
|
78
78
|
remoteRoot.mount();
|
|
79
79
|
let maybeRenderedRootNode;
|
|
80
80
|
/**
|
|
@@ -174,13 +174,14 @@ export const createRenderer = (extensionPointLocation) => {
|
|
|
174
174
|
return renderResult;
|
|
175
175
|
};
|
|
176
176
|
const getLatestRootNode = () => getRenderResult().getLatestRootNode();
|
|
177
|
-
const
|
|
177
|
+
const mocksContext = createRendererMocksContext(extensionPointLocation);
|
|
178
|
+
const { mocks } = mocksContext;
|
|
178
179
|
return {
|
|
179
180
|
render: (node) => {
|
|
180
|
-
renderResult = render(node,
|
|
181
|
+
renderResult = render(node, mocksContext);
|
|
181
182
|
return asRenderedRootNode(renderResult.getLatestRootNode());
|
|
182
183
|
},
|
|
183
|
-
mocks:
|
|
184
|
+
mocks: mocks,
|
|
184
185
|
find: (component, matcher) => {
|
|
185
186
|
return find(getLatestRootNode(), component, matcher);
|
|
186
187
|
},
|
package/dist/testing/types.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { SpyImpl } from 'tinyspy';
|
|
2
2
|
import type { useAssociations, useCrmProperties } from '../crm/index.ts';
|
|
3
|
+
import type { useAppPageLocation } from '../experimental/pages/internal/useAppPageLocation.tsx';
|
|
3
4
|
import type { useExtensionActions } from '../hooks/useExtensionActions.tsx';
|
|
4
5
|
import type { useExtensionApi } from '../hooks/useExtensionApi.tsx';
|
|
5
6
|
import type { useExtensionContext } from '../hooks/useExtensionContext.tsx';
|
|
6
7
|
import type { ExtensionPointApi, ExtensionPointApiActions, ExtensionPointLocation } from '../shared/types/extension-points.ts';
|
|
7
8
|
import type { ServerlessFuncRunner } from '../shared/types/http-requests.ts';
|
|
8
|
-
import type { HubSpotReactComponent, HubSpotReactFragmentProp, UnknownComponentProps } from '../shared/types/shared.ts';
|
|
9
|
+
import type { AppPageLocation, HubSpotReactComponent, HubSpotReactFragmentProp, UnknownComponentProps } from '../shared/types/shared.ts';
|
|
9
10
|
import type { AnyFunction } from './internal/types-internal.ts';
|
|
10
11
|
/**
|
|
11
12
|
* The type of a rendered node.
|
|
@@ -261,7 +262,7 @@ export type ExtensionPointApiActionSpies<TExtensionPointLocation extends Extensi
|
|
|
261
262
|
/**
|
|
262
263
|
* An object containing the spies for the various functions.
|
|
263
264
|
*/
|
|
264
|
-
export interface
|
|
265
|
+
export interface RendererMocks<TExtensionPointLocation extends ExtensionPointLocation = ExtensionPointLocation> {
|
|
265
266
|
/**
|
|
266
267
|
* A spy for the `useCrmProperties` hook function.
|
|
267
268
|
* The spy can be used to track the calls to the hook function and also control the
|
|
@@ -307,6 +308,15 @@ export interface RendererSpies<TExtensionPointLocation extends ExtensionPointLoc
|
|
|
307
308
|
* information about spies and the supported API.
|
|
308
309
|
*/
|
|
309
310
|
useExtensionApi: FunctionSpy<typeof useExtensionApi>;
|
|
311
|
+
/**
|
|
312
|
+
* A spy for the `useAppPageLocation` hook function.
|
|
313
|
+
* The spy can be used to track the calls to the hook function and also control the
|
|
314
|
+
* return result of the hook function.
|
|
315
|
+
*
|
|
316
|
+
* See the [tinyspy](https://github.com/tiny-spy/tinyspy) library for more
|
|
317
|
+
* information about spies and the supported API.
|
|
318
|
+
*/
|
|
319
|
+
useAppPageLocation: FunctionSpy<typeof useAppPageLocation>;
|
|
310
320
|
/**
|
|
311
321
|
* Mock context object that contains fake context data for the extension point API.
|
|
312
322
|
*/
|
|
@@ -329,6 +339,12 @@ export interface RendererSpies<TExtensionPointLocation extends ExtensionPointLoc
|
|
|
329
339
|
* information about spies and the supported API.
|
|
330
340
|
*/
|
|
331
341
|
runServerlessFunction: FunctionSpy<ServerlessFuncRunner>;
|
|
342
|
+
/**
|
|
343
|
+
* Sets the current app page location for testing page routing.
|
|
344
|
+
*
|
|
345
|
+
* @param location The app page location to set.
|
|
346
|
+
*/
|
|
347
|
+
setPageLocation: (location: AppPageLocation) => void;
|
|
332
348
|
}
|
|
333
349
|
/**
|
|
334
350
|
* A result of a render operation.
|
|
@@ -363,7 +379,7 @@ export interface Renderer<TExtensionPointLocation extends ExtensionPointLocation
|
|
|
363
379
|
/**
|
|
364
380
|
* The mocks that can be used to control the behavior of the various functions.
|
|
365
381
|
*/
|
|
366
|
-
mocks:
|
|
382
|
+
mocks: RendererMocks<TExtensionPointLocation>;
|
|
367
383
|
/**
|
|
368
384
|
* Finds the first descendant element node that matches the given component and test ID.
|
|
369
385
|
*
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface PaginationResult {
|
|
2
|
+
hasNextPage: boolean;
|
|
3
|
+
hasPreviousPage: boolean;
|
|
4
|
+
currentPage: number;
|
|
5
|
+
pageSize: number;
|
|
6
|
+
nextPage: () => void;
|
|
7
|
+
previousPage: () => void;
|
|
8
|
+
reset: () => void;
|
|
9
|
+
}
|
|
10
|
+
export declare const DEFAULT_PAGE_SIZE = 10;
|
|
11
|
+
/**
|
|
12
|
+
* Calculate pagination flags based on current page and API hasMore flag
|
|
13
|
+
*/
|
|
14
|
+
export declare function calculatePaginationFlags(currentPage: number, hasMore: boolean): {
|
|
15
|
+
hasNextPage: boolean;
|
|
16
|
+
hasPreviousPage: boolean;
|
|
17
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const DEFAULT_PAGE_SIZE = 10;
|
|
2
|
+
/**
|
|
3
|
+
* Calculate pagination flags based on current page and API hasMore flag
|
|
4
|
+
*/
|
|
5
|
+
export function calculatePaginationFlags(currentPage, hasMore) {
|
|
6
|
+
return {
|
|
7
|
+
hasNextPage: hasMore,
|
|
8
|
+
hasPreviousPage: currentPage > 1,
|
|
9
|
+
};
|
|
10
|
+
}
|